salvus.mesh.layered_meshing.utils.partition_xarray_data
salvus.mesh.layered_meshing.utils.partition_xarray_data salvus mesh layered_meshing utils partition_xarray_data Partition an xarray DataArray or Dataset into layers separated by interfaces.
Functions
partition_xarray_data()
partition_xarray_data()def partition_xarray_data(
da: _XrTypes, labels: xr.DataArray
) -> tuple[list[_XrTypes], list[xr.DataArray]]: ...Partition a DataArray or Dataset into layers separated by interfaces.
The label array assigns an integer layer index to every grid point, with the horizontal coordinates as the leading dimensions and the vertical coordinate as the trailing dimension. Labels must be dense integers starting from 0 and must be non-decreasing along the vertical axis in unit steps, with the same number of distinct transitions in every horizontal column.
The interface between consecutive layers is located by finding where the label field crosses the midpoint between the two integer values (e.g. 0.5 between layers 0 and 1), using linear interpolation along the vertical coordinate. To ensure that parameters do not bleed across interfaces, each layer is extended by one grid point onto the neighboring layer:
0 --- 0 --- 0 --- 0 0 --- 0 --- 0 --- 0
| | | | | | | |
0 --- 0 --- 0 --- 0 0 --- 0 --- 0 --- 0 1 --- 1 --- 1 --- 1
iface - | | | | -> | | | | , | | | | 1 --- 1 --- 1 --- 1 0 --- 0 --- 0 --- 0 1 --- 1 --- 1 --- 1 | | | | | | | | 1 --- 1 --- 1 --- 1 1 --- 1 --- 1 --- 1
The result is returned as a pair of lists (layers, interfaces):
layers = [layer_0, layer_1, ..., layer_n]
interfaces = [interface_0, interface_1, ..., interface_{n-1}]
where layer_0 is the bottom-most layer and layer_n is the top-most, and
interface_i separates layer_i from layer_{i+1}. Each interface is a
DataArray defined on the horizontal coordinates only, whose values are the
vertical positions of the interface at each horizontal location.
da_XrTypes — The DataArray or Dataset to partition. For a Dataset every data variable is split independently at the same interfaces.labelsxr.DataArray — A DataArray with the same coordinates asda, containing integer labels that define the layers.
(layers, interfaces), where layers is a list of layer data (same type as da) ordered bottom-to-top, and interfaces is a list of DataArrays whose length is one less than layers.