healpix_geo.nested.bilinear_interpolation#

healpix_geo.nested.bilinear_interpolation(longitude, latitude, depth, *, ellipsoid='sphere', num_threads=0)#

Get the cell ids and weights necessary to bilinearly interpolate the given values.

Parameters:
  • longitude (numpy.ndarray) – The longitudes of the input points, in degrees.

  • latitude (numpy.ndarray) – The latitudes of the input points, in degrees.

  • depth (int, or numpy.ndarray) – The depth of the HEALPix cells. If given as an array, should have the same shape than ipix

  • ellipsoid (ellipsoid-like, default: "sphere") – Reference ellipsoid to evaluate healpix on. If the reference ellipsoid is spherical, this will return the same result as cdshealpix.nested.vertices().

  • num_threads (int, optional) – Specifies the number of threads to use for the computation. Default to 0 means it will choose the number of threads based on the RAYON_NUM_THREADS environment variable (if set), or the number of logical CPUs (otherwise)

Returns:

  • cell_ids (numpy.ndarray) – The neighbours above and below the given points as a \(N\) x \(4\) masked array.

  • weights (numpy.ndarray) – The associated weights as a \(N\) x \(4\) masked array.

Raises:

ValueError – When the HEALPix cell indexes given have values out of \([0, 4^{29 - depth})\).

Examples

>>> from healpix_geo.nested import bilinear_interpolation
>>> import numpy as np

Define coordinates

>>> lon = np.array([-15.0, -10.0, -5.0, 0.0, 5.0])
>>> lat = np.array([30.0, 35.0, 40.0, 45.0, 50.0])

Compute interpolation weights

>>> cell_ids, weights = bilinear_interpolation(lon, lat, depth=6, ellipsoid="WGS84")
>>> cell_ids
MArray(
    array([[13400, 13401, 13402, 13403],
           [13581, 13592, 13583, 13594],
           [13638, 13639, 13644, 13645],
           [ 2735,  2746, 13663, 13685],
           [ 2800,  2801,  2802,  2803]], dtype=uint64),
    array([[False, False, False, False],
           [False, False, False, False],
           [False, False, False, False],
           [False, False, False, False],
           [False, False, False, False]])
)
>>> weights
MArray(
    array([[0.22596183, 0.68795133, 0.02128467, 0.06480216],
           [0.15244623, 0.78751507, 0.00973729, 0.05030142],
           [0.04859157, 0.12318081, 0.23429192, 0.5939357 ],
           [0.32719215, 0.17280785, 0.32719215, 0.17280785],
           [0.14255714, 0.34522269, 0.1497    , 0.36252017]]),
    array([[False, False, False, False],
           [False, False, False, False],
           [False, False, False, False],
           [False, False, False, False],
           [False, False, False, False]])
)