healpix_resample.knn.KNeighborsResampler#

class healpix_resample.knn.KNeighborsResampler(lon_deg, lat_deg, Npt, level, *, nest=True, radius=6371000.0, ellipsoid='WGS84', dtype=torch.float64, device=None, ring_weight=None, ring_search_init=None, ring_search_max=2, num_threads=0, threshold=0.1, sigma_m=None, verbose=True, out_cell_ids=None, group_by=False)[source]#

GPU-friendly sparse HEALPix regridding via local Gaussian weights + CG deconvolution.

This class builds two sparse operators from unstructured lon/lat samples to a subset of HEALPix pixels at a target resolution (nside = 2**level).

Notation (matching your notebook):
  • N: number of samples (lon/lat)

  • K: number of kept HEALPix cells (cell_ids)

  • M: operator of shape (N, K) (named M here)

  • MT: operator of shape (K, N) (named MT here)

The solver estimates hval (B,K) such that M @ hval.T matches val (B,N), by solving a damped normal equation around a reference field x_ref = val @ M.

__init__(lon_deg, lat_deg, Npt, level, *, nest=True, radius=6371000.0, ellipsoid='WGS84', dtype=torch.float64, device=None, ring_weight=None, ring_search_init=None, ring_search_max=2, num_threads=0, threshold=0.1, sigma_m=None, verbose=True, out_cell_ids=None, group_by=False)[source]#

Pre-compute sparse operators.

Parameters:
  • lon_deg, lat_deg – unstructured sample coordinates in degrees, shape (N,)

  • Npt – number of nearest HEALPix cells used per sample

  • 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

Methods

__init__(lon_deg, lat_deg, Npt, level, *[, ...])

Pre-compute sparse operators.

comp_matrix()

get_cell_ids()

invert(hval)

Project HEALPix field back to the sample locations.

resample(val, *[, lam, max_iter, tol, x0, ...])

Estimate the HEALPix field from unstructured samples.