Mondaic

salvus.data.io

salvus.data.io salvus data io

Functions for data I/O.

Functions

external_data_to_hdf5()

def external_data_to_hdf5(
    data: xr.Dataset | xr.DataArray,
    receivers: list[_Base] | list[_BaseReceiver] | list[ReceiverChannel],
    output_filename: pathlib.Path | str,
) -> None: ...

Write an xarray.Dataset to a Salvus compatible HDF5 file that can be added to a project.

Parameters
  • data xr.Dataset | xr.DataArray — The data to write to the file.
  • receivers list[_Base] | list[_BaseReceiver] | list[ReceiverChannel] — The corresponding Salvus receivers or receiver channels in the same order as the data (the first dimension in the data is the receiver index).
  • output_filename pathlib.Path | str — Where to store the file.
Returns None

get_built_in_topo_dataset_name()

def get_built_in_topo_dataset_name(
    file_name: str | pathlib.Path,
    radius: float,
    edge_length: float,
    model_order: int,
) -> str: ...

Choose a dataset from Mondaic’s built-in Earth topography files.

The dataset chosen will have the highest angular order available, with the caveat that at least 4 points in the mesh should sample the topography’s highest wavenumber.

Parameters
  • file_name str | pathlib.Path — The name of the topography file.
  • radius float — The radius of the planet.
  • edge_length float — The maximum edge length at the mesh’s top surface.
  • model_order int — The order of the model representation.
Returns str

get_dem()

def get_dem(
    scale: float,
    varname: str,
    fname: str | pathlib.Path,
    min_phi: float | None = None,
    max_phi: float | None = None,
    min_theta: float | None = None,
    max_theta: float | None = None,
) -> tuple[npt.NDArray, npt.NDArray, npt.NDArray]: ...

Get the DEM from a hierarchical HDF5 file.

Parameters
  • scale float — Radius scale.
  • varname str — Variable to get.
  • fname str | pathlib.Path — The filename.
  • min_phi float | None — Minimum phi value.
  • max_phi float | None — Maximum phi value
  • min_theta float | None — Minimum theta value.
  • max_theta float | None — Maximum theta value.
Returns tuple[npt.NDArray, npt.NDArray, npt.NDArray]

manage_topo_bounds()

def manage_topo_bounds(
    euler_angles: tuple[typing.Any, typing.Any, typing.Any],
    min_phi: float | None,
    max_phi: float | None,
    min_theta: float | None,
    max_theta: float | None,
) -> tuple[float | None, float | None, float | None, float | None]: ...

Reset topography bounds if the 1st euler angle is nonzero.

A subtle issue exists in the computation of the domain for partial reads of topography files when euler angles are nonzero. In such cases we reset topographic bounds to their default value (None) which instructs the subsequent call to get_dem to ignore the partial read optimization and instead consider the entire file.

Parameters
  • euler_angles tuple[typing.Any, typing.Any, typing.Any] — The euler angles provided by the user.
  • min_phi float | None — The computed minimum phi value of the bounding box.
  • max_phi float | None — The computed maximum phi value of the bounding box.
  • min_theta float | None — The computed minimum theta value of the bounding box.
  • max_theta float | None — The computed maximum theta value of the bounding box.
Returns tuple[float | None, float | None, float | None, float | None] — If the last euler angle is not None, or if it nonzero, reset the phi / theta values to None as well, otherwise return the phi / theta values as they were.

read_built_in_topo_dataset()

def read_built_in_topo_dataset(
    d: domain.dim3.SphericalDomain,
    file_name: str | pathlib.Path,
    dataset_name: str,
    radius: float,
) -> xr.DataArray: ...

Read one of Mondaic’s built-in topography datasets.

Generic implementation for surface topography, moho topography, and ocean bathymetry.

Parameters
  • d domain.dim3.SphericalDomain — The domain.
  • file_name str | pathlib.Path — The topography file name.
  • dataset_name str — The dataset name in the file.
  • radius float — The radius of the spherical domain.
Returns xr.DataArray

validate_external_data()

def validate_external_data(data: xr.Dataset) -> xr.Dataset: ...

Validate an xarray.Dataset to ensure it can be written to a Salvus compatible HDF5 file.

Parameters
  • data xr.Dataset — Dataset to validate.
Returns xr.Dataset

Used in tutorials