UGRID Data Models#
Dataclasses for UGRID topology metadata, mesh variables, and dataset-level metadata summaries.
UgridMetadata is the dataset-level summary: it aggregates one MeshTopologyInfo per mesh and records
the variable inventory as a data_variables: dict[str, str] map (variable name → mesh location). The
MeshVariable records themselves are held by UgridDataset, not by UgridMetadata. A
MeshVariable carries a lazy loader so its data is only materialised on access, and offers
time-slicing helpers:
classDiagram
class UgridMetadata {
data_variables : dict[str,str]
global_attributes
conventions
n_nodes / n_faces / n_edges
}
class MeshTopologyInfo {
mesh_name
topology_dimension
node_x_var / node_y_var
face_node_var / edge_node_var
crs_wkt
}
class MeshVariable {
name · location · mesh_name
shape · nodata · units
+data
+n_time_steps
+sel_time(i)
+sel_time_range(a, b)
+with_data(arr)
}
UgridMetadata o-- MeshTopologyInfo : mesh_topologies
note for UgridMetadata "data_variables is a name → location map, not MeshVariable records"
note for MeshVariable "held by UgridDataset; data is loaded lazily on first access"
pyramids.netcdf.ugrid.MeshTopologyInfo
dataclass
#
Parsed UGRID topology metadata from a NetCDF file.
Represents the structure of a single mesh topology variable, including references to coordinate variables, connectivity arrays, and data variables defined on the mesh.
Attributes:
| Name | Type | Description |
|---|---|---|
mesh_name |
str
|
Name of the topology variable (e.g., "mesh2d"). |
topology_dimension |
int
|
Mesh dimensionality (1=network, 2=surface, 3=volume). |
node_x_var |
str
|
Name of the node x-coordinate variable. |
node_y_var |
str
|
Name of the node y-coordinate variable. |
face_node_var |
str | None
|
Name of the face-node connectivity variable. |
edge_node_var |
str | None
|
Name of the edge-node connectivity variable. |
face_edge_var |
str | None
|
Name of the face-edge connectivity variable. |
face_face_var |
str | None
|
Name of the face-face connectivity variable. |
edge_face_var |
str | None
|
Name of the edge-face connectivity variable. |
boundary_node_var |
str | None
|
Name of the boundary-node connectivity variable. |
face_x_var |
str | None
|
Name of the face center x-coordinate variable. |
face_y_var |
str | None
|
Name of the face center y-coordinate variable. |
edge_x_var |
str | None
|
Name of the edge center x-coordinate variable. |
edge_y_var |
str | None
|
Name of the edge center y-coordinate variable. |
data_variables |
dict[str, str]
|
Mapping of variable name to mesh location (e.g., {"water_level": "face"}). |
crs_wkt |
str | None
|
Well-Known Text representation of the CRS, if available. |
Source code in src/pyramids/netcdf/ugrid/models.py
pyramids.netcdf.ugrid.MeshVariable
dataclass
#
Data variable defined on a mesh location.
Wraps a numpy array of values associated with mesh elements (nodes, faces, or edges). Supports lazy loading via a loader callable that defers reading until data is first accessed.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Variable name in the NetCDF file. |
location |
str
|
Mesh location ("node", "face", or "edge"). |
mesh_name |
str
|
Name of the associated mesh topology variable. |
shape |
tuple[int, ...]
|
Shape of the data array. |
attributes |
dict[str, Any]
|
Dictionary of NetCDF variable attributes. |
nodata |
float | None
|
No-data / fill value for masked elements. |
units |
str | None
|
Physical units string (e.g., "m", "m/s"). |
standard_name |
str | None
|
CF standard name (e.g., "sea_surface_height"). |
_data |
ndarray | None
|
Eagerly loaded data array, or None if using lazy loading. |
_loader |
Callable[[], ndarray] | None
|
Callable that returns the data array on first access. |
Source code in src/pyramids/netcdf/ugrid/models.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
data
property
#
Return the data array, triggering lazy load if needed.
n_elements
property
#
Number of mesh elements (last dimension of shape).
has_time
property
#
True if the data has a time dimension (2D or higher).
n_time_steps
property
#
Number of time steps. Returns 0 if no time dimension.
dtype
property
#
Data type of the variable.
Returns the explicitly set dtype if available, falls back to the loaded data's dtype, and defaults to float64.
sel_time(index)
#
Select a single time step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Time step index. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
1D array of values at the given time step. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If index is out of range. |
ValueError
|
If the variable has no time dimension, or has no loaded data array. |
Source code in src/pyramids/netcdf/ugrid/models.py
sel_time_range(start, stop)
#
Select a time range, returning a new MeshVariable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
int
|
Start time index (inclusive). |
required |
stop
|
int
|
Stop time index (exclusive). |
required |
Returns:
| Type | Description |
|---|---|
MeshVariable
|
New MeshVariable with the selected time range. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the variable has no time dimension, or has no loaded data array. |
Source code in src/pyramids/netcdf/ugrid/models.py
with_data(data)
#
Return a copy of this variable carrying data, keeping all other metadata.
The new variable is eager (_data set, no loader); its shape is taken from
data when provided, else the original shape is retained. Used wherever a
derived dataset (time selection, spatial clip, …) replaces a variable's array while
preserving its name / location / mesh / attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray | None
|
The replacement data array, or |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MeshVariable |
MeshVariable
|
The copy carrying |
Source code in src/pyramids/netcdf/ugrid/models.py
pyramids.netcdf.ugrid.UgridMetadata
dataclass
#
Full metadata summary for a UGRID dataset.
Aggregates topology information, data variable inventory, global attributes, and mesh element counts for display and inspection purposes.
Attributes:
| Name | Type | Description |
|---|---|---|
mesh_topologies |
tuple[MeshTopologyInfo, ...]
|
List of parsed mesh topologies in the file. |
data_variables |
dict[str, str]
|
Mapping of variable name to location. |
global_attributes |
dict[str, Any]
|
File-level NetCDF attributes. |
conventions |
str | None
|
Conventions string (e.g., "CF-1.8 UGRID-1.0"). |
n_nodes |
int
|
Total number of mesh nodes. |
n_faces |
int
|
Total number of mesh faces. |
n_edges |
int
|
Total number of mesh edges. |