HydroMesh#

class hydromodpy.spatial.HydroMesh(vertices, cell_blocks, cell_data=<factory>, point_data=<factory>, structured_shape=None)[source]#

Bases: object

Unified mesh pivot for structured and unstructured grids.

Parameters#

verticesndarray, shape (n_nodes, 2) or (n_nodes, 3)

Node coordinates. 2-column for planar meshes, 3-column for 3D.

cell_blockstuple of CellBlock

One or more homogeneous connectivity blocks.

cell_datadict[str, ndarray]

Per-cell scalar fields. Each value has shape (total_n_cells,).

point_datadict[str, ndarray]

Per-point scalar fields. Each value has shape (n_nodes,).

structured_shapetuple of int, optional

(nrow, ncol) for 2D structured grids, (nlay, nrow, ncol) for 3D. When set, signals that the vertices follow a regular grid layout and enables optimized adapters (e.g. flopy DIS).

param vertices:

type vertices:

ndarray

param cell_blocks:

type cell_blocks:

tuple[CellBlock, ...]

param cell_data:

type cell_data:

dict[str, ndarray]

param point_data:

type point_data:

dict[str, ndarray]

param structured_shape:

type structured_shape:

tuple[int, ...] | None

property ndim: int#

Spatial dimension (2 or 3).

property single_cell_type: CellType#

Return the unique cell type, or raise if mixed.

property flat_connectivity: ndarray | tuple[ndarray, ...]#

Connectivity across all blocks as a per-cell sequence.

Returns a rectangular (n_cells, k) array for a single fixed-size block (the common case), or a tuple of 1D arrays for a ragged POLYGON block. Either way it is indexable per cell (conn[ic]) and has len(conn) == n_cells, which is all the DISV adapter needs. Mixing ragged and rectangular blocks is not supported here.

bounds()[source]#

Return (xmin, ymin, [zmin,] xmax, ymax, [zmax]).

Return type:

tuple[float, ...]

cell_centroids()[source]#

Per-cell (x, y) centers, matching the field-mesh signature.

Returns the explicit cell_data["disv_cell_center"] (the generator seeds, exact for a Voronoi/PEBI DISV) when present, otherwise the per-cell vertex mean. Ragged-safe (handles POLYGON blocks).

Return type:

tuple[ndarray, ndarray]

with_cell_data(**fields)[source]#

Return a new mesh with validated per-cell arrays added.

The method preserves immutability of the original mesh and therefore behaves as a light builder around the frozen dataclass.

Parameters:

fields (ndarray)

Return type:

HydroMesh

with_point_data(**fields)[source]#

Return a new mesh with validated per-point arrays added.

Parameters:

fields (ndarray)

Return type:

HydroMesh

as_summary()[source]#

Build a light JSON-serializable summary for diagnostics.

The summary intentionally stays compact so that it can be embedded in logs, manifests, or small QA JSON files without dragging the full mesh.

Return type:

dict[str, Any]

Parameters: