Version:

salvus.toolbox.helpers.wavefield_output

salvus.toolbox.helpers.wavefield_output salvus toolbox helpers wavefield_output
Functions for manipulating SalvusCompute's wavefield output.

Functions

wavefield_output_enclosing_elements()

Get the elements and coefficients for evaluation at arbitrary points.
Given a WavefieldOutput object, usually constructed directly from a SalvusCompute output file, this function wraps the calls required to both a) find the elements enclosing each point in an arbitrary list of points, and b) compute interpolation coefficients required for evaluation at said points.
SIGNATURE
def wavefield_output_enclosing_elements(
    wo: WavefieldOutput,
    points: tuple[npt.NDArray] | npt.NDArray | typing.Sequence[npt.ArrayLike],
) -> tuple[np.ndarray, np.ndarray]: ...
ARGUMENTS
Required
wo
Type:WavefieldOutput
Description:
The wavefield output object.
Required
points
Type:tuple[npt.NDArray] | npt.NDArray | typing.Sequence[npt.ArrayLike]
Description:
Either a list of numpy arrays, indicating a structured grid, or one array of shape (n_pnt, n_dim), indicating an unstructured collection of points.
RETURNS
Return type: tuple[np.ndarray, np.ndarray]
A tuple of (element indices, interpolation coefficients) for each point.

wavefield_output_to_xarray()

Evaluate wavefield output at a set of user-defined points.
This function allows for the evaluation of a wavefield output file as generated by Salvus compute onto an arbitrary series of points. Both structured and unstructured point specifications are supported; please see the argument documentation below for more information.
SIGNATURE
def wavefield_output_to_xarray(
    wo: WavefieldOutput,
    points: tuple[npt.NDArray] | npt.NDArray | typing.Sequence[npt.ArrayLike],
    enclosing_elements: tuple[np.ndarray, np.ndarray] | tuple[()] = (),
    mode: str = "batch",
    verbose: bool = True,
) -> xr.DataArray: ...
ARGUMENTS
Required
wo
Type:WavefieldOutput
Description:
The wavefield output object; generally initialized directly from a SalvusCompute HDF5 volumetric output file.
Required
points
Type:tuple[npt.NDArray] | npt.NDArray | typing.Sequence[npt.ArrayLike]
Description:
A list of spatial points to interpolate onto. If a list of arrays is passed, it will be assumed that these arrays describe a structured grid in len(points) dimensions. If a single numpy array is passed, it will be assumed that these points represent an unstructured collection of points.
Optional
enclosing_elements
Type:tuple[np.ndarray, np.ndarray] | tuple[()]
Default value:()
Description:
A tuple of the enclosing element indices and interpolation coefficients can be passed in order to skip the potentially expensive enclosing element search if such values already exist. If an empty tuple is passed, the requisite quantities will be computed within this function.
Optional
mode
Type:str
Default value:'batch'
Description:
Either "sequential" or "batch". If "sequential", perform a tensor contraction only along the time axis, and operate element by element. If "batch", perform a tensor contraction along all axes to perform the interpolation. Batch is generally an optimal approach when the number of points is approximately equal or less to the number of elements; otherwise it may result in unacceptable memory usage. Defaults to "sequential".
Optional
verbose
Type:bool
Default value:True
Description:
Whether to print a progress bar for the enclosing element search and interpolation step.
RETURNS
Return type: xr.DataArray
An xarray DataArray containing dimensions (t [time], c [component], x, y, [z]) if structured input is passed, or (t [time], c [component], point) if unstructured input was passed. Points that were not found within any output element are flagged as NANs.

xarray_to_vtk_image_data()

Write an xarray DataArray to a series of VTK image data files.
The resulting files can be opened as a sequence in Paraview to efficiently render time-dependent structured data. render time-dependent structured data. The suffix for VTK image data files is '.vti'
This function requires the VTK Python bindings to be installed (vtk.org).
SIGNATURE
def xarray_to_vtk_image_data(
    filename_prefix: pathlib.Path | str,
    da: xr.DataArray,
    filename_indexing: tuple[int, str] | None = None,
) -> None: ...
ARGUMENTS
Required
filename_prefix
Type:pathlib.Path | str
Description:
A full path, including a filename prefix, describing where the VTK files should be written.
Required
da
Type:xr.DataArray
Description:
The DataArray to write. Must have dimensions ("x", "y", and "t") (2-D) or ("x", "y", "z", "t") (3-D).
Optional
filename_indexing
Type:tuple[int, str] | None
Default value:None
Description:
A tuple of (offset, format) to use when computing the filenames. If not provided, filenames will start at 0 and sequential names will be front-padded with an appropriate number of zeros so as all time step outputs will be lexicographically ordered.

