Exotic Model-Grid Adapters#
pyramids.grids turns model grids that are not row-major rasters — ORCA curvilinear
ocean grids, octahedral reduced-Gaussian grids, and HEALPix sphere pixelizations — into a
regular-grid Dataset.
Rather than shipping a new regridder, each adapter reshapes its grid into one of the two regridding bridges pyramids already has, then reuses it:
- a mesh bridge —
mesh_to_grid(reached throughUgridDataset.to_dataset); and - a scattered-point bridge —
[
grid_points][pyramids.dataset.ops.interpolate.grid_points].
| Adapter | Input grid | Bridge it reuses |
|---|---|---|
from_orca |
curvilinear (ny, nx) lon/lat + data |
UGRID quad mesh → mesh_to_grid |
from_octahedral |
ragged per-point lat/lon + values | scattered points → grid_points |
from_healpix |
per-pixel HEALPix values (nside) |
pixel centres → grid_points |
Every adapter returns a single-band Dataset (array + geotransform + CRS) that renders with
no further GIS code on the caller side.
No healpy dependency
from_healpix needs only the HEALPix pixel→centre mapping (pix2ang), which is a
closed-form from the HEALPix paper. pyramids implements it in plain NumPy for both the
RING and NESTED pixel orderings, so no healpy (or other HEALPix C library) is
required.
See the exotic grids example notebook for runnable end-to-end usage of all three adapters.
Functions#
pyramids.grids.from_orca(lon2d, lat2d, data2d, *, cell_size, method='nearest', epsg=4326, nodata=-9999.0)
#
Regrid an ORCA curvilinear field onto a regular-grid :class:Dataset.
The (ny, nx) coordinate arrays are treated as mesh nodes and stitched into
(ny - 1) * (nx - 1) quadrilateral faces. Each face value is the NaN-aware mean
of its four corner nodes (:func:numpy.nanmean), so every value in data2d
(including the last row and column) contributes; NaN-masked nodes are ignored
and a face is NaN only when all four of its corners are NaN. Use NaN
(not a finite sentinel) to mark missing input values. The resulting UGRID mesh is
interpolated to a regular grid via :meth:UgridDataset.to_dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lon2d
|
ndarray
|
|
required |
lat2d
|
ndarray
|
|
required |
data2d
|
ndarray
|
|
required |
cell_size
|
float
|
Output pixel size in the target CRS units. |
required |
method
|
str
|
Interpolation method passed to |
'nearest'
|
epsg
|
int
|
Output EPSG code. |
4326
|
nodata
|
float
|
No-data value stamped on cells the mesh does not cover. |
-9999.0
|
Returns:
| Type | Description |
|---|---|
Dataset
|
A single-band :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Examples:
- Regrid a small curvilinear field and inspect the raster it produces:
>>> import numpy as np >>> from pyramids.grids import from_orca >>> lon2d = np.array([[0.0, 1.0, 2.0], [0.0, 1.0, 2.0]]) >>> lat2d = np.array([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]]) >>> data2d = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]) >>> ds = from_orca(lon2d, lat2d, data2d, cell_size=0.5) >>> ds.band_count 1 >>> ds.epsg 4326 - Mismatched coordinate/data shapes are rejected:
See Also
- :func:
pyramids.grids.from_octahedral: regrid ragged per-point fields. - :meth:
pyramids.netcdf.ugrid.dataset.UgridDataset.to_dataset: the mesh→raster bridge this adapter delegates to.
Source code in src/pyramids/grids/orca.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 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 | |
pyramids.grids.from_octahedral(lats, lons, values, *, cell_size, algorithm='nearest', epsg=4326, bbox=None)
#
Regrid an octahedral reduced-Gaussian field onto a regular-grid :class:Dataset.
The per-point lats/lons/values triples are wrapped in a point
:class:~geopandas.GeoDataFrame and interpolated with gdal.Grid via
:func:~pyramids.dataset.ops.interpolate.grid_points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lats
|
ndarray
|
1-D array of point latitudes. |
required |
lons
|
ndarray
|
1-D array of point longitudes, same length as |
required |
values
|
ndarray
|
1-D array of field values, same length as |
required |
cell_size
|
float
|
Output pixel size in the target CRS units. |
required |
algorithm
|
str
|
A |
'nearest'
|
epsg
|
int
|
Output EPSG code. |
4326
|
bbox
|
tuple[float, float, float, float] | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
A single-band :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Examples:
- Grid four corner observations with nearest-neighbour and inspect the result:
>>> import numpy as np >>> from pyramids.grids import from_octahedral >>> lats = np.array([0.0, 0.0, 5.0, 5.0]) >>> lons = np.array([0.0, 5.0, 0.0, 5.0]) >>> values = np.array([1.0, 2.0, 3.0, 4.0]) >>> ds = from_octahedral(lats, lons, values, cell_size=1.0, algorithm="nearest") >>> (ds.rows, ds.columns, ds.band_count) (5, 5, 1) - Arrays of unequal length are rejected:
See Also
- :func:
pyramids.grids.from_orca: regrid curvilinear(ny, nx)fields. - :func:
pyramids.dataset.ops.interpolate.grid_points: the scattered-point interpolation this adapter delegates to.
Source code in src/pyramids/grids/octahedral.py
pyramids.grids.from_healpix(values, *, nside=None, nest=False, cell_size, method='nearest', epsg=4326, bbox=None)
#
Regrid a HEALPix field onto a regular-grid :class:Dataset.
Each HEALPix pixel's centre longitude/latitude is computed in plain NumPy (no
healpy dependency) and the resulting points are interpolated with gdal.Grid
via :func:~pyramids.dataset.ops.interpolate.grid_points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ndarray
|
1-D array of per-pixel HEALPix values, length |
required |
nside
|
int | None
|
HEALPix resolution parameter. Derived from |
None
|
nest
|
bool
|
|
False
|
cell_size
|
float
|
Output pixel size in the target CRS units (degrees for EPSG:4326). |
required |
method
|
str
|
A |
'nearest'
|
epsg
|
int
|
Output EPSG code. |
4326
|
bbox
|
tuple[float, float, float, float] | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
A single-band :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Examples:
- Regrid a synthetic
nside=1field (12 pixels) and inspect the raster: - NESTED ordering is supported and requires a power-of-two
nside: - A length that is not a valid HEALPix pixel count is rejected:
See Also
- :func:
pyramids.grids.from_octahedral: the sibling point-based adapter this function delegates to viagrid_points.
Source code in src/pyramids/grids/healpix.py
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 | |