Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds zarr support #248

Merged
merged 6 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ dist/
*.blend[1-9]

## pytest
.pytest_cache
.pytest_cacheflycheck_*
1,516 changes: 758 additions & 758 deletions doc/bibliography/tyssue.bib

Large diffs are not rendered by default.

65 changes: 64 additions & 1 deletion tests/core/test_history.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest
import os
import pytest

from pathlib import Path

import numpy as np

from tyssue import Sheet, History, Epithelium, RNRGeometry
from tyssue.core.history import HistoryHdf5
Expand Down Expand Up @@ -63,6 +65,60 @@ def test_retrieve():
assert sheet_.datasets["face"].loc[0, "area"] == 100.0


def test_browse():
sheet = Sheet("3", *three_faces_sheet())
history = History(sheet)
for i in range(30):
history.record(i / 10)

times = [t for t, _ in history.browse()]
np.testing.assert_allclose(times, history.time_stamps)

times_areas = np.array(
[[t, s.face_df.loc[0, "area"]] for t, s in history.browse(2, 8, endpoint=True)]
)
assert times_areas.shape == (7, 2)
assert times_areas[0, 0] == history.time_stamps[2]
assert times_areas[-1, 0] == history.time_stamps[8]
assert set(times_areas[:, 0]).issubset(history.time_stamps)

times_areas = np.array(
[
[t, s.face_df.loc[0, "area"]]
for t, s in history.browse(2, 8, 4, endpoint=False)
]
)
assert times_areas.shape == (4, 2)
assert times_areas[0, 0] == history.time_stamps[2]
assert times_areas[-1, 0] == history.time_stamps[7]
assert set(times_areas[:, 0]).issubset(history.time_stamps)

times_areas = np.array(
[
[t, s.face_df.loc[0, "area"]]
for t, s in history.browse(2, 8, 4, endpoint=True)
]
)
assert times_areas.shape == (4, 2)
assert times_areas[0, 0] == history.time_stamps[2]
assert times_areas[-1, 0] == history.time_stamps[8]
assert set(times_areas[:, 0]).issubset(history.time_stamps)

times_areas = np.array(
[[t, s.face_df.loc[0, "area"]] for t, s in history.browse(2, 8, 10)]
)
assert times_areas.shape == (10, 2)
assert times_areas[0, 0] == history.time_stamps[2]
assert times_areas[-1, 0] == history.time_stamps[8]
assert set(times_areas[:, 0]).issubset(history.time_stamps)

times_areas = np.array(
[[t, s.edge_df.loc[0, "length"]] for t, s in history.browse(size=40)]
)
assert times_areas.shape == (40, 2)
assert set(times_areas[:, 0]) == set(history.time_stamps)


def test_overwrite_time():
sheet = Sheet("3", *three_faces_sheet())
history = History(sheet)
Expand Down Expand Up @@ -232,6 +288,13 @@ def test_historyHDF5_from_archive():
os.remove("test.hf5")


def test_retrieve_coords():
sheet = Sheet("3", *three_faces_sheet())
history = History(sheet)
history.record()
assert history.retrieve(0).coords == sheet.coords


def test_to_and_from_archive():

sheet = Sheet("3", *three_faces_sheet())
Expand Down
154 changes: 2 additions & 152 deletions tests/core/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,159 +492,9 @@ def test_polygons():
fp = eptm.face_polygons()

