Exemplo n.º 1
0
def test_update_specs():
    class BarrierElasticity(effectors.AbstractEffector):
        """
        Barrier use to maintain the tissue integrity.
        """

        dimensions = units.line_elasticity
        magnitude = "barrier_elasticity"
        label = "Barrier elasticity"
        element = "vert"
        specs = {
            "vert": {"barrier_elasticity": 1.2, "is_active": 1, "delta_rho": 0.0}
        }  # distance to a barrier membrane

        @staticmethod
        def energy(eptm):
            return eptm.vert_df.eval("delta_rho**2 * barrier_elasticity/2")

        @staticmethod
        def gradient(eptm):
            grad = np.zeros((eptm.Nv, 3))
            grad.columns = ["g" + c for c in eptm.coords]
            return grad, None

    model = factory.model_factory(
        [
            BarrierElasticity,
            effectors.LineTension,
            effectors.FaceAreaElasticity,
            effectors.FaceContractility,
        ]
    )
    sheet_dsets, specs = three_faces_sheet()
    sheet = Sheet("test", sheet_dsets, specs)
    sheet.update_specs(model.specs)
    assert sheet.vert_df.loc[0, "barrier_elasticity"] == 1.2
Exemplo n.º 2
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)
Exemplo n.º 3
0
def test_upcast_ndarray():
    datasets_2d, specs = three_faces_sheet(zaxis=True)
    datasets = extrude(datasets_2d)
    eptm = Epithelium("3faces_3D", datasets, specs)
    data = np.arange(eptm.Nv * 3).reshape((eptm.Nv, 3))
    assert eptm.upcast_srce(data).shape == (eptm.Ne, 3)
