Region selection¶
Select regions from HEALPix stores (grid_doctor.select). They read
only the chunks a region touches and compute the coordinates of the
selected cells, so they also work on stores written without coordinate
arrays (save_pyramid(write_coords=False)). See
Working with the data.
select_bbox(ds, *, lon, lat, level=None, query_delta=_DEFAULT_QUERY_DELTA, load=True)
¶
Extract all cells covering a geographic bounding box.
The box is rasterised at the coarse level level - query_delta;
every coarse parent expands to one contiguous fine-level range of
4**query_delta cells. The result therefore covers the box
(cells straddling the edge are included) with read granularity set
by query_delta; align it with the store's chunk exponent for
reads with zero waste.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
HEALPix dataset (see |
required |
lon
|
tuple[float, float]
|
|
required |
lat
|
tuple[float, float]
|
|
required |
level
|
int | None
|
HEALPix level override. |
None
|
query_delta
|
int
|
Level offset for the coverage query. Larger values mean fewer, larger contiguous reads; smaller values follow the box outline more tightly. |
_DEFAULT_QUERY_DELTA
|
load
|
bool
|
Load the selection into memory (default). |
True
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Compact subset covering the box. |
Source code in grid_doctor/select.py
select_cone(ds, *, lon, lat, radius, level=None, query_delta=_DEFAULT_QUERY_DELTA, load=True)
¶
Extract all cells within radius degrees of a centre point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
HEALPix dataset (see |
required |
lon
|
float
|
Centre coordinates in degrees. |
required |
lat
|
float
|
Centre coordinates in degrees. |
required |
radius
|
float
|
Angular radius in degrees. |
required |
level
|
int | None
|
HEALPix level override. |
None
|
query_delta
|
int
|
Level offset for the coverage query. |
_DEFAULT_QUERY_DELTA
|
load
|
bool
|
Load the selection into memory (default). |
True
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Compact subset covering the cone. |
Source code in grid_doctor/select.py
select_cells(ds, cells, *, level=None, load=True)
¶
Extract the given HEALPix cells from a dataset.
Works on dense datasets (positional index equals cell ID, with or
without materialised coordinates) and on compact subsets (cell
coordinate holds actual IDs). Contiguous ID runs are read as
contiguous slices, so a spatially compact selection touches only
the chunks it needs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
HEALPix dataset, typically opened with
|
required |
cells
|
Int64Array | list[int]
|
Global HEALPix cell IDs to extract (any order; duplicates are dropped). |
required |
level
|
int | None
|
HEALPix level override when the dataset has no HEALPix grid mapping. |
None
|
load
|
bool
|
Load the selected data into memory (default). The selection is small by construction; that is the point of selecting. |
True
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Compact subset: |
Source code in grid_doctor/select.py
attach_cell_coords(ds, cells, *, level, attrs=None)
¶
Attach computed cell coordinates to a compact subset.
HEALPix coordinates are a pure function of the cell index; stores
written with write_coords=False carry none, and this function
reconstructs them for exactly the cells at hand, on the ellipsoid
recorded in ds (the configured one if ds has no HEALPix metadata).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Subset whose |
required |
cells
|
Int64Array
|
Global HEALPix cell IDs, one per position along |
required |
level
|
int
|
HEALPix level of the IDs. |
required |
attrs
|
Mapping[Hashable, object] | None
|
Optional attribute mapping to merge (e.g. the source store's attributes). |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Subset with |