eptm.reset_index(order=True)
expected_res = [
[
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[1.5, 0.866, 0.0],
[1.0, 1.732, 0.0],
[0.0, 1.732, 0.0],
[-0.5, 0.866, 0.0],
],
[
[-1.5, -0.866, 0.0],
[-0.5, -0.866, 0.0],
[0.0, 0.0, 0.0],
[-0.5, 0.866, 0.0],
[-1.5, 0.866, 0.0],
[-2.0, 0.0, 0.0],
],
[
[0.0, -1.732, 0.0],
[1.0, -1.732, 0.0],
[1.5, -0.866, 0.0],
[1.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
[-0.5, -0.866, 0.0],
],
[
[0.0, 0.0, 0.0],
[0.33333333, 0.0, 0.0],
[0.5, 0.28866667, 0.0],
[0.33333333, 0.57733333, 0.0],
[0.0, 0.57733333, 0.0],
[-0.16666667, 0.28866667, 0.0],
],
[
[-0.5, -0.28866667, 0.0],
[-0.16666667, -0.28866667, 0.0],
[0.0, 0.0, 0.0],
[-0.16666667, 0.28866667, 0.0],
[-0.5, 0.28866667, 0.0],
[-0.66666667, 0.0, 0.0],
],
[
[0.0, -0.57733333, 0.0],
[0.33333333, -0.57733333, 0.0],
[0.5, -0.28866667, 0.0],
[0.33333333, 0.0, 0.0],
[0.0, 0.0, 0.0],
[-0.16666667, -0.28866667, 0.0],
],
[[1.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.33333333, 0.0, 0.0]],
[
[0.5, 0.28866667, 0.0],
[0.33333333, 0.0, 0.0],
[1.0, 0.0, 0.0],
[1.5, 0.866, 0.0],
],
[
[0.33333333, 0.57733333, 0.0],
[0.5, 0.28866667, 0.0],
[1.5, 0.866, 0.0],
[1.0, 1.732, 0.0],
],
[
[0.0, 0.57733333, 0.0],
[0.33333333, 0.57733333, 0.0],
[1.0, 1.732, 0.0],
[0.0, 1.732, 0.0],
],
[
[-0.5, 0.866, 0.0],
[-0.16666667, 0.28866667, 0.0],
[0.0, 0.57733333, 0.0],
[0.0, 1.732, 0.0],
],
[
[0.0, 0.0, 0.0],
[-0.16666667, 0.28866667, 0.0],
[0.0, 0.0, 0.0],
[-0.5, 0.866, 0.0],
],
[
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
[-0.16666667, 0.28866667, 0.0],
[-0.5, 0.866, 0.0],
],
[
[-0.5, 0.28866667, 0.0],
[-0.16666667, 0.28866667, 0.0],
[-0.5, 0.866, 0.0],
[-1.5, 0.866, 0.0],
],
[
[-2.0, 0.0, 0.0],
[-0.66666667, 0.0, 0.0],
[-0.5, 0.28866667, 0.0],
[-1.5, 0.866, 0.0],
],
[
[-1.5, -0.866, 0.0],
[-0.5, -0.28866667, 0.0],
[-0.66666667, 0.0, 0.0],
[-2.0, 0.0, 0.0],
],
[
[-1.5, -0.866, 0.0],
[-0.5, -0.866, 0.0],
[-0.16666667, -0.28866667, 0.0],
[-0.5, -0.28866667, 0.0],
],
[
[-0.5, -0.866, 0.0],
[0.0, 0.0, 0.0],
[-0.16666667, -0.28866667, 0.0],
[0.0, 0.0, 0.0],
],
[
[-0.5, -0.866, 0.0],
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
[-0.16666667, -0.28866667, 0.0],
],
[
[0.0, -1.732, 0.0],
[0.0, -0.57733333, 0.0],
[-0.16666667, -0.28866667, 0.0],
[-0.5, -0.866, 0.0],
],
[
[0.0, -1.732, 0.0],
[1.0, -1.732, 0.0],
[0.33333333, -0.57733333, 0.0],
[0.0, -0.57733333, 0.0],
],
[
[1.0, -1.732, 0.0],
[1.5, -0.866, 0.0],
[0.5, -0.28866667, 0.0],
[0.33333333, -0.57733333, 0.0],
],
[
[1.5, -0.866, 0.0],
[1.0, 0.0, 0.0],
[0.33333333, 0.0, 0.0],
[0.5, -0.28866667, 0.0],
],
[[1.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.33333333, 0.0, 0.0], [0.0, 0.0, 0.0]],
]
expected_res = [np.array(poly) for poly in expected_res]

res = eptm.face_polygons(["x", "y", "z"])
for i in range(res.shape[0]):
np.testing.assert_almost_equal(expected_res[i], res[i], decimal=4)
shapes = res.apply(lambda s: s.shape in ((6, 3), (4, 3)))
assert all(shapes)


def test_face_polygons_exception():
Expand Down
23 changes: 9 additions & 14 deletions tests/draw/test_plt.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_sheet_view(self):
0.0, 1.0, num=self.sheet.edge_df.shape[0]
)[::-1]