Exemplo n.º 4
0
def test_polygons():
    datasets_2d, specs = three_faces_sheet(zaxis=True)
    datasets = extrude(datasets_2d)
    eptm = Epithelium("3faces_3D", datasets, specs)
    eptm_2d = Epithelium("3faces_2D", datasets_2d, specs)

    dict_expected_res = {
        0: [
            [0.0, 0.0, 0.0],
            [1.0, 0.0, 0.0],
            [1.5, 0.86599999999999999, 0.0],
            [1.0, 1.732, 0.0],
            [0.0, 1.732, 0.0],
            [-0.5, 0.86599999999999999, 0.0],
        ],
        1: [
            [0.0, 0.0, 0.0],
            [-0.5, 0.86599999999999999, 0.0],
            [-1.5, 0.86599999999999999, 0.0],
            [-2.0, 0.0, 0.0],
            [-1.5, -0.86599999999999999, 0.0],
            [-0.5, -0.86599999999999999, 0.0],
        ],
        2: [
            [0.0, 0.0, 0.0],
            [-0.5, -0.86599999999999999, 0.0],
            [0.0, -1.732, 0.0],
            [1.0, -1.732, 0.0],
            [1.5, -0.86599999999999999, 0.0],
            [1.0, 0.0, 0.0],
        ],
        3: [
            [0.33333333333333331, 0.0, 0.0],
            [0.0, 0.0, 0.0],
            [-0.16666666666666666, 0.28866666666666663, 0.0],
            [0.0, 0.57733333333333325, 0.0],
            [0.33333333333333331, 0.57733333333333325, 0.0],
            [0.5, 0.28866666666666663, 0.0],
        ],
        4: [
            [-0.16666666666666666, 0.28866666666666663, 0.0],
            [0.0, 0.0, 0.0],
            [-0.16666666666666666, -0.28866666666666663, 0.0],
            [-0.5, -0.28866666666666663, 0.0],
            [-0.66666666666666663, 0.0, 0.0],
            [-0.5, 0.28866666666666663, 0.0],
        ],
        5: [
            [-0.16666666666666666, -0.28866666666666663, 0.0],
            [0.0, 0.0, 0.0],
            [0.33333333333333331, 0.0, 0.0],
            [0.5, -0.28866666666666663, 0.0],
            [0.33333333333333331, -0.57733333333333325, 0.0],
            [0.0, -0.57733333333333325, 0.0],
        ],
        6: [
            [1.0, 0.0, 0.0],
            [0.0, 0.0, 0.0],
            [0.0, 0.0, 0.0],
            [0.33333333333333331, 0.0, 0.0],
        ],
        7: [
            [1.5, 0.86599999999999999, 0.0],
            [1.0, 0.0, 0.0],
            [0.33333333333333331, 0.0, 0.0],
            [0.5, 0.28866666666666663, 0.0],
        ],
        8: [
            [1.0, 1.732, 0.0],
            [1.5, 0.86599999999999999, 0.0],
            [0.5, 0.28866666666666663, 0.0],
            [0.33333333333333331, 0.57733333333333325, 0.0],
        ],
        9: [
            [0.0, 1.732, 0.0],
            [1.0, 1.732, 0.0],
            [0.33333333333333331, 0.57733333333333325, 0.0],
            [0.0, 0.57733333333333325, 0.0],
        ],
        10: [
            [-0.5, 0.86599999999999999, 0.0],
            [0.0, 1.732, 0.0],
            [0.0, 0.57733333333333325, 0.0],
            [-0.16666666666666666, 0.28866666666666663, 0.0],
        ],
        11: [
            [0.0, 0.0, 0.0],
            [-0.5, 0.86599999999999999, 0.0],
            [-0.16666666666666666, 0.28866666666666663, 0.0],
            [0.0, 0.0, 0.0],
        ],
        12: [
            [-0.5, 0.86599999999999999, 0.0],
            [0.0, 0.0, 0.0],
            [0.0, 0.0, 0.0],
            [-0.16666666666666666, 0.28866666666666663, 0.0],
        ],
        13: [
            [-1.5, 0.86599999999999999, 0.0],
            [-0.5, 0.86599999999999999, 0.0],
            [-0.16666666666666666, 0.28866666666666663, 0.0],
            [-0.5, 0.28866666666666663, 0.0],
        ],
        14: [
            [-2.0, 0.0, 0.0],
            [-1.5, 0.86599999999999999, 0.0],
            [-0.5, 0.28866666666666663, 0.0],
            [-0.66666666666666663, 0.0, 0.0],
        ],
        15: [
            [-1.5, -0.86599999999999999, 0.0],
            [-2.0, 0.0, 0.0],
            [-0.66666666666666663, 0.0, 0.0],
            [-0.5, -0.28866666666666663, 0.0],
        ],
        16: [
            [-0.5, -0.86599999999999999, 0.0],
            [-1.5, -0.86599999999999999, 0.0],
            [-0.5, -0.28866666666666663, 0.0],
            [-0.16666666666666666, -0.28866666666666663, 0.0],
        ],
        17: [
            [0.0, 0.0, 0.0],
            [-0.5, -0.86599999999999999, 0.0],
            [-0.16666666666666666, -0.28866666666666663, 0.0],
            [0.0, 0.0, 0.0],
        ],
        18: [
            [-0.5, -0.86599999999999999, 0.0],
            [0.0, 0.0, 0.0],
            [0.0, 0.0, 0.0],
            [-0.16666666666666666, -0.28866666666666663, 0.0],
        ],
        19: [
            [0.0, -1.732, 0.0],
            [-0.5, -0.86599999999999999, 0.0],
            [-0.16666666666666666, -0.28866666666666663, 0.0],
            [0.0, -0.57733333333333325, 0.0],
        ],
        20: [
            [1.0, -1.732, 0.0],
            [0.0, -1.732, 0.0],
            [0.0, -0.57733333333333325, 0.0],
            [0.33333333333333331, -0.57733333333333325, 0.0],
        ],
        21: [
            [1.5, -0.86599999999999999, 0.0],
            [1.0, -1.732, 0.0],
            [0.33333333333333331, -0.57733333333333325, 0.0],
            [0.5, -0.28866666666666663, 0.0],
        ],
        22: [
            [1.0, 0.0, 0.0],
            [1.5, -0.86599999999999999, 0.0],
            [0.5, -0.28866666666666663, 0.0],
            [0.33333333333333331, 0.0, 0.0],
        ],
        23: [
            [0.0, 0.0, 0.0],
            [1.0, 0.0, 0.0],
            [0.33333333333333331, 0.0, 0.0],
            [0.0, 0.0, 0.0],
        ],
    }

    expected_res = pd.Series(dict_expected_res)

    ## test standard on a 3d-epithelium

    res = eptm.face_polygons(["x", "y", "z"])
    assert all([(expected_res[i] == res[i]).all()
                for i in range(res.shape[0])])
Exemplo n.º 5
0
def test_3faces():

    datasets, specs = three_faces_sheet()
    eptm = Epithelium("3faces_2D", datasets, specs)
    assert (eptm.Nc, eptm.Nv, eptm.Ne) == (3, 13, 18)
Exemplo n.º 6
0
def test_verts_in_face_connectivity():
    data, specs = three_faces_sheet()
    sheet = Sheet("test", data, specs)
    vfc = connectivity.verts_in_face_connectivity(sheet)
    assert vfc[0][vfc[0] == 2].shape == (3, )
