Beispiel #1
0
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_find_transitions():

    sheet = Sheet.planar_sheet_3d("sheet", 5, 5, 1, 1)
    sheet.sanitize()
    datasets = extrude(sheet.datasets, method="translation")

    eptm = Monolayer("test_IHt", datasets, bulk_spec())
    BulkGeometry.update_all(eptm)
    eptm.settings["threshold_length"] = 1e-3
    IH_transition(eptm, 26)
    BulkGeometry.update_all(eptm)

    eptm.settings["threshold_length"] = 1e-2
    ih, hi = find_rearangements(eptm)

    assert len(ih) == 0
    assert len(hi) == 2
    assert len(find_HIs(eptm))

    face = eptm.face_df.index[-1]
    HI_transition(eptm, face)
    BulkGeometry.update_all(eptm)

    eptm.settings["threshold_length"] = 2e-1

    ih, hi = find_rearangements(eptm)
    assert len(ih) == 1
    assert len(hi) == 0

    assert len(find_IHs(eptm))
Beispiel #3
0
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
Beispiel #4
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
Beispiel #5
0
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()
Beispiel #6
0
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()
Beispiel #7
0
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)
Beispiel #8
0
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)
Beispiel #9
0
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]))
Beispiel #10
0
def test_apoptosis():
    specs = config.geometry.bulk_spec()
    sheet = Sheet.planar_sheet_3d("flat", 4, 5, 1, 1)
    sheet.sanitize()
    datasets = extrude(sheet.datasets, method="translation")
    mono = Monolayer("mono", datasets, specs)
    mono.face_df["id"] = mono.face_df.index.values
    geom.center(mono)
    geom.update_all(mono)
    mono.face_df["contractility"] = 1.0
    manager = EventManager("face")
    cell_id = 0
    apical_face = mono.face_df[
        (mono.face_df.index.isin(mono.get_orbits("cell", "face")[cell_id]))
        & (mono.face_df.segment == "apical")].index[0]
    sheet.settings["apoptosis"] = {"cell_id": cell_id}
    initial_cell_event = [(apoptosis, sheet.settings["apoptosis"])]

    manager.extend(initial_cell_event)
    manager.execute(mono)
    manager.update()
    assert len(manager.current) == 1

    i = 0
    while i < 5:
        manager.execute(mono)
        manager.update()
        i = i + 1

    assert mono.face_df.loc[apical_face, "contractility"] > 1.0
Beispiel #11
0
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")
Beispiel #12
0
    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_iso_solver():

    pth = os.path.join(stores_dir, "rod_sheet.hf5")
    datasets = load_datasets(pth)
    specs = config.geometry.rod_sheet()
    sheet = Sheet("rod", datasets, specs)
    geom.reset_scafold(sheet)
    geom.update_all(sheet)

    dyn_specs = config.dynamics.quasistatic_sheet_spec()
    dyn_specs["vert"]["basal_shift"] = 0.0
    dyn_specs["face"]["prefered_vol"] = 1.0

    sheet.update_specs(dyn_specs, reset=True)
    geom.update_all(sheet)
    res = bruteforce_isotropic_relax(sheet, geom, model)
    assert_almost_equal(res["x"], 1.6001116383)
Beispiel #14
0
def test_change_col_types():
    sheet = Sheet("3", *three_faces_sheet())
    history = HistoryHdf5(
        sheet,
        extra_cols={
            "face": sheet.face_df.columns,
            "edge": list(sheet.edge_df.columns),
            "vert": list(sheet.vert_df.columns),
        },
        hf5file="test.hf5",
    )
    history.record()
    history.record()
    sheet.face_df["z"] = "abc"
    with pytest.raises(ValueError):
        history.record()
    os.remove("test.hf5")
Beispiel #15
0
def test_unsaved_col():
    sheet = Sheet("3", *three_faces_sheet())
    history = HistoryHdf5(
        sheet,
        extra_cols={
            "face": sheet.face_df.columns,
            "edge": list(sheet.edge_df.columns),
            "vert": list(sheet.vert_df.columns),
        },
        hf5file="test.hf5",
    )
    history.record()
    history.record()
    sheet.face_df["new_col"] = 0
    with pytest.warns(UserWarning):
        history.record()
    os.remove("test.hf5")
Beispiel #16
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
Beispiel #17
0
def test_x_and_y_boundary_celldiv():
    dsets = hdf5.load_datasets(
        Path(stores.stores_dir) / "planar_periodic8x8.hf5")
    specs = config.geometry.planar_sheet()
    specs["settings"]["boundaries"] = {"x": [-0.1, 8.1], "y": [-0.1, 8.1]}
    sheet = Sheet("periodic", dsets, specs)
    coords = ["x", "y"]
    draw_specs = config.draw.sheet_spec()
    PlanarGeometry.update_all(sheet)
    Nf = sheet.Nf
    # arbitrarily choose a cells on x_boundary and y_boundary to divide
    div_cell = sheet.face_df.index[(sheet.face_df["at_x_boundary"] == True)
                                   &
                                   (sheet.face_df["at_y_boundary"] == True)][0]
    daughter = cell_division(sheet, div_cell, PlanarGeometry, angle=0.6)
    assert sheet.validate()
    assert sheet.Nf == Nf + 1
Beispiel #18
0
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]
Beispiel #19
0
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
Beispiel #20
0
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")
Beispiel #21
0
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]
Beispiel #22
0
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
Beispiel #23
0
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)
Beispiel #24
0
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
Beispiel #25
0
def test_warning():

    sheet = Sheet("3", *three_faces_sheet())
    with pytest.warns(UserWarning):
        History(sheet,
                extra_cols={
                    "edge": ["dx"],
                    "face": ["area"],
                    "vert": ["segment"]
                })
Beispiel #26
0
def test_save_triangulated():

    sheet = Sheet("test", *three_faces_sheet())

    fh = tempfile.mktemp(suffix=".obj")
    obj.save_triangulated(fh, sheet)
    with open(fh) as fb:
        lines = fb.readlines()
    assert len(lines) == 40
    assert "# 16 vertices" in lines[4]
Beispiel #27
0
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)
Beispiel #28
0
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
Beispiel #29
0
def test_save_splitted():

    sheet = Sheet("test", *three_faces_sheet())

    fh = tempfile.mktemp(suffix=".obj")
    obj.save_splitted_cells(fh, sheet)
    with open(fh) as fb:
        lines = fb.readlines()
    assert len(lines) == 63
    assert "# 39 vertices" in lines[4]
Beispiel #30
0
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
    ipv.clear()
    fig, (edge_mesh, face_mesh) = sheet_view(sheet,
                                             face=face_spec,
                                             edge=edge_spec)
    assert face_mesh.triangles.shape == (6, 3)

    ipv.clear()
    edge_spec = {"color": lambda sheet: sheet.edge_df["dx"], "visible": True}
    face_spec = {"color": lambda sheet: sheet.face_df["area"], "visible": True}
    fig, (edge_mesh, face_mesh) = sheet_view(sheet,
                                             face=face_spec,
                                             edge=edge_spec)
    assert face_mesh.color.shape == (13, 3)