self.draw_specs["edge"]["visible"] = True
self.draw_specs["edge"]["visible"] = True
self.draw_specs["edge"]["color"] = self.sheet.edge_df["rand"] # [0, 0, 0, 1]
self.draw_specs["edge"]["alpha"] = 1.0
self.draw_specs["edge"]["color_range"] = 0, 3
Expand Down Expand Up @@ -145,13 +145,11 @@ def test_create_gif():
sheet.edge_df.loc[[1], "line_tension"] *= 8
res = solver.solve(0.5, dt=0.05)

with pytest.raises(ValueError):
create_gif(history, "frames.gif")
create_gif(history, "frames.gif", num_frames=5)
create_gif(history, "interval.gif", interval=(2, 4))

assert os.path.isfile("frames.gif") == True
assert os.path.isfile("interval.gif") == True
assert os.path.isfile("frames.gif")
assert os.path.isfile("interval.gif")

os.remove("frames.gif")
os.remove("interval.gif")
Expand All @@ -161,13 +159,10 @@ def test_plot_forces():
geom = SheetGeometry
model = PlanarModel
sheet = Sheet("3", *three_faces_sheet())
sheet.update_specs(model.specs)
sheet.update_specs(model.specs)
geom.update_all(sheet)
fig, ax = plot_forces(sheet,
geom,
model,
list('xy'),
0.05,
**{'extract': {'x_boundary': (-10, 10)}})

assert ax.lines[0].get_xydata().shape == (54, 2)
fig, ax = plot_forces(
sheet, geom, model, list("xy"), 0.05, **{"extract": {"x_boundary": (-10, 10)}}
)

assert ax.lines[0].get_xydata().shape == (54, 2)
25 changes: 25 additions & 0 deletions tests/io/test_hdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import tempfile
import numpy as np
import pandas as pd

from tyssue.generation import three_faces_sheet
from tyssue import Sheet
from tyssue.io import hdf5


def test_save_datasets():
sheet = Sheet("test", *three_faces_sheet())
fh = tempfile.mktemp(suffix=".hdf5")
hdf5.save_datasets(fh, sheet)
with pd.HDFStore(fh) as st:
for key in sheet.datasets:
assert key in st


def test_load_datasets():
sheet = Sheet("test", *three_faces_sheet())
fh = tempfile.mktemp(suffix=".hdf5")
hdf5.save_datasets(fh, sheet)

datasets = hdf5.load_datasets(fh)
assert np.all(datasets["vert"][sheet.vert_df.columns] == sheet.vert_df)
31 changes: 31 additions & 0 deletions tests/io/test_zarr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import tempfile
import numpy as np
import pandas as pd
import zarr as zr

from tyssue.generation import three_faces_sheet
from tyssue import Sheet
from tyssue.io import zarr


def test_save_datasets():
sheet = Sheet("test", *three_faces_sheet())
fh = tempfile.mktemp(suffix=".zarr")
zarr.save_datasets(fh, sheet)
with zr.open(fh) as st:
for key in sheet.datasets:
assert key in st


def test_load_datasets():
sheet = Sheet("test", *three_faces_sheet())
sheet.settings["test"] = 3
fh = tempfile.mktemp(suffix=".zarr")
zarr.save_datasets(fh, sheet)
datasets, settings = zarr.load_datasets(fh)
assert np.all(datasets["vert"][sheet.vert_df.columns] == sheet.vert_df)
assert settings == sheet.settings
sheet.settings["test"] = np.zeros(4)
zarr.save_datasets(fh, sheet)
datasets, settings = zarr.load_datasets(fh)
assert settings["test"] == [0.0, 0.0, 0.0, 0.0]
Loading