Exemplo n.º 7
0
class TestsPlt:

    sheet = Sheet("test", *three_faces_sheet())
    draw_specs = config.draw.sheet_spec()

    def test_quick_edge_draw(self):

        fig, ax = quick_edge_draw(self.sheet)
        assert ax.lines[0].get_xydata().shape == (54, 2)

    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"]["visible"] = True
        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)

        self.draw_specs["edge"]["head_width"] = 1.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_sheet_view_color_string(self):
        self.draw_specs["edge"]["color"] = "k"
        self.draw_specs["face"]["color"] = "red"
        fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)
        assert ax.collections[1].get_edgecolors().shape == (1, 4)
        assert ax.collections[2].get_facecolors().shape == (1, 4)

    def test_sheet_view_color_partial_visibility(self):
        self.draw_specs["face"]["color"] = np.random.rand(3, 4)
        self.sheet.face_df["visible"] = False
        self.sheet.face_df.loc[0, "visible"] = True
        fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)
        assert ax.collections[2].get_facecolors().shape == (1, 4)

    def test_sheet_view_color_null_visibility(self):
        self.draw_specs["face"]["color"] = np.random.rand(3, 4)
        self.sheet.face_df["visible"] = False
        with pytest.warns(UserWarning):
            fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)
        assert ax.collections[2].get_facecolors().shape == (3, 4)

    def test_sheet_view_homogenous_color(self):
        with pytest.warns(UserWarning):
            self.draw_specs["face"]["color"] = np.ones(3)
            fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)

        with pytest.warns(UserWarning):
            self.draw_specs["edge"]["color"] = np.ones(self.sheet.Ne)
            fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)

        with pytest.warns(UserWarning):
            self.draw_specs["edge"]["color"] = np.ones(self.sheet.Nv)
            fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)

    def test_sheet_view_invalid_color_array(self):
        with pytest.raises(ValueError):
            self.draw_specs["face"]["color"] = np.arange(5)
            self.draw_specs["edge"]["color"] = np.arange(self.sheet.Nv)
            fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)

    def test_per_vertex_edge_colors(self):

        self.draw_specs["face"]["color"] = "red"
        self.sheet.face_df["visible"] = True
        self.draw_specs["edge"]["color"] = np.random.random(self.sheet.Nv)
        fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)

    def test_sheet_view_callable(self):
        with pytest.raises(ValueError):
            self.draw_specs["face"]["color"] = lambda sheet: np.ones(5)
            self.draw_specs["edge"]["color"] = lambda sheet: np.ones(5)
            fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)
Exemplo n.º 8
0
def test_triangular_mesh():
    datasets, specs = three_faces_sheet()
    eptm = Epithelium("3faces_2D", datasets, specs)
    vertices, faces = eptm.triangular_mesh(["x", "y", "z"], False)
    assert vertices.shape == (16, 3)
    assert faces.shape == (18, 3)
Exemplo n.º 9
0
def test_mono_update_perimeters():
    datasets_2d, _ = three_faces_sheet(zaxis=True)
    datasets = extrude(datasets_2d, method="translation")
    specs = config.geometry.bulk_spec()
    eptm = Epithelium("test_volume", datasets, specs, coords=["x", "y", "z"])
Exemplo n.º 10
0
def test_grow():
    sheet = Sheet("emin", *three_faces_sheet())
    sheet.face_df["prefered_vol"] = 1.0
    grow(sheet, 0, 1.2)
    assert sheet.face_df.loc[0, "prefered_vol"] == 1.2
Exemplo n.º 11
0
def test_get_next():
    sheet = Sheet("emin", *three_faces_sheet())
    next_ = utils.get_next(sheet)
    expected = np.array(
        [1, 2, 3, 4, 5, 0, 7, 8, 9, 10, 11, 6, 13, 14, 15, 16, 17, 12])
    np.testing.assert_array_equal(next_, expected)
Exemplo n.º 12
0
def test_set_value():
    sheet = Sheet("emin", *three_faces_sheet())
    sheet.face_df["prefered_vol"] = 1.0
    set_value(sheet, "face", 0, 12.0, "prefered_vol")
    assert sheet.face_df.loc[0, "prefered_vol"] == 12.0
    assert sheet.face_df.loc[1, "prefered_vol"] == 1.0
Exemplo n.º 13
0
def test_decrease():
    sheet = Sheet("emin", *three_faces_sheet())
    sheet.face_df["prefered_vol"] = 1.0
    decrease(sheet, "face", 0, 1.6, "prefered_vol")
    assert sheet.face_df.loc[0, "prefered_vol"] == 0.625
Exemplo n.º 14
0
from tyssue import Sheet
from tyssue.generation import three_faces_sheet
from collisions import self_intersections

sheet = Sheet("test", *three_faces_sheet())
assert len(self_intersections(sheet) == 0)
Exemplo n.º 15
0
def test_monolayer_with_lamina():

    sheet_dsets, _ = three_faces_sheet()
    dsets = extrude(sheet_dsets, method="translation")
    mono = MonolayerWithLamina("test", dsets, config.geometry.bulk_spec())
    assert mono.lamina_edges.shape == (3,)
