Ejemplo n.º 1
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"])
Ejemplo n.º 2
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)
Ejemplo n.º 3
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

    fig, (edge_mesh, face_mesh) = sheet_view(sheet,
                                             face=face_spec,
                                             edge=edge_spec)
    assert face_mesh.triangles.shape == (6, 3)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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]))
Ejemplo n.º 6
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
Ejemplo n.º 7
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
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
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"]
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
def test_get_phis():
    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)
    sheet.edge_df["sphi"] = SheetGeometry.get_phis(sheet)

    assert np.all(
        sheet.edge_df.sort_values(["face", "sphi"]).groupby("face").apply(
            lambda df: np.roll(df["trgt"], 1) == df["srce"]))
Ejemplo n.º 13
0
def get_ventral_patch(fname):

    sim_dsets = hdf5.load_datasets(fname)
    sheet = Sheet('morph', sim_dsets, config.geometry.flat_sheet())
    to_crop = sheet.cut_out(
        [[-300, 300], [sheet.vert_df.y.max() - 22,
                       sheet.vert_df.y.max() + 1], [-300, 300]], )

    sheet.remove(to_crop)
    sheet.vert_df[['x', 'y', 'z']] = sheet.vert_df[['x', 'z', 'y']]
    SheetGeometry.update_all(sheet)
    return sheet
Ejemplo n.º 14
0
def test_detection():
    sheet = Sheet("crossed",
                  hdf5.load_datasets(Path(stores_dir) / "sheet6x5.hf5"))
    sheet.vert_df.z = 5 * sheet.vert_df.x**2
    # sheet.vert_df[sheet.coords] += np.random.normal(scale=0.001, size=(sheet.Nv, 3))
    SheetGeometry.update_all(sheet)

    sheet.vert_df.x -= 35 * (sheet.vert_df.x / 2)**3
    SheetGeometry.update_all(sheet)
    colliding_edges = set(collisions.self_intersections(sheet).flatten())
    expected = {32, 1, 34, 9, 35}
    assert colliding_edges == expected
Ejemplo n.º 15
0
def test_data_at_opposite():
    sheet = Sheet("emin", *three_faces_sheet())
    geom.update_all(sheet)
    sheet.get_opposite()
    opp = utils.data_at_opposite(sheet,
                                 sheet.edge_df["length"],
                                 free_value=None)

    assert opp.shape == (sheet.Ne, )
    assert opp.loc[0] == 1.0
    assert ~np.isfinite(opp.loc[1])
    opp = utils.data_at_opposite(sheet, sheet.edge_df["length"], free_value=-1)
    assert opp.loc[1] == -1.0
Ejemplo n.º 16
0
def test_solving():

    sheet = Sheet("crossed",
                  hdf5.load_datasets(Path(stores_dir) / "sheet6x5.hf5"))
    sheet.vert_df.z = 5 * sheet.vert_df.x**2
    SheetGeometry.update_all(sheet)
    positions_buffer = sheet.vert_df[sheet.coords].copy()

    sheet.vert_df.x -= 35 * (sheet.vert_df.x / 2)**3
    SheetGeometry.update_all(sheet)
    colliding_edges = collisions.self_intersections(sheet)
    boxes = solvers.CollidingBoxes(sheet, positions_buffer, colliding_edges)
    boxes.solve_collisions(shyness=0.01)
    assert collisions.self_intersections(sheet).size == 0
    assert sheet.vert_df.loc[[22, 12], "x"].diff().loc[12] == 0.01
Ejemplo n.º 17
0
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)
Ejemplo n.º 18
0
def test_scaled_unscaled():

    sheet = Sheet("3faces_3D", *three_faces_sheet())
    SheetGeometry.update_all(sheet)

    def mean_area():
        return sheet.face_df.area.mean()

    prev_area = sheet.face_df.area.mean()

    sc_area = utils.scaled_unscaled(mean_area, 2, sheet, SheetGeometry)
    post_area = sheet.face_df.area.mean()
    assert post_area == prev_area
    assert_almost_equal(sc_area / post_area, 4.0)

    def fails():
        raise ValueError

    with pytest.raises(ValueError):
        utils.scaled_unscaled(fails, 2, sheet, SheetGeometry)
        post_area = sheet.face_df.area.mean()
        assert post_area == prev_area
Ejemplo n.º 19
0
def test_periodic_planar():
    hdf_path = hdf5.load_datasets(
        os.path.join(stores_dir, "planar_periodic8x8.hf5"))
    specs = config.stores.planar_periodic8x8()
    sheet = Sheet("periodic", hdf_path, specs)
    PlanarGeometry.update_all(sheet)
    assert sheet.edge_df.length.max() < 1.0
    fsx = sheet.edge_df["fx"] - sheet.edge_df["sx"]
    fsy = sheet.edge_df["fy"] - sheet.edge_df["sy"]
    lai = (fsx**2 + fsy**2)**0.5
    assert lai.max() < 0.7
    assert sheet.face_df.area.max() < 1.2
    assert sheet.face_df.area.min() > 0.8

    sheet.update_specs(config.geometry.sheet_spec())
    sheet = Sheet("2.5D", sheet.datasets, sheet.specs)
    SheetGeometry.update_all(sheet)
    assert sheet.edge_df.length.max() < 1.0
    fsx = sheet.edge_df["fx"] - sheet.edge_df["sx"]
    fsy = sheet.edge_df["fy"] - sheet.edge_df["sy"]
    lai = (fsx**2 + fsy**2)**0.5
    assert lai.max() < 0.7
    assert sheet.face_df.area.max() < 1.2
    assert sheet.face_df.area.min() > 0.8
Ejemplo n.º 20
0
def test_already():
    # GH111
    sheet = Sheet("crossed",
                  hdf5.load_datasets(Path(stores_dir) / "sheet6x5.hf5"))
    sheet.vert_df.z = 5 * sheet.vert_df.x**2
    SheetGeometry.update_all(sheet)

    sheet.vert_df.x -= 35 * (sheet.vert_df.x / 2)**3
    SheetGeometry.update_all(sheet)
    positions_buffer = sheet.vert_df[sheet.coords].copy()
    sheet.vert_df.x -= 0.1 * (sheet.vert_df.x / 2)**3
    SheetGeometry.update_all(sheet)
    colliding_edges = collisions.self_intersections(sheet)
    boxes = solvers.CollidingBoxes(sheet, positions_buffer, colliding_edges)
    res = boxes.solve_collisions(shyness=0.01)
    colliding_edges = collisions.self_intersections(sheet)
    assert len(colliding_edges) == 0