def test_face_polygons_exception(): datasets = {} tri_verts = [[0, 0], [1, 0], [-0.5, 3**0.5 / 2], [-0.5, -3**0.5 / 2]] tri_edges_valid = [[0, 1, 0], [1, 2, 0], [2, 0, 0], [0, 3, 1], [3, 1, 1], [1, 0, 1], [0, 2, 2], [2, 3, 2], [3, 0, 2]] tri_edges_invalid = [[0, 1, 0], [1, 2, 0], [2, 0, 0], [0, 3, 1], [3, 1, 1], [1, 0, 1], [0, 2, 2], [2, 3, 2], [3, 1, 2]] # changed 0 to 1 to create an invalid face datasets['edge'] = pd.DataFrame(data=np.array(tri_edges_valid), columns=['srce', 'trgt', 'face']) datasets['edge'].index.name = 'edge' datasets['face'] = pd.DataFrame(data=np.zeros((3, 2)), columns=['x', 'y']) datasets['face'].index.name = 'face' datasets['vert'] = pd.DataFrame(data=np.array(tri_verts), columns=['x', 'y']) datasets['vert'].index.name = 'vert' specs = config.geometry.planar_spec() eptm = Epithelium('valid', datasets, specs, coords=['x', 'y']) PlanarGeometry.update_all(eptm) eptm.face_polygons(['x', 'y'])
def test_sort_eastwest(): datasets = {} tri_verts = [[0, 0], [1, 0], [-0.5, 3**0.5 / 2], [-0.5, -(3**0.5) / 2]] tri_edges = [ [0, 1, 0], [1, 2, 0], [2, 0, 0], [0, 3, 1], [3, 1, 1], [1, 0, 1], [0, 2, 2], [2, 3, 2], [3, 0, 2], ] datasets["edge"] = pd.DataFrame(data=np.array(tri_edges), columns=["srce", "trgt", "face"]) datasets["edge"].index.name = "edge" datasets["face"] = pd.DataFrame(data=np.zeros((3, 2)), columns=["x", "y"]) datasets["face"].index.name = "face" datasets["vert"] = pd.DataFrame(data=np.array(tri_verts), columns=["x", "y"]) datasets["vert"].index.name = "vert" specs = config.geometry.planar_spec() eptm = Sheet("extra", datasets, specs, coords=["x", "y"]) PlanarGeometry.update_all(eptm) eptm.edge_df["opposite"] = get_opposite(eptm.edge_df) eptm.sort_edges_eastwest() assert_array_equal(np.asarray(eptm.free_edges), [0, 1, 2]) assert_array_equal(np.asarray(eptm.east_edges), [3, 4, 5]) assert_array_equal(np.asarray(eptm.west_edges), [6, 7, 8])
def test_model(): h5store = os.path.join(stores_dir, "small_hexagonal.hf5") datasets = load_datasets(h5store, data_names=["face", "vert", "edge"]) specs = config.geometry.cylindrical_sheet() sheet = Sheet("emin", datasets, specs) model_tester(sheet, model) model_tester(sheet, PlanarModel) flat = Sheet.planar_sheet_2d("flat", 5, 5, 1, 1) flat.sanitize() PlanarGeometry.update_all(flat) model_tester(flat, PlanarModel)
def test_extra_indices(): datasets = {} tri_verts = [[0, 0], [1, 0], [-0.5, 3**0.5 / 2], [-0.5, -(3**0.5) / 2]] tri_edges = [ [0, 1, 0], [1, 2, 0], [2, 0, 0], [0, 3, 1], [3, 1, 1], [1, 0, 1], [0, 2, 2], [2, 3, 2], [3, 0, 2], ] datasets["edge"] = pd.DataFrame(data=np.array(tri_edges), columns=["srce", "trgt", "face"]) datasets["edge"].index.name = "edge" datasets["face"] = pd.DataFrame(data=np.zeros((3, 2)), columns=["x", "y"]) datasets["face"].index.name = "face" datasets["vert"] = pd.DataFrame(data=np.array(tri_verts), columns=["x", "y"]) datasets["vert"].index.name = "vert" specs = config.geometry.planar_spec() eptm = Sheet("extra", datasets, specs, coords=["x", "y"]) PlanarGeometry.update_all(eptm) eptm.edge_df["opposite"] = get_opposite(eptm.edge_df) eptm.get_extra_indices() assert (2 * eptm.Ni + eptm.No) == eptm.Ne assert eptm.west_edges.size == eptm.Ni assert eptm.Nd == 2 * eptm.Ni for edge in eptm.free_edges: opps = eptm.edge_df[eptm.edge_df["srce"] == eptm.edge_df.loc[ edge, "trgt"]]["trgt"] assert eptm.edge_df.loc[edge, "srce"] not in opps for edge in eptm.east_edges: srce, trgt = eptm.edge_df.loc[edge, ["srce", "trgt"]] opp = eptm.edge_df[(eptm.edge_df["srce"] == trgt) & (eptm.edge_df["trgt"] == srce)].index assert opp[0] in eptm.west_edges for edge in eptm.west_edges: srce, trgt = eptm.edge_df.loc[edge, ["srce", "trgt"]] opp = eptm.edge_df[(eptm.edge_df["srce"] == trgt) & (eptm.edge_df["trgt"] == srce)].index assert opp[0] in eptm.east_edges
def test_face_projected_pos(): datasets = {} tri_verts = [[0, 0], [1, 0], [-0.5, 0.75], [-0.5, -0.75]] tri_edges = [ [0, 1, 0], [1, 2, 0], [2, 0, 0], [0, 3, 1], [3, 1, 1], [1, 0, 1], [0, 2, 2], [2, 3, 2], [3, 0, 2], ] datasets["edge"] = pd.DataFrame( data=np.array(tri_edges), columns=["srce", "trgt", "face"] ) datasets["edge"].index.name = "edge" datasets["face"] = pd.DataFrame(data=np.zeros((3, 2)), columns=["x", "y"]) datasets["face"].index.name = "face" datasets["vert"] = pd.DataFrame(data=np.array(tri_verts), columns=["x", "y"]) datasets["vert"].index.name = "vert" specs = config.geometry.planar_spec() eptm = Epithelium("extra", datasets, specs, coords=["x", "y"]) PlanarGeometry.update_all(eptm) res_rot_pos_pi2 = PlanarGeometry.face_projected_pos(eptm, 0, pi / 2.0) res_rot_pos_face1_2pi = PlanarGeometry.face_projected_pos(eptm, 1, 2.0 * pi) expected_rot_pos_pi2 = pd.DataFrame.from_dict( { "vert": [0, 1, 2, 3], "x": [0.25, 0.25, -0.5, 1.0], "y": [-0.166667, 0.8333333, -0.666667, -0.666667], } ).set_index("vert") expected_rot_pos_face1_2pi = pd.DataFrame.from_dict( { "vert": [0, 1, 2, 3], "x": [-0.166667, 0.833333, -0.666667, -0.666667], "y": [0.25, 0.25, 1.00, -0.5], } ).set_index("vert") tolerance = 1e-16 assert all((expected_rot_pos_pi2 - res_rot_pos_pi2) ** 2 < tolerance) assert all((expected_rot_pos_face1_2pi - res_rot_pos_face1_2pi) ** 2 < tolerance)
def test_get_force_inference(): # INIT TISSUE sheet = Sheet.planar_sheet_2d("jam", 10, 10, 1, 1, noise=0) PlanarGeometry.update_all(sheet) model = model_factory( [ effectors.FaceAreaElasticity, ], effectors.FaceAreaElasticity, ) sheet.remove(sheet.cut_out([[0, 10], [0, 10]])) sheet.sanitize(trim_borders=True) PlanarGeometry.scale(sheet, sheet.face_df.area.mean()**-0.5, ["x", "y"]) PlanarGeometry.center(sheet) PlanarGeometry.update_all(sheet) sheet.reset_index() sheet.reset_topo() sheet.face_df["area_elasticity"] = 1 sheet.face_df["prefered_area"] = 1 solver = QSSolver(with_t1=False, with_t3=False, with_collisions=False) solver.find_energy_min(sheet, PlanarGeometry, model, options={"gtol": 1e-8}) sheet.vert_df.y *= 0.5 solver.find_energy_min(sheet, PlanarGeometry, model, options={"gtol": 1e-8}) sheet.get_force_inference(column="tension", free_border_edges=True) sheet = sheet.extract_bounding_box(x_boundary=[-2, 2], y_boundary=[-1, 1]) sheet.edge_df["angle"] = ( np.arctan2(sheet.edge_df["dx"], sheet.edge_df["dy"]) * 180 / np.pi) sheet.edge_df["angle"] = sheet.edge_df["angle"].apply(lambda x: 180 + x if x < 0 else x) sheet.edge_df["angle"] = sheet.edge_df["angle"].apply(lambda x: 180 - x if x > 90 else x) for _, edge in sheet.edge_df[sheet.edge_df.angle > 45].iterrows(): assert edge.tension > 1.5 for _, edge in sheet.edge_df[sheet.edge_df.angle < 45].iterrows(): assert edge.tension < 1.5
def test_face_projected_pos(): datasets = {} tri_verts = [[0, 0], [1, 0], [-0.5, 0.75], [-0.5, -0.75]] tri_edges = [[0, 1, 0], [1, 2, 0], [2, 0, 0], [0, 3, 1], [3, 1, 1], [1, 0, 1], [0, 2, 2], [2, 3, 2], [3, 0, 2]] datasets['edge'] = pd.DataFrame(data=np.array(tri_edges), columns=['srce', 'trgt', 'face']) datasets['edge'].index.name = 'edge' datasets['face'] = pd.DataFrame(data=np.zeros((3, 2)), columns=['x', 'y']) datasets['face'].index.name = 'face' datasets['vert'] = pd.DataFrame(data=np.array(tri_verts), columns=['x', 'y']) datasets['vert'].index.name = 'vert' specs = config.geometry.planar_spec() eptm = Epithelium('extra', datasets, specs, coords=['x', 'y']) PlanarGeometry.update_all(eptm) res_rot_pos_pi2 = PlanarGeometry.face_projected_pos(eptm, 0, pi/2.) res_rot_pos_face1_2pi = PlanarGeometry.face_projected_pos(eptm, 1, 2.*pi) expected_rot_pos_pi2 = pd.DataFrame.from_dict({'vert':[0,1,2,3],\ 'x':[0.25, 0.25, -0.5, 1.0],\ 'y':[-0.166667, 0.8333333, -0.666667,\ -0.666667]}).set_index('vert') expected_rot_pos_face1_2pi = pd.DataFrame.from_dict({'vert':[0,1,2,3],\ 'x':[-0.166667, 0.833333, -0.666667, -0.666667],\ 'y':[0.25,0.25,1.00,-0.5]}).set_index('vert') tolerance = 1e-16 assert all( (expected_rot_pos_pi2 - res_rot_pos_pi2)**2 < tolerance ) assert all( (expected_rot_pos_face1_2pi - res_rot_pos_face1_2pi)**2 < tolerance )
def test_face_polygons_exception(): datasets = {} tri_verts = [[0, 0], [1, 0], [-0.5, 3**0.5 / 2], [-0.5, -(3**0.5) / 2]] tri_edges_valid = [ [0, 1, 0], [1, 2, 0], [2, 0, 0], [0, 3, 1], [3, 1, 1], [1, 0, 1], [0, 2, 2], [2, 3, 2], [3, 0, 2], ] tri_edges_invalid = [ [0, 1, 0], [1, 2, 0], [2, 0, 0], [0, 3, 1], [3, 1, 1], [1, 0, 1], [0, 2, 2], [2, 3, 2], [3, 1, 2], ] # changed 0 to 1 to create an invalid face datasets["edge"] = pd.DataFrame(data=np.array(tri_edges_valid), columns=["srce", "trgt", "face"]) datasets["edge"].index.name = "edge" datasets["face"] = pd.DataFrame(data=np.zeros((3, 2)), columns=["x", "y"]) datasets["face"].index.name = "face" datasets["vert"] = pd.DataFrame(data=np.array(tri_verts), columns=["x", "y"]) datasets["vert"].index.name = "vert" specs = config.geometry.planar_spec() eptm = Epithelium("valid", datasets, specs, coords=["x", "y"]) PlanarGeometry.update_all(eptm) eptm.reset_index(order=True) eptm.face_polygons(["x", "y"])
def test_extra_indices(): datasets = {} tri_verts = [[0, 0], [1, 0], [-0.5, 3**0.5 / 2], [-0.5, -3**0.5 / 2]] tri_edges = [[0, 1, 0], [1, 2, 0], [2, 0, 0], [0, 3, 1], [3, 1, 1], [1, 0, 1], [0, 2, 2], [2, 3, 2], [3, 0, 2]] datasets['edge'] = pd.DataFrame(data=np.array(tri_edges), columns=['srce', 'trgt', 'face']) datasets['edge'].index.name = 'edge' datasets['face'] = pd.DataFrame(data=np.zeros((3, 2)), columns=['x', 'y']) datasets['face'].index.name = 'face' datasets['vert'] = pd.DataFrame(data=np.array(tri_verts), columns=['x', 'y']) datasets['vert'].index.name = 'vert' specs = config.geometry.planar_spec() eptm = Epithelium('extra', datasets, specs, coords=['x', 'y']) PlanarGeometry.update_all(eptm) eptm.edge_df['opposite'] = get_opposite(eptm.edge_df) eptm.get_extra_indices() assert (2 * eptm.Ni + eptm.No) == eptm.Ne assert eptm.west_edges.size == eptm.Ni assert eptm.Nd == 2 * eptm.Ni for edge in eptm.free_edges: opps = eptm.edge_df[eptm.edge_df['srce'] == eptm.edge_df.loc[ edge, 'trgt']]['trgt'] assert eptm.edge_df.loc[edge, 'srce'] not in opps for edge in eptm.east_edges: srce, trgt = eptm.edge_df.loc[edge, ['srce', 'trgt']] opp = eptm.edge_df[(eptm.edge_df['srce'] == trgt) & (eptm.edge_df['trgt'] == srce)].index assert opp[0] in eptm.west_edges for edge in eptm.west_edges: srce, trgt = eptm.edge_df.loc[edge, ['srce', 'trgt']] opp = eptm.edge_df[(eptm.edge_df['srce'] == trgt) & (eptm.edge_df['trgt'] == srce)].index assert opp[0] in eptm.east_edges
def test_sort_eastwest(): datasets = {} tri_verts = [[0, 0], [1, 0], [-0.5, 3**0.5 / 2], [-0.5, -3**0.5 / 2]] tri_edges = [[0, 1, 0], [1, 2, 0], [2, 0, 0], [0, 3, 1], [3, 1, 1], [1, 0, 1], [0, 2, 2], [2, 3, 2], [3, 0, 2]] datasets['edge'] = pd.DataFrame(data=np.array(tri_edges), columns=['srce', 'trgt', 'face']) datasets['edge'].index.name = 'edge' datasets['face'] = pd.DataFrame(data=np.zeros((3, 2)), columns=['x', 'y']) datasets['face'].index.name = 'face' datasets['vert'] = pd.DataFrame(data=np.array(tri_verts), columns=['x', 'y']) datasets['vert'].index.name = 'vert' specs = config.geometry.planar_spec() eptm = Epithelium('extra', datasets, specs, coords=['x', 'y']) PlanarGeometry.update_all(eptm) eptm.edge_df['opposite'] = get_opposite(eptm.edge_df) eptm.sort_edges_eastwest() assert_array_equal(np.asarray(eptm.free_edges), [0, 1, 2]) assert_array_equal(np.asarray(eptm.east_edges), [3, 4, 5]) assert_array_equal(np.asarray(eptm.west_edges), [6, 7, 8])
def test_invalid_valid_sanitize(): # get_invalid and get_valid datasets = {} tri_verts = [[0, 0], [1, 0], [-0.5, 3**0.5 / 2], [-0.5, -(3**0.5) / 2]] tri_edges_valid = [ [0, 1, 0], [1, 2, 0], [2, 0, 0], [0, 3, 1], [3, 1, 1], [1, 0, 1], [0, 2, 2], [2, 3, 2], [3, 0, 2], ] tri_edges_invalid = [ [0, 1, 0], [1, 2, 0], [2, 0, 0], [0, 3, 1], [3, 1, 1], [1, 0, 1], [0, 2, 2], [2, 3, 2], [3, 1, 2], ] # changed 0 to 1 to create an invalid face # Epithelium whose faces are all valid ## datasets["edge"] = pd.DataFrame(data=np.array(tri_edges_valid), columns=["srce", "trgt", "face"]) datasets["edge"].index.name = "edge" datasets["face"] = pd.DataFrame(data=np.zeros((3, 2)), columns=["x", "y"]) datasets["face"].index.name = "face" datasets["vert"] = pd.DataFrame(data=np.array(tri_verts), columns=["x", "y"]) datasets["vert"].index.name = "vert" specs = config.geometry.planar_spec() eptm = Epithelium("valid", datasets, specs, coords=["x", "y"]) PlanarGeometry.update_all(eptm) # Epithelium with invalid faces (last 3) datasets_invalid = datasets.copy() datasets_invalid["edge"] = pd.DataFrame(data=np.array(tri_edges_invalid), columns=["srce", "trgt", "face"]) datasets_invalid["edge"].index.name = "edge" eptm_invalid = Epithelium("invalid", datasets_invalid, specs, coords=["x", "y"]) PlanarGeometry.update_all(eptm_invalid) eptm.get_valid() eptm_invalid.get_valid() res_invalid_expect_all_false = eptm.get_invalid() res_invalid_expect_some_true = eptm_invalid.get_invalid() assert eptm.edge_df["is_valid"].all() assert not eptm_invalid.edge_df["is_valid"][6:].all() assert not res_invalid_expect_all_false.all() assert res_invalid_expect_some_true[6:].all() # testing sanitize # edges 6 to 9 should be removed. edge_df_before = eptm.edge_df.copy() edge_df_invalid_before = eptm_invalid.edge_df.copy() eptm.sanitize() eptm_invalid.sanitize() assert edge_df_before.equals(eptm.edge_df) assert edge_df_invalid_before[:6].equals(eptm_invalid.edge_df)
def test_invalid_valid_sanitize(): # get_invalid and get_valid datasets = {} tri_verts = [[0, 0], [1, 0], [-0.5, 3**0.5 / 2], [-0.5, -3**0.5 / 2]] tri_edges_valid = [[0, 1, 0], [1, 2, 0], [2, 0, 0], [0, 3, 1], [3, 1, 1], [1, 0, 1], [0, 2, 2], [2, 3, 2], [3, 0, 2]] tri_edges_invalid = [[0, 1, 0], [1, 2, 0], [2, 0, 0], [0, 3, 1], [3, 1, 1], [1, 0, 1], [0, 2, 2], [2, 3, 2], [3, 1, 2]] # changed 0 to 1 to create an invalid face ## Epithelium whose faces are all valid ## datasets['edge'] = pd.DataFrame(data=np.array(tri_edges_valid), columns=['srce', 'trgt', 'face']) datasets['edge'].index.name = 'edge' datasets['face'] = pd.DataFrame(data=np.zeros((3, 2)), columns=['x', 'y']) datasets['face'].index.name = 'face' datasets['vert'] = pd.DataFrame(data=np.array(tri_verts), columns=['x', 'y']) datasets['vert'].index.name = 'vert' specs = config.geometry.planar_spec() eptm = Epithelium('valid', datasets, specs, coords=['x', 'y']) PlanarGeometry.update_all(eptm) ## Epithelium with invalid faces (last 3) datasets_invalid = datasets.copy() datasets_invalid['edge'] = pd.DataFrame(data=np.array(tri_edges_invalid), columns=['srce', 'trgt', 'face']) datasets_invalid['edge'].index.name = 'edge' eptm_invalid = Epithelium('invalid', datasets_invalid, specs, coords=['x', 'y']) PlanarGeometry.update_all(eptm_invalid) eptm.get_valid() eptm_invalid.get_valid() res_invalid_expect_all_false = eptm.get_invalid() res_invalid_expect_some_true = eptm_invalid.get_invalid() assert eptm.edge_df['is_valid'].all() assert (not eptm_invalid.edge_df['is_valid'][6:].all()) assert (not res_invalid_expect_all_false.all()) assert res_invalid_expect_some_true[6:].all() ### testing sanitize ### edges 6 to 9 should be removed. edge_df_before = eptm.edge_df.copy() edge_df_invalid_before = eptm_invalid.edge_df.copy() eptm.sanitize() eptm_invalid.sanitize() assert edge_df_before.equals(eptm.edge_df) assert edge_df_invalid_before[:6].equals(eptm_invalid.edge_df)