ogstools.meshlib.mesh_series module#
- class ogstools.meshlib.mesh_series.MeshSeries[source]#
Bases:
object
A wrapper around pyvista and meshio for reading of pvd and xdmf timeseries.
Initialize a MeshSeries object
- param filepath:
Path to the PVD or XDMF file.
- returns:
A MeshSeries object
- __init__(filepath)[source]#
Initialize a MeshSeries object
- param filepath:
Path to the PVD or XDMF file.
- returns:
A MeshSeries object
- copy(deep=True)[source]#
Create a copy of MeshSeries object. Deep copy is the default.
- Parameters:
deep (bool) – switch to choose between deep (default) and shallow (self.copy(deep=False)) copy.
- Returns:
Copy of self.
- Return type:
- __getitem__(index: int) Mesh [source]#
- __getitem__(index: slice | Sequence) MeshSeries
- aggregate_over_time(variable, func)[source]#
Aggregate data over all timesteps using a specified function.
- closest_timestep(timevalue)[source]#
Return the corresponding timestep from a timevalue.
- Return type:
int
- closest_timevalue(timevalue)[source]#
Return the closest timevalue to a timevalue.
- Return type:
float
- rawdata_file()[source]#
Checks, if working with the raw data is possible. For example, OGS Simulation results with XDMF support efficient raw data access via h5py
- Returns:
The location of the file containing the raw data. If it does not support efficient read (e.g., no efficient slicing), it returns None.
- Return type:
Path | None
- read_interp(timevalue, lazy_eval=True)[source]#
Return the temporal interpolated mesh for a given timevalue.
- Return type:
- property timevalues: ndarray#
Return the timevalues.
- property timesteps: list#
Return the OGS simulation timesteps of the timeseries data. Not to be confused with timevalues which returns a list of times usually given in time units.
- values(variable)[source]#
Get the data in the MeshSeries for all timesteps.
Adheres to time slicing via __get_item__ and an applied pyvista filter via transform if the applied filter produced ‘vtkOriginalPointIds’ or ‘vtkOriginalCellIds’ (e.g. clip(…, crinkle=True), extract_cells(…), threshold(…).)
- Parameters:
variable (str | Variable) – Variable to read/process from the MeshSeries.
- Returns:
A numpy array of shape (n_timesteps, n_points/c_cells). If given an argument of type Variable is given, its transform function is applied on the data.
- Return type:
ndarray
- time_of_min(variable)[source]#
Returns a Mesh with the time of the variable minimum as data.
- Return type:
- time_of_max(variable)[source]#
Returns a Mesh with the time of the variable maximum as data.
- Return type:
- aggregate_over_domain(variable, func)[source]#
Aggregate data over domain per timestep using a specified function.
- Parameters:
variable (Variable | str) – The mesh variable to be aggregated.
func (Callable) – The aggregation function to apply. E.g. np.min, np.max, np.mean, np.median, np.sum, np.std, np.var
- Returns:
A numpy array with aggregated data.
- Return type:
ndarray
- plot_domain_aggregate(variable, func, ax=None, **kwargs)[source]#
Plot the transient aggregated data over the domain per timestep.
- Parameters:
variable (Variable | str) – The mesh variable to be aggregated.
func (Callable) – The aggregation function to apply. E.g. np.min, np.max, np.mean, np.median, np.sum, np.std, np.var
ax (Axes | None) – matplotlib axis to use for plotting
kwargs (Any) – Keyword args passed to matplotlib’s plot function.
- Returns:
A matplotlib Figure or None if plotting on existing axis.
- Return type:
Figure | None
- probe(points, data_name, interp_method='linear')[source]#
Probe the MeshSeries at observation points.
- Parameters:
points (ndarray) – The observation points to sample at.
data_name (str) – Name of the data to sample.
interp_method (Literal['nearest', 'linear']) – Interpolation method, defaults to linear
- Returns:
numpy array of interpolated data at observation points.
- Return type:
ndarray
- plot_probe(points, variable, variable_abscissa=None, labels=None, interp_method='linear', colors=None, linestyles=None, ax=None, fill_between=False, **kwargs)[source]#
Plot the transient variable on the observation points in the MeshSeries.
- param points:
The points to sample at.
- param variable:
The variable to be sampled.
- param labels:
The labels for each observation point.
- param interp_method:
Choose the interpolation method, defaults to linear for xdmf MeshSeries and probefilter for pvd MeshSeries.
- param interp_backend:
Interpolation backend for PVD MeshSeries.
- param kwargs:
Keyword arguments passed to matplotlib’s plot function.
- returns:
A matplotlib Figure
- Return type:
Figure | None
- animate(variable, timevalues=None, plot_func=lambda *_: ..., **kwargs)[source]#
Create an animation for a variable with given timevalues.
- Parameters:
variable (Variable) – the field to be visualized on all timevalues
timevalues (Sequence | None) – the timevalues to animate
plot_func (Callable[[Axes, float], None]) – A function which expects to read a matplotlib Axes and the time value of the current frame. Useful to customize the plot in the animation.
- Keyword Arguments:
- Return type:
FuncAnimation
- plot_time_slice(variable, points, y_axis='auto', interpolate=True, time_logscale=False, fig=None, ax=None, cbar=True, **kwargs)[source]#
- Parameters:
variable (Variable | str) – The variable to be visualized.
points (ndarray) – The points along which the data is sampled over time.
y_axis (Literal['x', 'y', 'z', 'dist', 'auto']) – The component of the sampling points which labels the y-axis. By default, if only one coordinate of the points is changing, this axis is taken, otherwise the distance along the line is taken.
interpolate (bool) – Smoothen the result be interpolation.
time_logscale (bool) – Should log-scaling be applied to the time-axis?
fig (Figure | None) – matplotlib figure to use for plotting.
ax (Axes | None) – matplotlib axis to use for plotting.
cb_loc – Colorbar location. If None, omit colorbar.
- Keyword Arguments:
cb_labelsize: colorbar labelsize
cb_loc: colorbar location (‘left’ or ‘right’)
cb_pad: colorbar padding
cmap: colormap
vmin: minimum value for colorbar
vmax: maximum value for colorbar
num_levels: number of levels for colorbar
figsize: figure size
dpi: resolution
- Return type:
Figure
- property mesh_func: Callable[[Mesh], Mesh]#
Returns stored transformation function or identity if not given.
- transform(mesh_func=lambda mesh: ...)[source]#
Apply a transformation function to the underlying mesh.
- scale(spatial=1.0, time=1.0)[source]#
Scale the spatial coordinates and timevalues.
Useful to convert to other units, e.g. “m” to “km” or “s” to “a”. If given as tuple of strings, the latter units will also be set in ot.plot.setup.spatial_unt and ot.plot.setup.time_unit for plotting.
- Parameters:
spatial (float | tuple[str, str]) – Float factor or a tuple of str (from_unit, to_unit).
time (float | tuple[str, str]) – Float factor or a tuple of str (from_unit, to_unit).
- Return type:
- extract(index, preference='points')[source]#
Extract a subset of the domain by point or cell indices.
- Parameters:
index (slice | int | ndarray | list) – Indices of points or cells to extract.
preference (Literal['points', 'cells']) – Selected entities.
- Returns:
A MeshSeries with the selected domain subset.
- Return type: