Point Binning API¶
This section contains the functionality for mapping point-sampled data — satellite Level-2 swaths, station records, trajectories — onto the standard grid-doctor HEALPix representation. Point data cannot use the ESMF weight path: every granule has unique geometry (no weight reuse) and nearest source-to-destination would smear a narrow swath over the entire globe. Binning assigns each sample to its containing HEALPix cell and reduces per cell instead.
See the point data recipe for an end-to-end workflow and the shared technical decisions document for the design rationale.
Binning¶
bin_to_healpix(ds, level, *, agg='mean', nest=True, lat_name=None, lon_name=None, source_units='auto', fill_values=None, min_count=1, with_counts=False, dense=True)
¶
Bin point-sampled data into HEALPix cells.
Every sample is assigned to the HEALPix cell containing its coordinates (perfect-sphere geometry, consistent with all other grid-doctor output) and all samples per cell are reduced with the requested aggregation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with per-sample latitude/longitude variables (swath
geolocation, station coordinates, …). Variables that span the
sample dimensions are binned; variables that share none of the
sample dimensions are passed through unchanged; variables that
overlap them only partially are skipped with a warning.
Non-sample dimensions ( |
required |
level
|
int
|
Target HEALPix level. Choose it so the cell spacing
( |
required |
agg
|
BinAgg | Mapping[str, BinAgg]
|
Aggregation per variable: a single method applied to all
variables or a mapping |
'mean'
|
nest
|
bool
|
Use nested HEALPix ordering when True. Nested ordering is required for pyramid coarsening. |
True
|
lat_name
|
str | None
|
Explicit coordinate variable names. When omitted, the standard
grid-doctor name lists are searched ( |
None
|
lon_name
|
str | None
|
Explicit coordinate variable names. When omitted, the standard
grid-doctor name lists are searched ( |
None
|
source_units
|
SourceUnits
|
Angular unit convention of the coordinates. |
'auto'
|
fill_values
|
Mapping[str, float] | None
|
Explicit per-variable fill values, e.g. |
None
|
min_count
|
int
|
Minimum number of valid samples required for a cell to be
valid. Cells with fewer samples are set to NaN (does not apply
to |
1
|
with_counts
|
bool
|
Add an |
False
|
dense
|
bool
|
When True (default), return the full |
True
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Binned dataset on the HEALPix grid. |
Raises:
| Type | Description |
|---|---|
ValueError
|
On unknown aggregation methods, invalid levels, or when no valid sample coordinates exist. |
Examples:
hpx = gd.bin_to_healpix(
swath,
level=11,
agg={"radiance": "mean", "cloud_type": "mode"},
fill_values={"cloud_type": 255},
with_counts=True,
)
pyramid = {11: hpx}
for lvl in range(10, -1, -1):
pyramid[lvl] = gd.coarsen_healpix(pyramid[lvl + 1], lvl)
Source code in grid_doctor/swath/__init__.py
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 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 | |
Sparse intermediates¶
At high HEALPix levels a single granule touches only a tiny fraction of
the global grid. bin_to_healpix(..., dense=False) returns a compact
per-granule dataset that can be accumulated cheaply and expanded once
before publishing.
sparse_to_dense(ds)
¶
Scatter a compact (sparse) binned dataset onto the full grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Output of |
required |
Returns:
| Type | Description |
|---|---|
Dataset
|
Dense dataset with the standard grid-doctor HEALPix coordinates
and metadata, ready for
|
Raises:
| Type | Description |
|---|---|
ValueError
|
When ds does not look like a sparse binned dataset. |