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
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 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
data
property
#
Return the data array, triggering lazy load if needed.
has_data_source
property
#
True when the variable can produce an array — eager data or a lazy loader.
Metadata-only, so callers can decide whether to read a variable's values without forcing
the load a bare .data access would trigger.
n_elements
property
#
Number of mesh elements (last dimension of shape).
time_index
property
#
Axis of the real time dimension, or None when the variable is not temporal.
Identifies the time axis by name from dimensions (a dimension named time/t, or
time…/…_time/…_time_… per the CF/UGRID convention) rather than assuming any extra axis
is time. The word-boundary match avoids substring false-positives like runtime / lifetime
/ daytime, and a non-temporal multi-dimensional variable such as (n_layers, n_face)
reports None (ARC-19). When dimensions is unknown — e.g. an array-built variable that
carries no dimension names — it falls back to the historical heuristic (leading axis of a
1-D array).
Returns:
| Type | Description |
|---|---|
int | None
|
The 0-based index of the time axis, or |
has_time
property
#
True when the variable has a real time dimension.
Unlike a bare ndim > 1 test, this is driven by time_index, so a non-temporal
(n_layers, n_face) variable is not mis-flagged as temporal (ARC-19).
n_time_steps
property
#
Number of time steps. Returns 0 if the variable has 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.
load_array()
#
Return the full array without memoising it on this variable.
.data caches the loaded array on the instance; load_array reads it for a one-shot
consumer (e.g. writing every variable to a file) without retaining it, so a bulk operation
over many variables need not hold them all resident at once (issue #982). Returns an already
loaded array when present.
Source code in src/pyramids/netcdf/ugrid/models.py
sel_time(index)
#
Select a single time step, reading only that slab from disk when possible.
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, reading only that slab from disk when possible.
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. |