suxarray.grid package

Submodules

suxarray.grid.area module

suxarray.grid.grid module

class suxarray.grid.grid.Grid(grid_obj: Dataset | Grid, ds_sgrid_info: Dataset | None = None, source_grid_spec: str = 'UGRID', source_dims_dict: dict | None = {}, **kwargs)[source]

Bases: Grid

uxarray Grid class for SCHISM See uxarray Grid documentation for the details of the methods and properties

Examples

TBD

classmethod from_dataset(ds_out2d: Dataset, ds_zcoords: Dataset, **kwargs)[source]

Create a Grid object from a SCHISM output 2D dataset and a z-coordinate dataset

Parameters

ds_out2dxr.Dataset

SCHISM output 2D dataset

ds_sgrid_infoxr.Dataset, optional

Extra SCHISM grid information

Returns

Grid

get_strtree(elements: str | None = 'nodes')[source]
intersect(geometry: shapely.geometry.BaseGeometry, element: str | None = 'faces', **kwargs)[source]

Find intersecting elements with a Shapely geometry

Parameters

geometry: shapely.geometry.Geometry element: str, optional

Returns

int

Indices of intersecting elements

isel(**dim_kwargs)[source]

Indexes an unstructured grid along a given dimension (n_node, n_edge, or n_face) and returns a new grid.

Currently only supports inclusive selection, meaning that for cases where node or edge indices are provided, any face that contains that element is included in the resulting subset. This means that additional elements beyond those that were initially provided in the indices will be included. Support for more methods, such as exclusive and clipped indexing is in the works.

Parameters

inverse_indiceslist[str] | set[str] | bool, default=False

Indicates whether to store the original grids indices. Passing True stores the original face indices, other reverse indices can be stored by passing any or all of the following: ([“face”, “edge”, “node”], True)

**dims_kwargs: kwargs

Dimension to index, one of [‘n_node’, ‘n_edge’, ‘n_face’]

Example

>> grid = ux.open_grid(grid_path) >> grid.isel(n_face = [1,2,3,4])

property sgrid_info: Dataset
sgrid_isel(**kwargs)[source]
subset

alias of GridSubsetAccessor

suxarray.grid.integrate module

suxarray.grid.integrate.calc_volumes_from_projected(sxda)[source]

Calculate the volume of prism under a selection of nodes for each layer in the vertical direction.

Parameters

sxdaSxDataArray

SxDataArray with z-coordinates and bottom indices. This function enforces single-timestep behavior.

Returns

ndarray, shape (n_layer-1, n_face)

Volume of each prism layer under the selection of nodes.

Notes

For external dask/xarray parallelization over time, use calc_volumes_from_projected_kernel with xarray.apply_ufunc.

suxarray.grid.integrate.integrate_prism_variable(sxda, return_per_layer=False)[source]

Integrate a variable under an element over the water column for nodal data.

Parameters

sxdaSxDataArray

SxDataArray with z-coordinates and bottom indices containing the variable to integrate. Variable must be a concentration or density-like quantity (e.g., chlorophyll, salt, energy) that can be integrated over the water column to produce a total quantity per face element. This function enforces single-timestep behavior.

return_per_layerbool, optional

If True, return per-layer integrated values with shape (n_layer-1, n_face). If False (default), return total integrated values per face with shape (n_face).

Returns

ndarray

If return_per_layer=False: shape (n_face), integrated variable per face element summed over all layers. If return_per_layer=True: shape (n_layer-1, n_face), integrated variable per layer and face.

suxarray.grid.integrate.projected_volume_ufunc_kernel(z, node_x, node_y, connectivity, bottom_indices)[source]

Array-kernel companion for calc_volumes_from_projected.

This helper is designed for external orchestration with xarray.apply_ufunc(..., dask='parallelized') where z is passed as an ndarray block/chunk.

Parameters

zndarray, shape (n_node, n_layer)

Single-timestep z-coordinates.

node_xndarray, shape (n_node,)

x coordinates of nodes.

node_yndarray, shape (n_node,)

y coordinates of nodes.

connectivityndarray, shape (n_face, n_node_per_face)

Node indices for each face.

bottom_indicesndarray, shape (n_node,)

0-based bottom layer index for each node.

Returns

ndarray, shape (n_layer-1, n_face)

Prism volumes per layer and face for one timestep.

suxarray.grid.neighbors module

class suxarray.grid.neighbors.STRTree(grid, elements: str | None = 'nodes')[source]

Bases: object

property faces
nearest(geometry)[source]
property points
query(geometry, predicate=None, distance=None)[source]

Module contents

class suxarray.grid.Grid(grid_obj: Dataset | Grid, ds_sgrid_info: Dataset | None = None, source_grid_spec: str = 'UGRID', source_dims_dict: dict | None = {}, **kwargs)[source]

Bases: Grid

uxarray Grid class for SCHISM See uxarray Grid documentation for the details of the methods and properties

Examples

TBD

classmethod from_dataset(ds_out2d: Dataset, ds_zcoords: Dataset, **kwargs)[source]

Create a Grid object from a SCHISM output 2D dataset and a z-coordinate dataset

Parameters

ds_out2dxr.Dataset

SCHISM output 2D dataset

ds_sgrid_infoxr.Dataset, optional

Extra SCHISM grid information

Returns

Grid

get_strtree(elements: str | None = 'nodes')[source]
intersect(geometry: shapely.geometry.BaseGeometry, element: str | None = 'faces', **kwargs)[source]

Find intersecting elements with a Shapely geometry

Parameters

geometry: shapely.geometry.Geometry element: str, optional

Returns

int

Indices of intersecting elements

isel(**dim_kwargs)[source]

Indexes an unstructured grid along a given dimension (n_node, n_edge, or n_face) and returns a new grid.

Currently only supports inclusive selection, meaning that for cases where node or edge indices are provided, any face that contains that element is included in the resulting subset. This means that additional elements beyond those that were initially provided in the indices will be included. Support for more methods, such as exclusive and clipped indexing is in the works.

Parameters

inverse_indiceslist[str] | set[str] | bool, default=False

Indicates whether to store the original grids indices. Passing True stores the original face indices, other reverse indices can be stored by passing any or all of the following: ([“face”, “edge”, “node”], True)

**dims_kwargs: kwargs

Dimension to index, one of [‘n_node’, ‘n_edge’, ‘n_face’]

Example

>> grid = ux.open_grid(grid_path) >> grid.isel(n_face = [1,2,3,4])

property sgrid_info: Dataset
sgrid_isel(**kwargs)[source]
subset

alias of GridSubsetAccessor