def test_retrieve_bulk(): eptm = Epithelium("3", extrude(three_faces_sheet()[0])) RNRGeometry.update_all(eptm) history = History(eptm) eptm_ = history.retrieve(0) RNRGeometry.update_all(eptm_)
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_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_warning(): sheet = Sheet("3", *three_faces_sheet()) with pytest.warns(UserWarning): History(sheet, extra_cols={ "edge": ["dx"], "face": ["area"], "vert": ["segment"] })
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_to_and_from_archive(): sheet = Sheet("3", *three_faces_sheet()) history = History(sheet) history.record() history.record() history.record() history.to_archive("test.hf5") history_h = HistoryHdf5.from_archive("test.hf5") sheet_ = history_h.retrieve(2) try: assert sheet_.Nv == sheet.Nv finally: os.remove("test.hf5")
def test_euler(): geom = SheetGeometry model = PlanarModel sheet = Sheet("3", *three_faces_sheet()) geom.update_all(sheet) sheet.settings["threshold_length"] = 1e-3 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, with_t1=True, with_t3=True) sheet.vert_df["viscosity"] = 1.0 sheet.edge_df.loc[[0, 17], "line_tension"] *= 4 l0 = sheet.edge_df.loc[0, "length"] res = solver.solve(0.2, dt=0.05) assert sheet.edge_df.loc[0, "length"] < l0 assert len(solver.history) == 5
def test_simple_history(): sheet = Sheet("3", *three_faces_sheet()) history = History(sheet) assert "dx" in history.datasets["edge"].columns for element in sheet.datasets: assert sheet.datasets[element].shape[0] == history.datasets[ element].shape[0] history.record() assert sheet.datasets["vert"].shape[0] * 2 == history.datasets[ "vert"].shape[0] history.record() assert sheet.datasets["vert"].shape[0] * 3 == history.datasets[ "vert"].shape[0] assert sheet.datasets["face"].shape[0] * 3 == history.datasets[ "face"].shape[0] mono = Epithelium("eptm", extrude(sheet.datasets)) histo2 = History(mono) for element in mono.datasets: assert mono.datasets[element].shape[0] == histo2.datasets[ element].shape[0]
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_warning(): sheet = Sheet("3", *three_faces_sheet()) with pytest.warns(UserWarning): history = History(sheet, extra_cols={"vert": ["invalid_column"]})
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_retrieve_coords(): sheet = Sheet("3", *three_faces_sheet()) history = History(sheet) history.record() assert history.retrieve(0).coords == sheet.coords