Exemplo n.º 16
0
def test_bulk_update_vol():

    datasets_2d, _ = three_faces_sheet(zaxis=True)
    datasets = extrude(datasets_2d, method="translation")
    specs = config.geometry.bulk_spec()
    eptm = Epithelium("test_volume", datasets, specs, coords=["x", "y", "z"])

    BulkGeometry.update_all(eptm)

    expected_cell_df = pd.DataFrame.from_dict({
        "cell": [0, 1, 2],
        "x": [0.5, -1.0, 0.5],
        "y": [8.660000e-01, -6.167906e-18, -8.6600000e-01],
        "z": [-0.5, -0.5, -0.5],
        "is_alive": [True, True, True],
        "num_faces": [8, 8, 8],
        "vol": [2.598, 2.598, 2.598],
    }).set_index("cell")

    expected_face_centroids = pd.DataFrame.from_dict({
        "face":
        list(range(24)),
        "x": [
            0.5,
            -1.0,
            0.5,
            0.5,
            -1.0,
            0.5,
            0.5,
            1.25,
            1.25,
            0.5,
            -0.25,
            -0.25,
            -0.25,
            -1.0,
            -1.75,
            -1.75,
            -1.0,
            -0.25,
            -0.25,
            -0.25,
            0.5,
            1.25,
            1.25,
            0.5,
        ],
        "y": [
            0.86599999999999999,
            0.0,
            -0.86599999999999999,
            0.86599999999999999,
            0.0,
            -0.86599999999999999,
            0.0,
            0.433,
            1.2989999999999999,
            1.732,
            1.2989999999999999,
            0.433,
            0.433,
            0.86599999999999999,
            0.433,
            -0.433,
            -0.86599999999999999,
            -0.433,
            -0.433,
            -1.2989999999999999,
            -1.732,
            -1.2989999999999999,
            -0.433,
            0.0,
        ],
        "z": [
            0.0,
            0.0,
            0.0,
            -1.0,
            -1.0,
            -1.0,
            -0.5,
            -0.5,
            -0.5,
            -0.5,
            -0.5,
            -0.5,
            -0.5,
            -0.5,
            -0.5,
            -0.5,
            -0.5,
            -0.5,
            -0.5,
            -0.5,
            -0.5,
            -0.5,
            -0.5,
            -0.5,
        ],
    }).set_index("face")

    ## only update class methods in BulkGeometry : update_vol, update_centroids
    tolerance = 1e-16

    ## check volumes
    assert all((expected_cell_df["vol"] - eptm.cell_df["vol"])**2 < tolerance)

    ## check centroids
    assert all((expected_face_centroids -
                eptm.face_df.loc[:, ["x", "y", "z"]])**2 < tolerance)
Exemplo n.º 17
0
def test_idx_lookup():
    datasets, specs = three_faces_sheet()
    eptm = Epithelium("3faces_2D", datasets, specs)
    eptm.face_df["id"] = eptm.face_df.index.values
    assert eptm.idx_lookup(1, "face") == 1
Exemplo n.º 18
0
def test_cut_out():
    datasets_2d, _ = three_faces_sheet()
    datasets = extrude(datasets_2d, method="translation")

    eptm = Epithelium("3faces_3D", datasets)

    bounding_box_xy = np.array([[-1.0, 10.0], [-1.5, 1.5]])
    bounding_box_yx = np.array([[-1.5, 1.5], [-1.0, 10.0]])
    bounding_box_xyz = np.array([[-10.0, 10.0], [-1.5, 10.0], [-2.0, 1.0]])

    expected_index_xy = pd.Index(
        [
            2,
            3,
            4,
            7,
            8,
            9,
            10,
            13,
            14,
            15,
            20,
            21,
            22,
            25,
            26,
            27,
            28,
            31,
            32,
            33,
            44,
            46,
            47,
            48,
            49,
            50,
            51,
            52,
            53,
            54,
            64,
            66,
            67,
            68,
            69,
            70,
            71,
            72,
            73,
            74,
            75,
            76,
            77,
            78,
            88,
            90,
            91,
            92,
            93,
            94,
            95,
            96,
            97,
            98,
        ],
        name="edge",
        dtype="int64",
    )

    expected_index_xyz = pd.Index(
        [13, 14, 15, 31, 32, 33, 88, 90, 91, 92, 93, 94, 95, 96, 97, 98],
        name="edge",
        dtype="int64",
    )

    # test 2-coords, ordered
    res = eptm.cut_out(bbox=bounding_box_xy, coords=["x", "y"])
    assert len(res) == len(expected_index_xy)
    assert (res == expected_index_xy).all()

    # test 2-coords, inverse order
    res = eptm.cut_out(bbox=bounding_box_yx, coords=["y", "x"])
    assert len(res) == len(expected_index_xy)
    assert (res == expected_index_xy).all()

    # test 3-coords
    res = eptm.cut_out(bbox=bounding_box_xyz, coords=["x", "y", "z"])
    assert len(res) == len(expected_index_xyz)
    assert (res == expected_index_xyz).all()

    # test default coords argument
    res = eptm.cut_out(bbox=bounding_box_xy)
    assert len(res) == len(expected_index_xy)
    assert (res == expected_index_xy).all()
