Skip to content

Commit

Permalink
Merge branch 'master' of github.com:DamCB/tyssue
Browse files Browse the repository at this point in the history
  • Loading branch information
glyg committed Jan 29, 2018
2 parents 950e3c9 + 045ad43 commit 8b89430
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 3 deletions.
22 changes: 22 additions & 0 deletions tests/core/test_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,25 @@ def test_anchors():

res_srce_trgt_anchors = sheet.edge_df.loc[18:, ['srce', 'trgt']]
assert res_srce_trgt_anchors.equals(expected_res)


def test_sheet_extract():
datasets, specs = generation.three_faces_sheet()
sheet = Sheet('test_sheet_extract_coordinate', datasets, specs)
subsheet = sheet.sheet_extract('is_alive')
assert subsheet.face_df['is_alive'].all() == True


def test_sheet_extract_coordinate():
grid = hexa_grid2d(6, 4, 3, 3)
datasets = from_2d_voronoi(Voronoi(grid))
sheet = Sheet('test_extract_bounding_box', datasets)
subsheet = sheet.extract_bounding_box(
[sheet.face_df['x'].min(), sheet.face_df['x'].max()/2],
[sheet.face_df['y'].min(), sheet.face_df['y'].max()/2])
assert subsheet.face_df['x'].max() <= sheet.face_df['x'].max()/2
assert subsheet.face_df['x'].min() >= sheet.face_df['x'].min()
assert subsheet.face_df['y'].max() <= sheet.face_df['y'].max()/2
assert subsheet.face_df['y'].min() >= sheet.face_df['y'].min()
assert subsheet.face_df['z'].max() <= sheet.face_df['z'].max()
assert subsheet.face_df['z'].min() >= sheet.face_df['z'].min()
2 changes: 1 addition & 1 deletion tyssue/behaviors/sheet_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def ab_pull(self, face, *args):
verts = self.sheet.edge_df[self.sheet.edge_df['face'] ==
self.idx_lookup(face)]['srce'].unique()
factor = args[0]
new_tension = self.sheet.specs['edge']['line_tension'] * factor
new_tension = self.sheet.specs['edge']['radial_tension'] * factor
self.sheet.vert_df.loc[verts, 'radial_tension'] += new_tension

def divide(self, face, *args):
Expand Down
83 changes: 81 additions & 2 deletions tyssue/core/sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def get_neighborhood(self, face, order):
# Start with the face so that it's not gathered later
neighbors = pd.DataFrame.from_dict({'face': [face],
'order': [0]})
for k in range(order+1):
for neigh in neighbors[neighbors['order'] == k-1]['face']:
for k in range(order + 1):
for neigh in neighbors[neighbors['order'] == k - 1]['face']:
new_neighs = self.get_neighbors(neigh)
new_neighs = set(new_neighs).difference(neighbors['face'])

Expand All @@ -91,6 +91,85 @@ def get_neighborhood(self, face, order):

return neighbors.reset_index(drop=True).loc[1:]

def sheet_extract(self, face_mask, coords=['x', 'y', 'z']):
""" Extract a new sheet from the embryo sheet
that correspond to a key word that define a face.
Parameters
----------
sheet: a :class:Sheet object
face_mask : column name in face composed by boolean value
coords
Returns
-------
sheet_fold_patch_extract :
subsheet corresponding to the fold patch area.
"""
x, y, z = coords
datasets = {}

datasets['face'] = self.face_df[
self.face_df[face_mask] == True].copy()
datasets['edge'] = self.edge_df[self.edge_df['face'].isin(
datasets['face'].index)].copy()
datasets['vert'] = self.vert_df.loc[self.edge_df['srce'].unique()]

subsheet = Sheet('subsheet', datasets, self.specs)
subsheet.reset_index()
subsheet.reset_topo()
return (subsheet)

def extract_bounding_box(self, x_boundary=None, y_boundary=None,
z_boundary=None, coords=['x', 'y', 'z']):
""" Extract a new sheet from the embryo sheet
that correspond to boundary coordinate
define by the user.
Parameters
----------
sheet: a :class:Sheet object
xmin, xmax : boundary
ymin, ymax : boundary
zmin, zmax : boundary
coords
Returns
-------
sheet_extract :
subsheet
"""
x, y, z = coords
datasets = {}
datasets['face'] = self.face_df.copy()

if x_boundary is not None:
xmin, xmax = x_boundary
datasets['face'] = datasets['face'][
(datasets['face']['x'] > xmin) & (datasets['face']['x'] < xmax)
].copy()

if y_boundary is not None:
ymin, ymax = y_boundary
datasets['face'] = datasets['face'][
(datasets['face']['y'] > ymin) & (datasets['face']['y'] < ymax)
].copy()

if z_boundary is not None:
zmin, zmax = z_boundary
datasets['face'] = datasets['face'][
(datasets['face']['z'] > zmin) & (datasets['face']['z'] < zmax)
].copy()

datasets['edge'] = self.edge_df[self.edge_df['face'].isin(
datasets['face'].index)].copy()

datasets['vert'] = self.vert_df.loc[self.edge_df['srce'].unique()]

subsheet = Sheet('subsheet', datasets, self.specs)
subsheet.reset_index()
subsheet.reset_topo()
return (subsheet)

@classmethod
def planar_sheet_2d(cls, identifier,
nx, ny, distx, disty):
Expand Down

0 comments on commit 8b89430

Please sign in to comment.