Mesh-to-Grid Interpolation#
Converts unstructured mesh data to regular grids using
nearest-neighbor or linear interpolation. This module
implements the bridge between UgridDataset and Dataset.
pyramids.netcdf.ugrid.interpolation.mesh_to_grid(mesh, data, location, cell_size, method='nearest', bounds=None, nodata=-9999.0, max_distance=None)
#
Interpolate mesh data onto a regular grid.
This is the core bridge function. The result is a 2D numpy array and a GDAL-style geotransform that can be wrapped in a pyramids Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
Mesh2d
|
Source mesh topology. |
required |
data
|
ndarray
|
1D data array (n_faces, n_nodes, or n_edges). |
required |
location
|
str
|
"face", "node", or "edge". |
required |
cell_size
|
float
|
Target grid cell size in coordinate units. |
required |
method
|
str
|
Interpolation method ("nearest" or "linear"). |
'nearest'
|
bounds
|
tuple[float, float, float, float] | None
|
(xmin, ymin, xmax, ymax). Defaults to mesh bounds. |
None
|
nodata
|
float
|
Fill value for grid cells outside the mesh. |
-9999.0
|
max_distance
|
float | None
|
Maximum distance from a mesh element for a grid cell to receive a value. Defaults to 2 * cell_size. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Tuple of (grid_array, geotransform) where grid_array is 2D |
tuple[float, ...]
|
(rows, cols) and geotransform is a 6-element tuple |
tuple[ndarray, tuple[float, ...]]
|
(x_origin, cell_size, 0, y_origin, 0, -cell_size). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If location is unknown or edge coordinates are unavailable for edge-centered data. |