Skip to content
Snippets Groups Projects
Commit 4018c834 authored by Florian Zill's avatar Florian Zill
Browse files

timevalues as np array

parent 353f7740
No related branches found
No related tags found
1 merge request!117Probe Functionality
...@@ -215,23 +215,23 @@ class MeshSeries: ...@@ -215,23 +215,23 @@ class MeshSeries:
return range(len(self.timevalues)) return range(len(self.timevalues))
@property @property
def timevalues(self) -> list[float]: def timevalues(self) -> np.ndarray:
"""Return the timevalues of the timeseries data.""" """Return the timevalues of the timeseries data."""
if self._data_type == "vtu": if self._data_type == "vtu":
return [0] return np.zeros(1)
if self._data_type == "pvd": if self._data_type == "pvd":
return self._pvd_reader.time_values return np.asarray(self._pvd_reader.time_values)
# elif self._data_type == "xdmf": # elif self._data_type == "xdmf":
time_values = [] time_values = []
for collection_i in self._xdmf_reader.collection: for collection_i in self._xdmf_reader.collection:
for element in collection_i: for element in collection_i:
if element.tag == "Time": if element.tag == "Time":
time_values += [float(element.attrib["Value"])] time_values += [float(element.attrib["Value"])]
return time_values return np.asarray(time_values)
def closest_timestep(self, timevalue: float) -> int: def closest_timestep(self, timevalue: float) -> int:
"""Return the corresponding timestep from a timevalue.""" """Return the corresponding timestep from a timevalue."""
return int(np.argmin(np.abs(np.array(self.timevalues) - timevalue))) return int(np.argmin(np.abs(self.timevalues - timevalue)))
def closest_timevalue(self, timevalue: float) -> float: def closest_timevalue(self, timevalue: float) -> float:
"""Return the closest timevalue to a timevalue.""" """Return the closest timevalue to a timevalue."""
...@@ -245,7 +245,7 @@ class MeshSeries: ...@@ -245,7 +245,7 @@ class MeshSeries:
self, timevalue: float, lazy_eval: bool = True self, timevalue: float, lazy_eval: bool = True
) -> pv.UnstructuredGrid: ) -> pv.UnstructuredGrid:
"""Return the temporal interpolated mesh for a given timevalue.""" """Return the temporal interpolated mesh for a given timevalue."""
t_vals = np.array(self.timevalues) t_vals = self.timevalues
ts1 = int(t_vals.searchsorted(timevalue, "right") - 1) ts1 = int(t_vals.searchsorted(timevalue, "right") - 1)
ts2 = min(ts1 + 1, len(t_vals) - 1) ts2 = min(ts1 + 1, len(t_vals) - 1)
if np.isclose(timevalue, t_vals[ts1]): if np.isclose(timevalue, t_vals[ts1]):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment