Skip to content

Commit

Permalink
feat(extended_classes): add ability to reverse mapped signal data
Browse files Browse the repository at this point in the history
  • Loading branch information
uliw committed Dec 20, 2024
1 parent 86149c9 commit c7e7786
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions src/esbmtk/extended_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,8 @@ def __init__(self, **kwargs) -> None:
"duration": ["None", (str, Q_)],
"species": ["None", (SpeciesProperties)],
"delta": [0, (int, float)],
"stype": [
"addition",
(str),
],
"stype": ["addition", (str)],
"reverse": [False, (bool)],
"shape": ["None", (str)],
"filename": ["None", (str)],
"mass": ["None", (str, Q_)],
Expand Down Expand Up @@ -659,8 +657,12 @@ def __map_signal__(self) -> Flux:
signal_index
] # TODO: for future thinking how to calculate isotope fluxes

mapped_signal_data.m = mapped_m
mapped_signal_data.l = mapped_l
if self.reverse:
mapped_signal_data.m = np.flip(mapped_m)
mapped_signal_data.l = np.flip(mapped_l)
else:
mapped_signal_data.m = mapped_m
mapped_signal_data.l = mapped_l

return mapped_signal_data

Expand Down Expand Up @@ -768,23 +770,12 @@ def __int_ext_data__(self) -> None:

self.s_time = self.ed.x
self.s_data = self.ed.y * self.scale

self.st: float = self.s_time[0] # signal start time
self.et: float = self.s_time[-1] # signal end time
self.duration = int(round((self.et - self.st)))
if len(self.ed.x) > self.mo.number_of_datapoints:
message = (
f"\n{self.filename} contains {len(self.ed.x)} datapoints\n",
f"but model resolves only {self.mo.number_of_datapoints} datapoints\n",
f"adjust the number_of_datapoints option in the model object\n",
)
raise ValueError(message)
else:
signal_duration = self.et - self.st
model_time_step = self.mo.dt
# Calculate how many data points are needed to interpolate signal duration with model time step
num_steps = int(round(signal_duration / model_time_step))

signal_duration = self.et - self.st
model_time_step = self.mo.dt
# Calculate how many data points are needed to interpolate signal duration with model time step
num_steps = int(signal_duration / model_time_step)
# setup the points at which to interpolate
xi = np.linspace(self.st, self.et, num_steps + 1)

Expand Down

0 comments on commit c7e7786

Please sign in to comment.