healpix_resample.CellPointResampler#

class healpix_resample.CellPointResampler(*args, **kwargs)[source]#

Resample input lat-lon points as HEALPix “cell-points”.

The values of the input lat-lon points are resampled on HEALPix cells with a fixed, maximum refinement level (=29) in which the points are located.

Level-29 cells have a tiny resolution of 0.4 milliarcseconds. In many applications those cells can be approximated as “points”.

If multiple input points are located within the same cell, their values are merged according to the reduce option.

__init__(*args, **kwargs)[source]#

Pre-compute sparse operators.

Parameters:
  • lon_deg, lat_deg – unstructured sample coordinates in degrees, shape (N,); float32 or float64, the geometry is computed in float64

  • Npt – number of nearest HEALPix cells used per sample. A sample that does not find Npt kept cells within ring_search_max rings (samples much sparser than the cells) keeps the ones it found.

  • ring_search_init, ring_search_max – first and last HEALPix ring of the per-sample neighbour search; a ring_search_max below ring_search_init is raised to it

  • level – HEALPix level, nside = 2**level

  • sigma_m – Gaussian length scale (meters). If None, uses the HEALPix pixel scale sigma = sqrt(4*pi/(12*4**level))*R.

  • threshold – keep only HEALPix cells whose global weight sum >= threshold

  • nest – HEALPix indexing scheme

  • dtype/device – torch dtype/device for all matrices and computations

  • out_cell_ids – optional subset of level cells to restrict the output to (e.g. one chunk or one parent cell). If none of these cells has enough support among the samples, the operator is built with K = 0 instead of raising: resample() then returns cell_ids of size 0 and cell_data of shape (B, 0), except NearestResampler, whose fallback fills the requested cells with their nearest sample (see its max_distance_m).

  • batch_size – process the samples in slices of this size when building the operators (see healpix_weighted_nearest): the temporary memory of the neighbour search is then about 2 kB per sample of a slice instead of 2 kB per sample. None (default) processes all samples at once. The result is the same.

  • coarse_level_delta – number the cells of the neighbour search from their parents this many levels coarser (nested only; see healpix_weighted_nearest): the same cells, neighbours and ties as the fine-level search, in less time and memory. None (default): the fine-level search.

  • neighbours – the links (NeighbourLinks) of an earlier resampler on the same samples, level and search parameters (its neighbours attribute): the neighbour search is skipped and the distances computed again, so the resampler is the same, bit for bit. With Npt=1 it is ignored.

Raises:

RuntimeError – without out_cell_ids, when no cell passes threshold (lower threshold or widen the neighbourhood rings), or when cells pass it but no sample reaches any of them within ring_search_max rings.

Methods

__init__(*args, **kwargs)

Pre-compute sparse operators.

comp_matrix()

Build self.M (N,K), sparse CSC: links weighted by _link_weights() (and the tied links by _tie_weights()), normalised per cell (column).

get_cell_ids()

invert(hval)

Project HEALPix field back to the sample locations.

resample(val)

Estimate the HEALPix field from unstructured samples.

Attributes

MT

Sparse CSR (K, N) operator, cells -> samples (invert()); built on first access.

M_cons

Sparse CSR (N, K) conservative operator (resample(conservative=True), same links as M, each sample's weights summing to 1); built on first access.