Exemplo n.º 19
0
def test_summation():
    datasets_2d, specs = three_faces_sheet(zaxis=True)
    datasets = extrude(datasets_2d)
    eptm = Epithelium("3faces_3D", datasets, specs)
    data = eptm.edge_df.index.values
    assert_array_equal(
        eptm.sum_cell(data).values.flatten(), np.array([1278, 1926, 2574]))

    sum_trgt = np.array([
        462,
        302,
        88,
        97,
        106,
        248,
        142,
        151,
        160,
        356,
        196,
        205,
        214,
        501,
        340,
        107,
        116,
        125,
        286,
        161,
        170,
        179,
        394,
        215,
        224,
        233,
    ])
    assert_array_equal(eptm.sum_trgt(data).values.flatten(), sum_trgt)

    sum_srce = np.array([
        441,
        300,
        87,
        96,
        105,
        246,
        141,
        150,
        159,
        354,
        195,
        204,
        213,
        522,
        342,
        108,
        117,
        126,
        288,
        162,
        171,
        180,
        396,
        216,
        225,
        234,
    ])
    assert_array_equal(eptm.sum_srce(data).values.flatten(), sum_srce)
    sum_face = np.array([
        15,
        51,
        87,
        123,
        159,
        195,
        150,
        166,
        182,
        198,
        214,
        230,
        246,
        262,
        278,
        294,
        310,
        326,
        342,
        358,
        374,
        390,
        406,
        422,
    ])
    assert_array_equal(eptm.sum_face(data).values.flatten(), sum_face)
Exemplo n.º 20
0
def test_extrude_invalid_method():
    datasets, specs = generation.three_faces_sheet()
    with raises(ValueError):
        datasets_3d = extrude(datasets, method="invalid_method")
Exemplo n.º 21
0
def test_remove():
    datasets, specs = three_faces_sheet()
    datasets = extrude(datasets, method="translation")

    eptm = Epithelium("3Faces_3D", datasets, specs)

    dict_after = {
        "srce": {
            0: 0,
            1: 2,
            2: 3,
            3: 4,
            4: 5,
            5: 6,
            6: 0,
            7: 6,
            8: 7,
            9: 8,
            10: 9,
            11: 1,
            12: 12,
            13: 13,
            14: 14,
            15: 15,
            16: 16,
            17: 10,
            18: 16,
            19: 17,
            20: 18,
            21: 19,
            22: 11,
            23: 10,
            24: 2,
            25: 0,
            26: 10,
            27: 12,
            28: 3,
            29: 2,
            30: 12,
            31: 13,
            32: 4,
            33: 3,
            34: 13,
            35: 14,
            36: 5,
            37: 4,
            38: 14,
            39: 15,
            40: 6,
            41: 5,
            42: 15,
            43: 16,
            44: 0,
            45: 6,
            46: 16,
            47: 10,
            48: 6,
            49: 0,
            50: 10,
            51: 16,
            52: 7,
            53: 6,
            54: 16,
            55: 17,
            56: 8,
            57: 7,
            58: 17,
            59: 18,
            60: 9,
            61: 8,
            62: 18,
            63: 19,
            64: 1,
            65: 9,
            66: 19,
            67: 11,
            68: 0,
            69: 1,
            70: 11,
            71: 10,
        },
        "trgt": {
            0: 2,
            1: 3,
            2: 4,
            3: 5,
            4: 6,
            5: 0,
            6: 6,
            7: 7,
            8: 8,
            9: 9,
            10: 1,
            11: 0,
            12: 10,
            13: 12,
            14: 13,
            15: 14,
            16: 15,
            17: 16,
            18: 10,
            19: 16,
            20: 17,
            21: 18,
            22: 19,
            23: 11,
            24: 0,
            25: 10,
            26: 12,
            27: 2,
            28: 2,
            29: 12,
            30: 13,
            31: 3,
            32: 3,
            33: 13,
            34: 14,
            35: 4,
            36: 4,
            37: 14,
            38: 15,
            39: 5,
            40: 5,
            41: 15,
            42: 16,
            43: 6,
            44: 6,
            45: 16,
            46: 10,
            47: 0,
            48: 0,
            49: 10,
            50: 16,
            51: 6,
            52: 6,
            53: 16,
            54: 17,
            55: 7,
            56: 7,
            57: 17,
            58: 18,
            59: 8,
            60: 8,
            61: 18,
            62: 19,
            63: 9,
            64: 9,
            65: 19,
            66: 11,
            67: 1,
            68: 1,
            69: 11,
            70: 10,
            71: 0,
        },
        "face": {
            0: 0,
            1: 0,
            2: 0,
            3: 0,
            4: 0,
            5: 0,
            6: 1,
            7: 1,
            8: 1,
            9: 1,
            10: 1,
            11: 1,
            12: 2,
            13: 2,
            14: 2,
            15: 2,
            16: 2,
            17: 2,
            18: 3,
            19: 3,
            20: 3,
            21: 3,
            22: 3,
            23: 3,
            24: 4,
            25: 4,
            26: 4,
            27: 4,
            28: 5,
            29: 5,
            30: 5,
            31: 5,
            32: 6,
            33: 6,
            34: 6,
            35: 6,
            36: 7,
            37: 7,
            38: 7,
            39: 7,
            40: 8,
            41: 8,
            42: 8,
            43: 8,
            44: 9,
            45: 9,
            46: 9,
            47: 9,
            48: 10,
            49: 10,
            50: 10,
            51: 10,
            52: 11,
            53: 11,
            54: 11,
            55: 11,
            56: 12,
            57: 12,
            58: 12,
            59: 12,
            60: 13,
            61: 13,
            62: 13,
            63: 13,
            64: 14,
            65: 14,
            66: 14,
            67: 14,
            68: 15,
            69: 15,
            70: 15,
            71: 15,
        },
    }

    sft_after = pd.DataFrame.from_dict(dict_after)

    eptm.remove([0])

    assert eptm.edge_df[["srce", "trgt",
                         "face"]].equals(sft_after[["srce", "trgt", "face"]])
