healpix_resample.knn.healpix_weighted_nearest#
- healpix_resample.knn.healpix_weighted_nearest(longitude1, latitude1, level, Npt, *, return_ties=False, **kwargs)[source]#
- Returns:
cell_ids – (K,) HEALPix pixels (at level) kept by the weight threshold (and intersected with out_cell_ids, if given) idx_k : (N, Npt + E) indices into cell_ids (0..K-1), -1 if not enough neighbours dist_k : (N, Npt + E) distances (m) to the centres of those pixels, inf if not enough neighbours
With
return_ties=True:(cell_ids, idx_k, dist_k, ties), whereidx_k/dist_kare(N, Npt)andties = (rows, idx, dist)holds the tied links as flat 1-D tensors (empty without ties). This is whatKNeighborsResampleruses: the ties are a few per million samples, so they do not widen the(N, Npt)arrays.Notes
The E extra columns of idx_k / dist_k hold the cells at the same distance as the Npt-th one (ties, see
_nearest_with_ties), -1 / inf for the samples without a tie; E = 0 when no sample has a tie.Distances: chord-based great-circle distance in the Npt-nearest search (
_arc_distance),R * acos(dot)in the threshold stage.healpix_geo is used for lonlat_to_healpix, kth_neighbourhood, healpix_to_lonlat.
The accuracy is good enough for “pixel centre matching”.
batch_size: the weight accumulation and the Npt-nearest search allocate about(2*ring+1)**2 * 100bytes per sample (the neighbourhood ids, centre coordinates, distances and weights of every sample at once). Withbatch_sizeset, the samples are processed in slices of that size, so this temporary memory is bounded by the batch and not by N; the per-cell weight sums and the per-sample results are the same (see_healpix_weighted_nearest_batched).coarse_level_delta(nested ids only,Npt > 1): number the cells from their parents that many levels coarser (c * 4**k + jids, centres computed once per cell) and get the neighbourhoods from the face coordinates instead of a global sort andkth_neighbourhoodper sample, in batches ofbatch_sizesamples (default 32768). Same result as without it, in less time and memory. See_coarse_weighted_nearest.
The other keyword arguments are those of
_healpix_weighted_nearest.