Skip to content
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

edited history.py for a typo #291

Closed
wants to merge 3 commits into from
Closed
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
27 changes: 16 additions & 11 deletions src/tyssue/core/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ def __init__(

self.datasets = {}
self.columns = {}
self.dicts = {}
vcols = sheet.coords + extra_cols["vert"]
vcols = list(set(vcols))
self.vcols = _filter_columns(vcols, sheet.vert_df.columns, "vertex")
_vert_h = sheet.vert_df[self.vcols].reset_index(drop=False)
if "time" not in self.vcols:
_vert_h["time"] = 0
self.datasets["vert"] = _vert_h
self.dicts["vert"] = {}
self.columns["vert"] = self.vcols

fcols = extra_cols["face"]
Expand All @@ -96,6 +98,7 @@ def __init__(
if "time" not in self.fcols:
_face_h["time"] = 0
self.datasets["face"] = _face_h
self.dicts["face"] = {}
self.columns["face"] = self.fcols

if sheet.cell_df is not None:
Expand All @@ -105,6 +108,7 @@ def __init__(
if "time" not in self.ccols:
_cell_h["time"] = 0
self.datasets["cell"] = _cell_h
self.dicts["cell"] = {}
self.columns["cell"] = self.ccols
extra_cols["edge"].append("cell")

Expand All @@ -115,6 +119,7 @@ def __init__(
if "time" not in self.ecols:
_edge_h["time"] = 0
self.datasets["edge"] = _edge_h
self.dicts["edge"] = {}
self.columns["edge"] = self.ecols

def __len__(self):
Expand Down Expand Up @@ -156,7 +161,8 @@ def cell_h(self):

def record(self, time_stamp=None):
"""Appends a copy of the sheet datasets to the history instance.

Appends to the corresponding dict. Use update_datasets() method
to create the self.datasets dataframes as in the previous implementation
Parameters
----------
time_stamp : float, save specific timestamp
Expand All @@ -171,25 +177,24 @@ def record(self, time_stamp=None):
self.index % (int(self.save_every / self.dt)) == 0
):
for element in self.datasets:
hist = self.datasets[element]
cols = self.columns[element]
df = self.sheet.datasets[element][cols].reset_index(drop=False)
if "time" not in cols:
times = pd.Series(np.ones((df.shape[0],)) * self.time, name="time")
df = pd.concat([df, times], ignore_index=False, axis=1, sort=False)
else:
df["time"] = self.time

if self.time in hist["time"]:
if f"{self.time}" in self.dicts[element].keys():
# erase previously recorded time point
hist = hist[hist["time"] != self.time]
self.dicts[element].pop(f"{self.time}")

hist = pd.concat([hist, df], ignore_index=True, axis=0, sort=False)

self.datasets[element] = hist
self.dicts[element].update({f"{self.time}": df})

self.index += 1

def update_datasets(self):
"""Concatenate all datasets in self.datasets into self.datasets as pd.DataFrame objects
"""
for element in self.sheet.datasets:
self.datasets[element] = pd.concat(self.dicts[element].values(), ignore_index=True)

def retrieve(self, time):
"""Return datasets at time `time`.

Expand Down
6 changes: 6 additions & 0 deletions src/tyssue/solvers/viscous.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def set_pos(self, pos):
def record(self, t):
self.history.record(time_stamp=t)

def update_datasets(self):
self.history.update_datasets()

def solve(self, tf, dt, on_topo_change=None, topo_change_args=()):
"""Solves the system of differential equations from the current time
to tf with steps of dt with a forward Euler method.
Expand Down Expand Up @@ -132,6 +135,9 @@ def solve(self, tf, dt, on_topo_change=None, topo_change_args=()):
self.eptm.topo_changed = False
self.record(t)

if t == tf:
self.update_datasets()

def ode_func(self, t, pos):
"""Computes the models' gradient.

Expand Down
Loading