Skip to content

Improve plot_force and fix spec_updater #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions tests/draw/test_plt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from tyssue import Sheet, config
from tyssue.draw.plt_draw import quick_edge_draw, sheet_view
from tyssue.draw.plt_draw import _face_color_from_sequence
from tyssue.draw.plt_draw import create_gif
from tyssue.draw.plt_draw import create_gif, plot_forces


class TestsPlt:
Expand Down Expand Up @@ -51,7 +51,7 @@ def test_sheet_view(self):
0.0, 1.0, num=self.sheet.edge_df.shape[0]
)[::-1]

self.draw_specs["edge"]["visible"] = True
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
Expand Down Expand Up @@ -155,3 +155,19 @@ def test_create_gif():

os.remove("frames.gif")
os.remove("interval.gif")


def test_plot_forces():
geom = SheetGeometry
model = PlanarModel
sheet = Sheet("3", *three_faces_sheet())
sheet.update_specs(model.specs)
geom.update_all(sheet)
fig, ax = plot_forces(sheet,
geom,
model,
list('xy'),
0.05,
**{'extract': {'x_boundary': (-10, 10)}})

assert ax.lines[0].get_xydata().shape == (54, 2)
5 changes: 5 additions & 0 deletions tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def test_spec_updater():
print(specs)
assert specs["face"]["geometry"] == new_specs["face"]["geometry"]

new_specs = {"extract":{"z_boundary":(-10,10)}}
utils.spec_updater(specs, new_specs)
assert "extract" in specs
assert specs["extract"]['z_boundary'] == new_specs["extract"]['z_boundary']


def test_set_data_columns():
dsets, _ = three_faces_sheet()
Expand Down
8 changes: 5 additions & 3 deletions tyssue/draw/plt_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,17 @@ def plot_forces(
else:
grad_i = model.compute_gradient(sheet, components=False) * scaling
grad_i = grad_i.loc[sheet.vert_df["is_active"].astype(bool)]
arrows = pd.DataFrame(columns=coords + gcoords, index=sheet.vert_df.index)
arrows[coords] = sheet.vert_df[coords]
arrows[gcoords] = -grad_i[gcoords] # F = -grad E
sheet.vert_df[gcoords]=-grad_i[gcoords] # F = -grad E

if 'extract' in draw_specs:
sheet = sheet.extract_bounding_box(**draw_specs['extract'])

if ax is None:
fig, ax = quick_edge_draw(sheet, coords)
else:
fig = ax.get_figure()

arrows = sheet.vert_df[coords+gcoords]
for _, arrow in arrows.iterrows():
ax.arrow(*arrow, **draw_specs["grad"])
return fig, ax
Expand Down
9 changes: 6 additions & 3 deletions tyssue/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ def spec_updater(specs, new):
specs: specification that will be modified
new: dictionary of new specification
"""
for key, spec in specs.items():
if new.get(key) is not None:
spec.update(new[key])
for key in new.keys():
if specs.get(key) is not None:
specs[key].update(new[key])
else:
specs[key] = new[key]



def set_data_columns(datasets, specs, reset=False):
Expand Down