def test_save_import_triangular_mesh(): sheet = Sheet("test", *three_faces_sheet()) fh = tempfile.mktemp(suffix=".obj") meshes.save_triangular_mesh(fh, sheet) data = meshes.import_triangular_mesh(fh) sheet = Sheet('test', data) geom.update_all(sheet) assert sheet.Nf == 18 assert sheet.Ne == 54 assert sheet.Nv == 16
def test_sheet_view(): sheet = Sheet("test", *three_faces_sheet()) SheetGeometry.update_all(sheet) face_spec = { "color": pd.Series(range(3)), "color_range": (0, 3), "visible": True, "colormap": "Blues", "epsilon": 0.1, } color = pd.DataFrame(np.zeros((sheet.Ne, 3)), index=sheet.edge_df.index, columns=["R", "G", "B"]) color.loc[0, "R"] = 0.8 edge_spec = {"color": color, "visible": True} fig, (edge_mesh, face_mesh) = sheet_view(sheet, face=face_spec, edge=edge_spec) assert face_mesh.color.shape == (39, 3) assert face_mesh.triangles.shape == (18, 3) assert face_mesh.lines is None assert edge_mesh.triangles is None assert edge_mesh.lines.shape == (18, 2) sheet.face_df["visible"] = False sheet.face_df.loc[0, "visible"] = True fig, (edge_mesh, face_mesh) = sheet_view(sheet, face=face_spec, edge=edge_spec) assert face_mesh.triangles.shape == (6, 3)
def test_retrieve(): sheet = Sheet("3", *three_faces_sheet()) history = History(sheet, {"face": ["area"]}) sheet_ = history.retrieve(0) for elem, dset in sheet_.datasets.items(): assert dset.shape[0] == sheet.datasets[elem].shape[0] assert "area" in sheet_.datasets["face"].columns sheet_ = history.retrieve(1) for elem, dset in sheet_.datasets.items(): assert dset.shape[0] == sheet.datasets[elem].shape[0] sheet.vert_df.loc[0, "x"] = 100 sheet.face_df["area"] = 100 history.record() sheet_ = history.retrieve(1) for elem, dset in sheet_.datasets.items(): assert dset.shape[0] == sheet.datasets[elem].shape[0] print(dset) assert sheet_.datasets["vert"].loc[0, "x"] == 100 assert sheet_.datasets["face"].loc[0, "area"] != 100 history.record(["vert", "face"]) sheet_ = history.retrieve(2) assert sheet_.datasets["face"].loc[0, "area"] == 100 sheet_ = history.retrieve(1) assert sheet_.datasets["face"].loc[0, "area"] != 100
def test_historyHDF5_itemsize(): sheet = Sheet("3", *three_faces_sheet()) sheet.vert_df["segment"] = "apical" history = HistoryHdf5(sheet, extra_cols={ "edge": ["dx"], "face": ["area"], "vert": ["segment"] }) for element in sheet.datasets: assert sheet.datasets[element].shape[0] == history.datasets[ element].shape[0] sheet.vert_df.loc[0, "segment"] = "" history.record(time_stamp=1) sheet.vert_df.loc[0, "segment"] = "lateral" history.record(time_stamp=2) sheet.face_df.loc[0, "area"] = 12.0 history.record(time_stamp=3, sheet=sheet) sheet1_ = history.retrieve(1) assert sheet1_.vert_df.loc[0, "segment"] == "" sheet2_ = history.retrieve(2) assert sheet2_.vert_df.loc[0, "segment"] == "lateral" sheet3_ = history.retrieve(3) assert sheet3_.face_df.loc[0, "area"] == 12.0 os.remove("out.hf5")
def test_spherical_update_height(): datasets, _ = three_faces_sheet(zaxis=True) specs = config.geometry.spherical_sheet() eptm = Sheet("3faces_3D", datasets, specs) expected_rho = pd.Series([ 0.0, 1.0, 1.7320381058163818, 1.9999559995159892, 1.732, 0.99997799975799462, 1.7320381058163818, 2.0, 1.7320381058163818, 0.99997799975799462, 1.732, 1.9999559995159892, 1.7320381058163818, ]) expected_height = expected_rho - eptm.vert_df["basal_shift"] SheetGeometry.update_all(eptm) assert all((eptm.vert_df["rho"] - expected_rho)**2 < TOLERANCE) assert all((eptm.vert_df["height"] - expected_height)**2 < TOLERANCE)
def test_retrieve(): sheet = Sheet("3", *three_faces_sheet()) history = History(sheet) sheet_ = history.retrieve(0) for elem, dset in sheet_.datasets.items(): assert dset.shape[0] == sheet.datasets[elem].shape[0] assert "area" in sheet_.datasets["face"].columns with pytest.warns(UserWarning): sheet_ = history.retrieve(1) for elem, dset in sheet_.datasets.items(): assert dset.shape[0] == sheet.datasets[elem].shape[0] sheet.vert_df.loc[0, "x"] = 100.0 sheet.face_df["area"] = 100.0 history.record() sheet_ = history.retrieve(1) for elem, dset in sheet_.datasets.items(): assert dset.shape[0] == sheet.datasets[elem].shape[0] print(dset) assert sheet_.datasets["vert"].loc[0, "x"] == 100.0 assert sheet_.datasets["face"].loc[0, "area"] == 100.0 history.record() sheet_ = history.retrieve(2) assert sheet_.datasets["face"].loc[0, "area"] == 100.0 sheet_ = history.retrieve(1) assert sheet_.datasets["face"].loc[0, "area"] == 100.0
def test_ar_calculation(): sheet = Sheet("test", *three_faces_sheet()) SheetGeometry.update_all(sheet) sheet.face_df["AR"] = utils.ar_calculation(sheet, coords=["x", "y"]) sheet.vert_df["x"] = sheet.vert_df["x"] * 2 sheet.face_df["AR2"] = utils.ar_calculation(sheet, coords=["x", "y"]) assert_allclose(sheet.face_df["AR2"], 2 * sheet.face_df["AR"])
def test_effector(): sheet_dsets, specs = three_faces_sheet() sheet = Sheet("test", sheet_dsets, specs) mono = Monolayer.from_flat_sheet("test", sheet, config.geometry.bulk_spec()) testing.effector_tester(mono, BorderElasticity)
def test_sheet_view(): sheet = Sheet("test", *three_faces_sheet()) SheetGeometry.update_all(sheet) face_spec = { "color": pd.Series(range(3)), "color_range": (0, 3), "visible": True, "colormap": "Blues", "epsilon": 0.1, } color = pd.DataFrame( np.zeros((sheet.Ne, 3)), index=sheet.edge_df.index, columns=["R", "G", "B"] ) color.loc[0, "R"] = 0.8 edge_spec = {"color": color, "visible": True} canvas, view = sheet_view(sheet, face=face_spec, edge=edge_spec, interactive=False) content = view.scene.children edge_mesh, face_mesh = content[-2:] assert face_mesh.mesh_data.get_face_colors().shape == (18, 4) assert face_mesh.mesh_data.get_faces().shape == (18, 3) assert edge_mesh.pos.shape == (13, 3)
def test_historyHDF5_save_every(): sheet = Sheet("3", *three_faces_sheet()) history = HistoryHdf5(sheet, extra_cols={"edge": ["dx"]}, save_every=2, dt=1) for element in sheet.datasets: assert sheet.datasets[element].shape[0] == history.datasets[ element].shape[0] for i in range(6): history.record(time_stamp=i) sheet_ = history.retrieve(0) for elem, dset in sheet_.datasets.items(): assert dset.shape[0] == sheet.datasets[elem].shape[0] assert dset.time.unique()[0] == 0 sheet_ = history.retrieve(1) for elem, dset in sheet_.datasets.items(): assert dset.shape[0] == sheet.datasets[elem].shape[0] assert dset.time.unique()[0] == 0 sheet_ = history.retrieve(2) for elem, dset in sheet_.datasets.items(): assert dset.shape[0] == sheet.datasets[elem].shape[0] assert dset.time.unique()[0] == 2 os.remove("out.hf5")
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 initiate_ellipsoid(dataset_path, json_path): """ Create ellipsoid tissue as a sheet with mesodermal cells dataset_path: initial hf45 file json_path: json spec file """ dsets = hdf5.load_datasets(dataset_path, data_names=['vert', 'edge', 'face']) with open(json_path, 'r+') as fp: specs = json.load(fp) sheet = Sheet('ellipse', dsets, specs) # Modify some initial value sheet.settings['threshold_length'] = 1e-3 sheet.settings['vitelline_space'] = 0.2 sheet.vert_df['radial_tension'] = 0. sheet.settings['lumen_prefered_vol'] = 4539601.384437251 sheet.settings['lumen_vol_elasticity'] = 3.e-6 sheet.edge_df.cell = np.nan # Define mesoderm and relaxating cells define_mesoderm(sheet, 145, 40) define_relaxation_cells(sheet, 140, 33, 145, 40) return sheet
def test_historyHDF5_save_every(): sheet = Sheet("3", *three_faces_sheet()) history = HistoryHdf5( sheet, save_every=2, dt=1, hf5file="out.hf5", ) for element in sheet.datasets: assert sheet.datasets[element].shape[0] == history.datasets[ element].shape[0] for i in range(6): history.record(time_stamp=i) sheet_ = history.retrieve(0) for elem, dset in sheet_.datasets.items(): assert dset.shape[0] == sheet.datasets[elem].shape[0] assert dset.time.unique()[0] == 0 sheet_ = history.retrieve(1) for elem, dset in sheet_.datasets.items(): assert dset.shape[0] == sheet.datasets[elem].shape[0] assert dset.time.unique()[0] == 0 sheet_ = history.retrieve(2) for elem, dset in sheet_.datasets.items(): assert dset.shape[0] == sheet.datasets[elem].shape[0] assert dset.time.unique()[0] == 2 for p in Path(".").glob("out*.hf5"): p.unlink()
def test_sheet_view(self): self.sheet = Sheet("test", *three_faces_sheet()) self.sheet.vert_df["rand"] = np.linspace( 0.0, 1.0, num=self.sheet.vert_df.shape[0]) cmap = plt.cm.get_cmap("viridis") color_cmap = cmap(self.sheet.vert_df.rand) self.draw_specs["vert"]["color"] = color_cmap self.draw_specs["vert"]["alpha"] = 0.5 self.draw_specs["vert"]["s"] = 500 self.sheet.face_df["col"] = np.linspace( 0.0, 1.0, num=self.sheet.face_df.shape[0]) self.draw_specs["face"]["color"] = self.sheet.face_df["col"] self.draw_specs["face"]["visible"] = True self.draw_specs["face"]["alpha"] = 0.5 self.sheet.edge_df["rand"] = np.linspace( 0.0, 1.0, num=self.sheet.edge_df.shape[0])[::-1] 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 self.draw_specs["edge"]["width"] = 1.0 * np.linspace( 0.0, 1.0, num=self.sheet.edge_df.shape[0]) fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs) assert len(ax.collections) == 3 assert ax.collections[0].get_edgecolors().shape == (13, 4) assert ax.collections[1].get_edgecolors().shape == (18, 4) assert ax.collections[2].get_edgecolors().shape == (0, 4) assert ax.collections[2].get_facecolors().shape == (3, 4)
def test_create_gif(): geom = SheetGeometry model = PlanarModel sheet = Sheet("3", *three_faces_sheet()) geom.update_all(sheet) sheet.settings["threshold_length"] = 0.1 sheet.update_specs(config.dynamics.quasistatic_plane_spec()) sheet.face_df["prefered_area"] = sheet.face_df["area"].mean() history = History(sheet) solver = EulerSolver(sheet, geom, model, history=history, auto_reconnect=True) sheet.vert_df["viscosity"] = 0.1 sheet.edge_df.loc[[0, 17], "line_tension"] *= 2 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 os.remove("frames.gif") os.remove("interval.gif")
def test_historyHDF5_save_other_sheet(): sheet = Sheet("3", *three_faces_sheet()) history = HistoryHdf5( sheet, save_only={ "edge": ["dx"], "face": ["area"], "vert": ["segment"] }, hf5file="out.hf5", ) for element in sheet.datasets: assert sheet.datasets[element].shape[0] == history.datasets[ element].shape[0] sheet.face_df.loc[0, "area"] = 1.0 history.record(time_stamp=1) sheet.face_df.loc[0, "area"] = 12.0 history.record(time_stamp=2, sheet=sheet) sheet1_ = history.retrieve(1) assert sheet1_.face_df.loc[0, "area"] == 1.0 sheet2_ = history.retrieve(2) assert sheet2_.face_df.loc[0, "area"] == 12.0 for p in Path(".").glob("out*.hf5"): p.unlink()
def test_historyHDF5_itemsize(): sheet = Sheet("3", *three_faces_sheet()) sheet.vert_df["segment"] = "apical" history = HistoryHdf5( sheet, hf5file="out.hf5", ) for element in sheet.datasets: assert sheet.datasets[element].shape[0] == history.datasets[ element].shape[0] sheet.vert_df.loc[0, "segment"] = "" history.record(time_stamp=1) sheet.vert_df.loc[0, "segment"] = "lateral" history.record(time_stamp=2) sheet.face_df.loc[0, "area"] = 12.0 history.record(time_stamp=3, sheet=sheet) sheet1_ = history.retrieve(1) assert sheet1_.vert_df.loc[0, "segment"] == "" sheet2_ = history.retrieve(2) assert sheet2_.vert_df.loc[0, "segment"] == "lateral" sheet3_ = history.retrieve(3) assert sheet3_.face_df.loc[0, "area"] == 12.0 for p in Path(".").glob("out*.hf5"): p.unlink()
def test_length_grad(): sheet = Sheet("etst", *generation.three_faces_sheet()) SheetGeometry.update_all(sheet) lg = length_grad(sheet) assert np.all(lg.loc[0].values == np.array([-1, 0, 0]))
def test_overwrite_time(): sheet = Sheet("3", *three_faces_sheet()) history = History(sheet) history.record(time_stamp=1) history.record(time_stamp=1) sheet_ = history.retrieve(1) assert sheet_.Nv == sheet.Nv
def test_write_storm(): sheet = Sheet("test", *three_faces_sheet()) fh = tempfile.mktemp(suffix=".csv") csv.write_storm_csv(fh, sheet.vert_df[sheet.coords]) with open(fh) as fb: lines = fb.readlines() assert len(lines) == 14 assert "frame" in lines[0]
def test_overwrite_tim_hdf5e(): sheet = Sheet("3", *three_faces_sheet()) history = HistoryHdf5(sheet, hf5file="out.hf5") history.record(time_stamp=1) history.record(time_stamp=1) sheet_ = history.retrieve(1) os.remove("out.hf5") assert sheet_.Nv == sheet.Nv
def test_rod_update_height(): pth = os.path.join(CURRENT_DIR, '../../stores/rod_sheet.hf5') datasets = load_datasets(pth) specs = config.geometry.rod_sheet() sheet = Sheet('rod', datasets, specs) SheetGeometry.update_all(sheet) assert (sheet.vert_df.rho.mean() - 0.7895479495559642)**2 < TOLERANCE
def test_rod_update_height(): pth = os.path.join(stores_dir, "rod_sheet.hf5") datasets = load_datasets(pth) specs = config.geometry.rod_sheet() sheet = Sheet("rod", datasets, specs) SheetGeometry.update_all(sheet) assert (sheet.vert_df.rho.mean() - 0.96074585429756632)**2 < TOLERANCE
def test_models(): sheet_dsets, specs = three_faces_sheet() sheet = Sheet("test", sheet_dsets, specs) mono = Monolayer.from_flat_sheet("test", sheet, config.geometry.bulk_spec()) testing.model_tester(mono, BulkModel) testing.model_tester(mono, BulkModelwithFreeBorders)
def test_write_junction_mesh(): sheet = Sheet("test", *three_faces_sheet()) fh = tempfile.mktemp(suffix=".obj") obj.save_junction_mesh(fh, sheet) with open(fh) as fb: lines = fb.readlines() assert len(lines) == 35 assert "# 13 vertices" in lines[4]
def test_cell_centered_patch(): grid = hexa_grid2d(6, 4, 3, 3) datasets = from_2d_voronoi(Voronoi(grid)) _ = Sheet("test", datasets) extruded = extrude(datasets, method="translation") mono = Monolayer("test", extruded, config.geometry.bulk_spec()) submono = utils.cell_centered_patch(mono, 5, 1) assert submono.Nc == 4
def test_warning(): sheet = Sheet("3", *three_faces_sheet()) with pytest.warns(UserWarning): History(sheet, extra_cols={ "edge": ["dx"], "face": ["area"], "vert": ["segment"] })
def test_data_at_opposite_df(): sheet = Sheet("emin", *three_faces_sheet()) geom.update_all(sheet) sheet.get_opposite() opp = utils.data_at_opposite(sheet, sheet.edge_df[["dx", "dy"]], free_value=None) assert opp.shape == (sheet.Ne, 2) assert list(opp.columns) == ["dx", "dy"]
def test_data_at_opposite_array(): sheet = Sheet("emin", *three_faces_sheet()) geom.update_all(sheet) sheet.get_opposite() opp = utils.data_at_opposite(sheet, sheet.edge_df[["dx", "dy"]].to_numpy(), free_value=None) assert opp.shape == (sheet.Ne, 2) assert_array_equal(opp.index, sheet.edge_df.index)
def main(): # --------- Chargement d'un fichier HDF5 --------- # dsets = hdf5.load_datasets("data/with_collisions.hf5", data_names=["vert", "edge", "face"]) specs = config.geometry.cylindrical_sheet() sheet = Sheet("ellipse", dsets, specs) SheetGeometry.update_all(sheet) list_intersected_facesolve_intersection(sheet)