Exemplo n.º 22
0
def test_retrieve_coords():
    sheet = Sheet("3", *three_faces_sheet())
    history = History(sheet)
    history.record()
    assert history.retrieve(0).coords == sheet.coords
Exemplo n.º 23
0
def test_3faces():

    datasets, _ = generation.three_faces_sheet()
    assert datasets["edge"].shape[0] == 18
    assert datasets["face"].shape[0] == 3
    assert datasets["vert"].shape[0] == 13
Exemplo n.º 24
0
def test_polygons():
    datasets_2d, specs = three_faces_sheet(zaxis=True)
    datasets = extrude(datasets_2d, scale=1 / 3.0)
    eptm = Epithelium("3faces_3D", datasets, specs)
    RNRGeometry.update_all(eptm)
    with raises(ValueError):
        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)
Exemplo n.º 25
0
def test_srce_trgt_connectivity():
    data, specs = three_faces_sheet()
    sheet = Sheet("test", data, specs)
    stc = connectivity.srce_trgt_connectivity(sheet)
    expected = np.array([3, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1])
    np.testing.assert_array_equal(stc.sum(axis=0), expected)
Exemplo n.º 26
0
def test_remove():
    datasets, specs = three_faces_sheet()
    datasets = extrude(datasets, method="translation")

    eptm = Epithelium("3Faces_3D", datasets, specs)

    dict_before = {
        "srce": {
            0: 0,
            1: 1,
            2: 2,
            3: 3,
            4: 4,
            5: 5,
            6: 0,
            7: 5,
            8: 6,
            9: 7,
            10: 8,
            11: 9,
            12: 0,
            13: 9,
            14: 10,
            15: 11,
            16: 12,
            17: 1,
            18: 14,
            19: 15,
            20: 16,
            21: 17,
            22: 18,
            23: 13,
            24: 18,
            25: 19,
            26: 20,
            27: 21,
            28: 22,
            29: 13,
            30: 22,
            31: 23,
            32: 24,
            33: 25,
            34: 14,
            35: 13,
            36: 1,
            37: 0,
            38: 13,
            39: 14,
            40: 2,
            41: 1,
            42: 14,
            43: 15,
            44: 3,
            45: 2,
            46: 15,
            47: 16,
            48: 4,
            49: 3,
            50: 16,
            51: 17,
            52: 5,
            53: 4,
            54: 17,
            55: 18,
            56: 0,
            57: 5,
            58: 18,
            59: 13,
            60: 5,
            61: 0,
            62: 13,
            63: 18,
            64: 6,
            65: 5,
            66: 18,
            67: 19,
            68: 7,
            69: 6,
            70: 19,
            71: 20,
            72: 8,
            73: 7,
            74: 20,
            75: 21,
            76: 9,
            77: 8,
            78: 21,
            79: 22,
            80: 0,
            81: 9,
            82: 22,
            83: 13,
            84: 9,
            85: 0,
            86: 13,
            87: 22,
            88: 10,
            89: 9,
            90: 22,
            91: 23,
            92: 11,
            93: 10,
            94: 23,
            95: 24,
            96: 12,
            97: 11,
            98: 24,
            99: 25,
            100: 1,
            101: 12,
            102: 25,
            103: 14,
            104: 0,
            105: 1,
            106: 14,
            107: 13,
        },
        "trgt": {
            0: 1,
            1: 2,
            2: 3,
            3: 4,
            4: 5,
            5: 0,
            6: 5,
            7: 6,
            8: 7,
            9: 8,
            10: 9,
            11: 0,
            12: 9,
            13: 10,
            14: 11,
            15: 12,
            16: 1,
            17: 0,
            18: 13,
            19: 14,
            20: 15,
            21: 16,
            22: 17,
            23: 18,
            24: 13,
            25: 18,
            26: 19,
            27: 20,
            28: 21,
            29: 22,
            30: 13,
            31: 22,
            32: 23,
            33: 24,
            34: 25,
            35: 14,
            36: 0,
            37: 13,
            38: 14,
            39: 1,
            40: 1,
            41: 14,
            42: 15,
            43: 2,
            44: 2,
            45: 15,
            46: 16,
            47: 3,
            48: 3,
            49: 16,
            50: 17,
            51: 4,
            52: 4,
            53: 17,
            54: 18,
            55: 5,
            56: 5,
            57: 18,
            58: 13,
            59: 0,
            60: 0,
            61: 13,
            62: 18,
            63: 5,
            64: 5,
            65: 18,
            66: 19,
            67: 6,
            68: 6,
            69: 19,
            70: 20,
            71: 7,
            72: 7,
            73: 20,
            74: 21,
            75: 8,
            76: 8,
            77: 21,
            78: 22,
            79: 9,
            80: 9,
            81: 22,
            82: 13,
            83: 0,
            84: 0,
            85: 13,
            86: 22,
            87: 9,
            88: 9,
            89: 22,
            90: 23,
            91: 10,
            92: 10,
            93: 23,
            94: 24,
            95: 11,
            96: 11,
            97: 24,
            98: 25,
            99: 12,
            100: 12,
            101: 25,
            102: 14,
            103: 1,
            104: 1,
            105: 14,
            106: 13,
            107: 0,
        },
        "face": {
            0: 0,
            1: 0,
            2: 0,
            3: 0,
            4: 0,
            5: 0,
            6: 1,
            7: 1,
            8: 1,
            9: 1,
            10: 1,
            11: 1,
            12: 2,
            13: 2,
            14: 2,
            15: 2,
            16: 2,
            17: 2,
            18: 3,
            19: 3,
            20: 3,
            21: 3,
            22: 3,
            23: 3,
            24: 4,
            25: 4,
            26: 4,
            27: 4,
            28: 4,
            29: 4,
            30: 5,
            31: 5,
            32: 5,
            33: 5,
            34: 5,
            35: 5,
            36: 6,
            37: 6,
            38: 6,
            39: 6,
            40: 7,
            41: 7,
            42: 7,
            43: 7,
            44: 8,
            45: 8,
            46: 8,
            47: 8,
            48: 9,
            49: 9,
            50: 9,
            51: 9,
            52: 10,
            53: 10,
            54: 10,
            55: 10,
            56: 11,
            57: 11,
            58: 11,
            59: 11,
            60: 12,
            61: 12,
            62: 12,
            63: 12,
            64: 13,
            65: 13,
            66: 13,
            67: 13,
            68: 14,
            69: 14,
            70: 14,
            71: 14,
            72: 15,
            73: 15,
            74: 15,
            75: 15,
            76: 16,
            77: 16,
            78: 16,
            79: 16,
            80: 17,
            81: 17,
            82: 17,
            83: 17,
            84: 18,
            85: 18,
            86: 18,
            87: 18,
            88: 19,
            89: 19,
            90: 19,
            91: 19,
            92: 20,
            93: 20,
            94: 20,
            95: 20,
            96: 21,
            97: 21,
            98: 21,
            99: 21,
            100: 22,
            101: 22,
            102: 22,
            103: 22,
            104: 23,
            105: 23,
            106: 23,
            107: 23,
        },
    }

    dict_after = {
        "srce": {
            0: 0,
            1: 2,
            2: 3,
            3: 4,
            4: 5,
            5: 6,
            6: 0,
            7: 6,
            8: 7,
            9: 8,
            10: 9,
            11: 1,
            12: 12,
            13: 13,
            14: 14,
            15: 15,
            16: 16,
            17: 10,
            18: 16,
            19: 17,
            20: 18,
            21: 19,
            22: 11,
            23: 10,
            24: 2,
            25: 0,
            26: 10,
            27: 12,
            28: 3,
            29: 2,
            30: 12,
            31: 13,
            32: 4,
            33: 3,
            34: 13,
            35: 14,
            36: 5,
            37: 4,
            38: 14,
            39: 15,
            40: 6,
            41: 5,
            42: 15,
            43: 16,
            44: 0,
            45: 6,
            46: 16,
            47: 10,
            48: 6,
            49: 0,
            50: 10,
            51: 16,
            52: 7,
            53: 6,
            54: 16,
            55: 17,
            56: 8,
            57: 7,
            58: 17,
            59: 18,
            60: 9,
            61: 8,
            62: 18,
            63: 19,
            64: 1,
            65: 9,
            66: 19,
            67: 11,
            68: 0,
            69: 1,
            70: 11,
            71: 10,
        },
        "trgt": {
            0: 2,
            1: 3,
            2: 4,
            3: 5,
            4: 6,
            5: 0,
            6: 6,
            7: 7,
            8: 8,
            9: 9,
            10: 1,
            11: 0,
            12: 10,
            13: 12,
            14: 13,
            15: 14,
            16: 15,
            17: 16,
            18: 10,
            19: 16,
            20: 17,
            21: 18,
            22: 19,
            23: 11,
            24: 0,
            25: 10,
            26: 12,
            27: 2,
            28: 2,
            29: 12,
            30: 13,
            31: 3,
            32: 3,
            33: 13,
            34: 14,
            35: 4,
            36: 4,
            37: 14,
            38: 15,
            39: 5,
            40: 5,
            41: 15,
            42: 16,
            43: 6,
            44: 6,
            45: 16,
            46: 10,
            47: 0,
            48: 0,
            49: 10,
            50: 16,
            51: 6,
            52: 6,
            53: 16,
            54: 17,
            55: 7,
            56: 7,
            57: 17,
            58: 18,
            59: 8,
            60: 8,
            61: 18,
            62: 19,
            63: 9,
            64: 9,
            65: 19,
            66: 11,
            67: 1,
            68: 1,
            69: 11,
            70: 10,
            71: 0,
        },
        "face": {
            0: 0,
            1: 0,
            2: 0,
            3: 0,
            4: 0,
            5: 0,
            6: 1,
            7: 1,
            8: 1,
            9: 1,
            10: 1,
            11: 1,
            12: 2,
            13: 2,
            14: 2,
            15: 2,
            16: 2,
            17: 2,
            18: 3,
            19: 3,
            20: 3,
            21: 3,
            22: 3,
            23: 3,
            24: 4,
            25: 4,
            26: 4,
            27: 4,
            28: 5,
            29: 5,
            30: 5,
            31: 5,
            32: 6,
            33: 6,
            34: 6,
            35: 6,
            36: 7,
            37: 7,
            38: 7,
            39: 7,
            40: 8,
            41: 8,
            42: 8,
            43: 8,
            44: 9,
            45: 9,
            46: 9,
            47: 9,
            48: 10,
            49: 10,
            50: 10,
            51: 10,
            52: 11,
            53: 11,
            54: 11,
            55: 11,
            56: 12,
            57: 12,
            58: 12,
            59: 12,
            60: 13,
            61: 13,
            62: 13,
            63: 13,
            64: 14,
            65: 14,
            66: 14,
            67: 14,
            68: 15,
            69: 15,
            70: 15,
            71: 15,
        },
    }

    sft_before = pd.DataFrame.from_dict(dict_before)
    sft_after = pd.DataFrame.from_dict(dict_after)

    eptm.remove([0])

    assert eptm.edge_df[["srce", "trgt",
                         "face"]].equals(sft_after[["srce", "trgt", "face"]])
Exemplo n.º 27
0
def test_ef_connect():
    data, specs = three_faces_sheet()
    sheet = Sheet("test", data, specs)
    ef_connect = connectivity.edge_in_face_connectivity(sheet)
    idx = sheet.edge_df.query(f"face == {sheet.Nf-1}").index
    assert ef_connect[idx[0], idx[1]]
Exemplo n.º 28
0
def test_wrong_datasets_keys():
    datasets, specs = three_faces_sheet()
    datasets["edges"] = datasets["edge"]
    del datasets["edge"]
    with raises(ValueError):
        eptm = Epithelium("3faces_2D", datasets, specs)
Exemplo n.º 29
0
def test_warning():

    sheet = Sheet("3", *three_faces_sheet())
    with pytest.warns(UserWarning):
        history = History(sheet, extra_cols={"vert": ["invalid_column"]})
Exemplo n.º 30
0
def test_shrink():
    sheet = Sheet("emin", *three_faces_sheet())
    sheet.face_df["prefered_vol"] = 1.0
    shrink(sheet, 0, 0.6)
    assert sheet.face_df.loc[0, "prefered_vol"] == 0.625