pyinterp.RTree3D

Contents

pyinterp.RTree3D#

pyinterp.RTree3D(spheroid: pyinterp.core.geometry.geographic.Spheroid | None = None, dtype: object | None = None, distance: str = 'euclidean') → object#

Spatial index for 3D point data with interpolation methods.

Create a spatial R-tree index for 3D point data with support for various interpolation methods including k-nearest neighbor search, inverse distance weighting, kriging, radial basis functions, and window functions.

Parameters:
  • spheroid – Optional spheroid for geodetic coordinate conversions. If provided, input coordinates are assumed to be (lon, lat, alt) in degrees/degrees/meters, and will be converted to ECEF internally. If None, input coordinates are treated as Cartesian without any transformation. These can represent ECEF coordinates, planar coordinates (with Z=0), or any other Cartesian system. Users must ensure unit consistency across all coordinates and values. Defaults to None.

  • dtype – Data type for internal storage, either ‘float32’ or ‘float64’. Determines precision and memory usage. Defaults to ‘float64’.

  • distance –

    Distance measured between the points, used to select the neighbors and returned by the queries and interpolators:

    • 'euclidean' (default): straight-line distance; between ECEF points when a spheroid is given (the chord through the Earth).

    • 'geodesic': geodesic distance on the spheroid (Andoyer’s formula), the distance of pyinterp.core.geometry.geographic.RTree. Requires a spheroid and points at zero altitude. The search still runs on ECEF coordinates and returns the exact geodesic nearest neighbors, at a moderate cost over 'euclidean'. Radial basis functions and kriging keep Euclidean distances between the neighbors in their kernels.

Examples

>>> import numpy as np
>>> import pyinterp

Create RTree for Cartesian coordinates with float64 (default)

>>> coords = np.array([
...     [0.0, 0.0, 0.0],
...     [1.0, 1.0, 0.0]
... ], dtype='float64')
>>> values = np.array([10.5, 20.3], dtype='float64')
>>> tree = pyinterp.RTree3D()
>>> tree.packing(coords, values)

Create RTree with float32 for reduced memory usage

>>> coords_f32 = coords.astype('float32')
>>> values_f32 = values.astype('float32')
>>> tree_f32 = pyinterp.RTree3D(dtype='float32')
>>> tree_f32.packing(coords_f32, values_f32)

Query k-nearest neighbors

>>> from pyinterp.core.config.rtree import Query
>>> query_coords = np.array([[0.5, 0.5, 0.0]])
>>> distances, values = tree.query(query_coords, Query().with_k(2))

Create RTree with geodetic coordinates (lon, lat, alt)

>>> geodetic_coords = np.array([
...     [0.0, 45.0, 100.0],
...     [1.0, 46.0, 200.0]
... ], dtype='float64')
>>> tree_geodetic = pyinterp.RTree3D(spheroid=pyinterp.Spheroid())
>>> tree_geodetic.packing(geodetic_coords, values)