healpix_analyse.neighbour_reduce#
Generic neighbourhood reductions for nested HEALPix fields.
This module provides local, unweighted reductions over geometrically defined HEALPix neighbourhoods.
Neighbourhood geometry is shared with healpix_analyse.morphology.
In particular, the two supported neighbourhood definitions are:
cell_centerInclude cells whose centres lie within
radius_mmetres of the target-cell centre.cone_coverageInclude cells intersecting the circular coverage region returned by
healpix_geo.nested.cone_coverage().
The public API supports both NumPy arrays and PyTorch tensors.
Domain semantics#
cell_ids identifies all HEALPix cells for which input values are
available.
domain identifies the valid processing/output domain.
If domain is None, the processing domain is exactly cell_ids.
If domain is supplied, every domain cell must occur in cell_ids:
domain subset_of cell_ids
Only cells belonging to domain participate in a reduction. A cell
that is geometrically inside a neighbourhood but outside domain is
not treated as zero, False, NaN, or any other padding value. It is
simply absent from the effective neighbourhood.
The output order follows domain exactly when it is supplied, and
cell_ids otherwise.
Classes#
Reusable HEALPix neighbourhood-reduction operator. |
Functions#
|
Reduce field values over local HEALPix neighbourhoods. |
|
Apply a numerical median over HEALPix neighbourhoods. |
|
Apply a mean over HEALPix neighbourhoods. |
|
Apply a minimum over HEALPix neighbourhoods. |
|
Apply a maximum over HEALPix neighbourhoods. |
Module Contents#
- class healpix_analyse.neighbour_reduce.HealPixNeighbourReducer(cell_ids, refinement_level: int, *, radius_m: float, domain=None, neighbourhood: healpix_analyse._neighbourhood.NeighbourhoodMethod = 'cell_center', include_self: bool = True, ellipsoid: str = 'WGS84')[source]#
Reusable HEALPix neighbourhood-reduction operator.
Geometry is constructed once during initialisation and can then be reused for multiple fields sharing the same
cell_idsand processingdomain.- Parameters:
cell_ids – One-dimensional array of unique NESTED HEALPix cell IDs for which input values are available.
Input order is preserved and defines the relationship between
cell_idsand the last dimension ofvalues.refinement_level – HEALPix refinement level, between 0 and 29.
radius_m – Physical neighbourhood radius in metres.
domain – Optional processing/output domain.
If
None, all cells incell_idsform the processing domain.If supplied, every cell in
domainmust also occur incell_ids.Cells outside
domainnever participate in a reduction, even when they lie geometrically withinradius_mand have an available value invalues.Output ordering follows
domainexactly.neighbourhood – HEALPix neighbourhood definition.
"cell_center"Include HEALPix cells whose centres are within
radius_mmetres of the target-cell centre."cone_coverage"Include cells intersecting the circular coverage region used by
healpix_geo.nested.cone_coverage.
include_self – Whether the target cell participates in its own reduction. Defaults to
True.ellipsoid – Reference ellipsoid used by the shared morphology geometry. Defaults to
"WGS84".
Notes
Near a partial-domain boundary, the number of contributing samples can decrease because cells outside
domainare excluded rather than padded with artificial values.- refinement_level#
- radius_m#
- neighbourhood = 'cell_center'#
- include_self = True#
- ellipsoid = 'WGS84'#
- cell_ids#
- property output_cell_ids: numpy.ndarray#
Return output HEALPix IDs in exact output order.
- healpix_analyse.neighbour_reduce.neighbour_reduce(values: ArrayLike, cell_ids, refinement_level: int, *, radius_m: float, reduction: Reduction = 'mean', domain=None, neighbourhood: healpix_analyse._neighbourhood.NeighbourhoodMethod = 'cell_center', include_self: bool = True, ellipsoid: str = 'WGS84') ArrayLike[source]#
Reduce field values over local HEALPix neighbourhoods.
- Parameters:
values – NumPy array or PyTorch tensor.
The last dimension is aligned one-to-one with
cell_ids. Arbitrary leading dimensions are supported.cell_ids – One-dimensional array of unique NESTED HEALPix cell IDs for which input values are available.
The order of
cell_idsis preserved.refinement_level – HEALPix refinement level, between 0 and 29.
radius_m – Physical neighbourhood radius in metres.
reduction – Reduction applied to each effective local neighbourhood.
Supported values are
"mean","sum","min","max","median","count","std","any","all", and"mode".domain – Optional processing/output domain.
If
None, all cells incell_idsform the domain.If provided,
domainmust be a subset ofcell_ids. The output contains one value per domain cell and follows the exact order ofdomain.Cells outside
domainnever participate in a reduction, even when they lie geometrically withinradius_mand have an input value invalues.Such cells are not zero-padded or assigned another synthetic value. They are simply absent from the effective neighbourhood.
neighbourhood – Definition of the HEALPix neighbourhood.
"cell_center"Include cells whose centres are within
radius_mmetres of the target-cell centre."cone_coverage"Include cells intersecting the corresponding circular coverage region.
include_self – Whether the target cell participates in its own reduction. Defaults to
True.ellipsoid – Reference ellipsoid used for physical-distance calculations. Defaults to
"WGS84".
- Returns:
numpy.ndarrayortorch.Tensor– Reduced values.The backend follows
values. The final dimension followsdomainwhen explicitly supplied andcell_idsotherwise.
Notes
Near a partial-domain boundary, the effective neighbourhood can contain fewer samples because cells outside the processing domain are excluded rather than padded.
Numerical
medianand categoricalmodeare intentionally different operations. For an even number of numerical samples,medianaverages the two central sorted values.Empty effective neighbourhoods have the following identities:
sum-> 0count-> 0any-> Falseall-> True
Other reductions raise
ValueErroron an empty effective neighbourhood.
- healpix_analyse.neighbour_reduce.median_filter(values: ArrayLike, cell_ids, refinement_level: int, *, radius_m: float, domain=None, neighbourhood: healpix_analyse._neighbourhood.NeighbourhoodMethod = 'cell_center', include_self: bool = True, ellipsoid: str = 'WGS84') ArrayLike[source]#
Apply a numerical median over HEALPix neighbourhoods.
- healpix_analyse.neighbour_reduce.mean_filter(values: ArrayLike, cell_ids, refinement_level: int, *, radius_m: float, domain=None, neighbourhood: healpix_analyse._neighbourhood.NeighbourhoodMethod = 'cell_center', include_self: bool = True, ellipsoid: str = 'WGS84') ArrayLike[source]#
Apply a mean over HEALPix neighbourhoods.
- healpix_analyse.neighbour_reduce.min_filter(values: ArrayLike, cell_ids, refinement_level: int, *, radius_m: float, domain=None, neighbourhood: healpix_analyse._neighbourhood.NeighbourhoodMethod = 'cell_center', include_self: bool = True, ellipsoid: str = 'WGS84') ArrayLike[source]#
Apply a minimum over HEALPix neighbourhoods.
- healpix_analyse.neighbour_reduce.max_filter(values: ArrayLike, cell_ids, refinement_level: int, *, radius_m: float, domain=None, neighbourhood: healpix_analyse._neighbourhood.NeighbourhoodMethod = 'cell_center', include_self: bool = True, ellipsoid: str = 'WGS84') ArrayLike[source]#
Apply a maximum over HEALPix neighbourhoods.