Skip to content

Commit

Permalink
corrects bug in voronoi_3d with bellonging with 2 cells, fixes DamCB#137
Browse files Browse the repository at this point in the history
  • Loading branch information
glyg committed May 12, 2021
1 parent 69423ac commit 4737485
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
10 changes: 8 additions & 2 deletions tests/generation/test_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ def test_from_3d_voronoi():
datasets = from_3d_voronoi(Voronoi(grid))
assert datasets["vert"].shape[0] == 139
assert datasets["edge"].shape[0] == 1272
assert datasets["face"].shape[0] == 141
assert datasets["face"].shape[0] == 282
assert datasets["cell"].shape[0] == 70
bulk = Epithelium("bulk", datasets, config.geometry.bulk_spec())
bulk.reset_index()
bulk.reset_topo()
BulkGeometry.update_all(bulk)
bulk.sanitize()

# GH 137
assert (
bulk.edge_df.groupby("face").apply(lambda df: df["cell"].unique().size).max()
== 1
)
assert bulk.validate()


Expand Down Expand Up @@ -88,7 +94,7 @@ def test_hexagrid3d_noise():
datasets = from_3d_voronoi(Voronoi(grid))
assert datasets["vert"].shape[0] == 318
assert datasets["edge"].shape[0] == 3300
assert datasets["face"].shape[0] == 335
assert datasets["face"].shape[0] == 670
assert datasets["cell"].shape[0] == 72


Expand Down
3 changes: 1 addition & 2 deletions tests/topology/test_bulk_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def test_bulk_division():
bulk.sanitize()
bulk.reset_topo()
bulk.reset_index()
with pytest.raises(ValueError):
cell_division(bulk, 4, BulkGeometry)
cell_division(bulk, 4, BulkGeometry)

dsets = hdf5.load_datasets(Path(stores_dir) / "with_4sided_cell.hf5")
bulk = Monolayer("4", dsets)
Expand Down
30 changes: 21 additions & 9 deletions tyssue/generation/from_voronoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def from_3d_voronoi(voro):
""" Creates 3D (bulk geometry) datasets from a Voronoï tessalation
"""Creates 3D (bulk geometry) datasets from a Voronoï tessalation
Parameters
----------
Expand All @@ -23,10 +23,26 @@ def from_3d_voronoi(voro):
datasets: dict
datasets suitable for :class:`Epithelium` implementation
Notes
-----
It is important to reset the index of the created epithelium after creation
Example
-------
cells = hexa_grid3d(3, 3, 3)
datasets = from_3d_voronoi(Voronoi(cells))
bulk = Epithelium('bulk', datasets)
bulk.reset_topo()
bulk.reset_index(order=True)
bulk.sanitize()
"""

specs3d = bulk_spec()

el_idx = []
n_single_faces = len(voro.ridge_vertices)

for f_idx, (rv, rp) in enumerate(zip(voro.ridge_vertices, voro.ridge_points)):

Expand All @@ -46,10 +62,10 @@ def from_3d_voronoi(voro):
dotp = np.dot(ctof, normal)
if np.sign(dotp) > 0:
el_idx.append([rv0, rv1, f_idx, rp[0]])
el_idx.append([rv1, rv0, f_idx, rp[1]])
el_idx.append([rv1, rv0, f_idx + n_single_faces, rp[1]])
else:
el_idx.append([rv1, rv0, f_idx, rp[0]])
el_idx.append([rv0, rv1, f_idx, rp[1]])
el_idx.append([rv0, rv1, f_idx + n_single_faces, rp[1]])

el_idx = np.array(el_idx)

Expand All @@ -72,20 +88,16 @@ def from_3d_voronoi(voro):
included_cells = edge_df["cell"].unique()
cell_df = cell_df.loc[included_cells].copy()

nfaces = len(voro.ridge_vertices)
face_idx = pd.Index(np.arange(nfaces), name="face")
face_df = make_df(face_idx, specs3d["face"])
included_faces = edge_df["face"].unique()
face_df = face_df.loc[included_faces].copy()

face_df = make_df(included_faces, specs3d["face"])
edge_df.sort_values(by="cell", inplace=True)

datasets = {"vert": vert_df, "edge": edge_df, "face": face_df, "cell": cell_df}
return datasets


def from_2d_voronoi(voro, specs=None):
""" Creates 2D (sheet geometry) datasets from a Voronoï tessalation
"""Creates 2D (sheet geometry) datasets from a Voronoï tessalation
Parameters
----------
Expand Down

0 comments on commit 4737485

Please sign in to comment.