wradlib.ipol.IpolMethods.interpolate

wradlib.ipol.IpolMethods.interpolate#

IpolMethods.interpolate(trg, **kwargs)[source]#

Interpolate data from source coordinates to target coordinates using a chosen backend.

This function provides a unified interface to multiple interpolation backends (scipy.spatial.KDTree-based, scipy.interpolate.griddata based, and scipy.ndimage.map_coordinates) through a single method keyword. The behavior depends on the chosen backend and the dimensionality of the source and target data.

Backends and method strings#

scipy.spatial.KDTree-based methods (structured or unstructured points):
  • ‘nearest’ : nearest neighbor

  • ‘inverse_distance’ : inverse distance weighting (IDW)

  • ‘ordinary_kriging’ : ordinary kriging

scipy.interpolate.griddata (arbitrary N-dimensional points):
  • ‘griddata’ : uses SciPy default (‘linear’)

  • ‘griddata_linear’ : linear interpolation

  • ‘griddata_cubic’ : cubic interpolation

scipy.ndimage.map_coordinates (N-dimensional arrays with fractional coordinates):
  • ‘map_coordinates’ : default order=3 (cubic)

  • ‘map_coordinates_nearest’: order=0

  • ‘map_coordinates_linear’ : order=1

  • ‘map_coordinates_quadratic’: order=2

  • ‘map_coordinates_cubic’ : order=3

  • ‘map_coordinates_quartic’: order=4

  • ‘map_coordinates_quintic’: order=5

Parameters:
  • src (xarray.DataArray or xarray.Dataset) – Source data to be interpolated. Can be N-dimensional.

  • trg (xarray.DataArray or xarray.Dataset) –

    Target coordinates. Expected shape and dimensionality depend on the backend:
  • method (str) – Interpolation method / backend selection. See “Backends and method strings” above. Suffixes indicate backend-specific interpolation type (e.g., ‘griddata_cubic’).

  • kwargs (dict) – Additional keyword arguments passed to the low-level interpolation routines.

returns:

xarray.DataArray or xarray.Dataset – Interpolated data on the target coordinates. The output type matches the input.

Notes

  • scipy.spatial.KDTree-based methods automatically compute a mapping from source to target unless a precomputed mapping is provided.

  • scipy.interpolate.griddata uses ‘linear’ by default if no specific method is provided.

  • scipy.ndimage.map_coordinates uses order=3 (cubic) by default. User-supplied order overrides the method suffix; a warning is issued if both are provided.

  • The method keyword encodes both backend and interpolation type; the backend is inferred from the prefix (‘nearest’, ‘griddata’, ‘map_coordinates’, etc.).

  • Backend-specific kwargs take precedence over defaults when provided.

  • This function supports arbitrary N-dimensional data; polar-to-Cartesian is just one common use case.

Examples

>>> # KDTree nearest neighbor interpolation
>>> out = src.wrl.ipol.interpolate(target, method='nearest')
>>> # KDTree inverse distance weighting
>>> out = src.wrl.ipol.interpolate(target, method='inverse_distance')
>>> # SciPy griddata with cubic interpolation
>>> out = src.wrl.ipol.interpolate(target, method='griddata_cubic', backend_kwargs={'fill_value': np.nan})
>>> # SciPy map_coordinates with quintic spline interpolation
>>> out = src.wrl.ipol.interpolate(target, method='map_coordinates_quintic')