pyinterp.RTree3D

Contents

pyinterp.RTree3D#

pyinterp.RTree3D(spheroid: pyinterp.core.geometry.geographic.Spheroid | None = None, dtype: object | None = None) 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’.

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

>>> query_coords = np.array([[0.5, 0.5, 0.0]])
>>> distances, values = tree.query(query_coords, 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)