xarray_to_vtk_rectilinear_grid()

Write an xarray DataArray to a series of VTK rectilinear grid files.
The resulting files can be opened as a sequence in Paraview to efficiently render time-dependent structured data. The suffix for VTK rectilinear grid files is '.vtr'
This function requires the VTK Python bindings to be installed (vtk.org).
SIGNATURE
def xarray_to_vtk_rectilinear_grid(
    filename_prefix: pathlib.Path | str,
    da: xr.DataArray,
    filename_indexing: tuple[int, str] | None = None,
) -> None: ...
ARGUMENTS
Required
filename_prefix
Type:pathlib.Path | str
Description:
A full path, including a filename prefix, describing where the VTK files should be written.
Required
da
Type:xr.DataArray
Description:
The DataArray to write. Must have dimensions ("x", "y", and "t") (2-D) or ("x", "y", "z", "t") (3-D).
Optional
filename_indexing
Type:tuple[int, str] | None
Default value:None
Description:
A tuple of (offset, format) to use when computing the filenames. If not provided, filenames will start at 0 and sequential names will be front-padded with an appropriate number of zeros so as all time step outputs will be lexicographically ordered.

Classes

WavefieldOutput

Encapsulation of Salvus' volumetric wavefield output.
Meant to mirror the important parts of a volumetric .h5 output file stored on disk as output by SalvusCompute during a simulation.
SIGNATURE
class WavefieldOutput(builtins.object):
    def __init__(
        self,
        conn: np.ndarray,
        crds: np.ndarray,
        data: np.ndarray,
        start_time: float,
        sampling_rate: float,
    ) -> None: ...
ARGUMENTS
Required
conn
Type:np.ndarray
Description:
The connectivity array.
Required
crds
Type:np.ndarray
Description:
The coordinate array.
Required
data
Type:np.ndarray
Description:
The wavefield output data.
Required
start_time
Type:float
Description:
The start time of the encapsulated data (in seconds).
Required
sampling_rate
Type:float
Description:
The sampling rate of the encapsulated data (in hertz).

Properties

  • n_pnts_per_elem(int)-Get the number of points per element (without padding).
  • n_sub_elem(int)-Get the number of sub elements (for visualization).
  • n_ts(float)-Get the number of time steps stored.
  • ndim(int)-Get the dimension of the stored wavefield.
  • nelem(int)-Get the number of elements.
  • sampling_interval(float)-Get the sampling interval of the stored wavefield.
  • shape_order(int)-Get the polynomial order of the stored wavefield.

Class Methods

WavefieldOutput.from_file()
Initialize a WavefieldOutput object from a file.
Meant to be the common way this class is initialized, as all relevant components will be read automatically from the specified file.
SIGNATURE
def from_file(
    filename: pathlib.Path | str,
    field: str,
    output_type: str,
    time_steps: slice = slice(None, None, None),
) -> WavefieldOutput: ...
ARGUMENTS
Required
filename
Type:pathlib.Path | str
Description:
The output file to read from.
Required
field
Type:str
Description:
The field to read.
Required
output_type
Type:str
Description:
The output type of the field (surface or volume).
Optional
time_steps
Type:slice
Default value:slice(None, None, None)
Description:
The time steps indices to read expressed as a python slice object.

Methods

WavefieldOutput.drop_dimension()
Drop a dimension from the output's coordinates.
This function is useful when one wants to plot a 2-D representation of a 3-D surface. Such a use-case is, however, not valid in all circumstances, as degenerate coordinates may be produced as mesh edges, coincident slices, etc. If this case is detected, an exception will be thrown.
SIGNATURE
def drop_dimension(self, dim: int) -> WavefieldOutput: ...
ARGUMENTS
Required
dim
Type:int
Description:
The dimension to drop. Must be an integer in the range(0, n_dim).
WavefieldOutput.get_element_centroid()
Get the centroid of each element.
SIGNATURE
def get_element_centroid(self) -> np.ndarray: ...
WavefieldOutput.get_element_nodes()
Get the nodal locations of each element.
SIGNATURE
def get_element_nodes(self) -> np.ndarray: ...
WavefieldOutput.sizes()
Get the sizes on disk of a wavefield data array.
SIGNATURE
def sizes(
    filename: pathlib.Path | str, field: str, output_type: str
) -> tuple[int, ...]: ...
ARGUMENTS
Required
filename
Type:pathlib.Path | str
Description:
The path to the HDF5 file.
Required
field
Type:str
Description:
The field to query.
Required
output_type
Type:str
Description:
The output type (volume or surface).
PAGE CONTENTS