Pyramids¶
Build multi-resolution HEALPix pyramids (grid_doctor.pyramid).
create_healpix_pyramid remaps the
finest level and coarsens it down to the coarsest;
coarsen_healpix coarsens any HEALPix
dataset, for example binned point data. How coarsening treats missing
values is described in the
technical decisions.
Pyramid creation¶
create_healpix_pyramid(ds, max_level=None, min_level=0, *, coarsen_mode='auto', min_valid_fraction=0.5, valid_fraction=False, **kwargs)
¶
Create a multi-resolution HEALPix pyramid.
The input dataset is first remapped to max_level with
regrid_to_healpix.
For nested output ordering, lower levels are derived efficiently
with
coarsen_healpix.
For ring ordering, each lower level is regenerated directly from
the source dataset.
For dask-backed input the result is lazy and chunked along cell
(cell_chunks, forwarded to
regrid_to_healpix); coarser
levels keep that chunk size. Every level builds on the finest one,
so write the pyramid with
save_pyramid, which computes
all levels in one pass. Calling .compute() per level instead
regrids the source once per level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Source dataset. |
required |
max_level
|
int | None
|
Finest HEALPix level. |
None
|
min_level
|
int
|
Coarsest HEALPix level to keep. |
0
|
coarsen_mode
|
CoarsenMode
|
Coarsening strategy for building lower pyramid levels.
|
'auto'
|
min_valid_fraction
|
float
|
Minimum fraction of valid children for a parent cell to be
valid. Default |
0.5
|
valid_fraction
|
ValidFraction
|
Store
|
False
|
**kwargs
|
Unpack[RegridOptions]
|
Forwarded to
|
{}
|
Returns:
| Type | Description |
|---|---|
dict[int, Dataset]
|
Pyramid keyed by level. |
Source code in grid_doctor/pyramid/_build.py
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 | |
Coarsening¶
coarsen_healpix(ds, target_level, coarsen_mode='auto', min_valid_fraction=0.5, valid_fraction=False)
¶
Coarsen a HEALPix dataset to a lower-resolution level.
The coarsening is performed as a single reshape + reduction over all batch dimensions simultaneously, without per-slice Python loops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
HEALPix dataset with a |
required |
target_level
|
int
|
Target HEALPix level (must be lower than the current level). |
required |
coarsen_mode
|
CoarsenMode
|
|
'auto'
|
min_valid_fraction
|
float
|
Minimum fraction of valid (non-NaN) children required to
produce a valid parent cell. Parents with fewer valid
children are set to NaN. Default |
0.5
|
valid_fraction
|
ValidFraction
|
Add |
False
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Coarsened dataset. |
Notes
Nested HEALPix indices have a direct parent-child relationship:
pixel i at level L contains children 4*i to 4*i+3 at
level L+1. Coarsening therefore reduces to grouping contiguous
blocks of 4**delta_level child cells and averaging (or taking
the mode for categorical data).
Ring-ordered datasets do not have contiguous parent-child layout and must be remapped directly at each target level.
With coarsen_mode="mean", always coarsen from the finest level
rather than chaining level by level. A chained mean weights every
valid parent equally, regardless of how many valid finest-level
cells it was built from, so data with NaNs (land, sea ice,
observation gaps) drifts between levels.
Raises:
| Type | Description |
|---|---|
ValueError
|
When the ordering is not nested, or target_level is not lower than the current level. |
Source code in grid_doctor/pyramid/_build.py
Resolution helpers¶
Choose the HEALPix level that matches the resolution of a source grid.
get_latlon_resolution(ds)
¶
Estimate the horizontal resolution of ds in degrees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset on a regular lon/lat grid, a curvilinear grid, or an unstructured grid. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Approximate grid spacing in degrees. |
Examples:
Source code in grid_doctor/_geometry/coords.py
resolution_to_healpix_level(resolution_deg)
¶
Convert an approximate source resolution to a HEALPix level.
The heuristic uses a characteristic HEALPix pixel spacing of about
58.6° / 2**level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution_deg
|
float
|
Approximate source resolution in degrees. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Suggested HEALPix level. |
Examples: