xarray.DataArray.interp

DataArray.interp(coords=None, method='linear', assume_sorted=False, kwargs=None, **coords_kwargs)

Multidimensional interpolation of variables.

Parameters
  • coords (dict, optional) – Mapping from dimension names to the new coordinates. New coordinate can be an scalar, array-like or DataArray. If DataArrays are passed as new coordinates, their dimensions are used for the broadcasting. Missing values are skipped.

  • method (str, default: "linear") – The method used to interpolate. Choose from

    • {“linear”, “nearest”} for multidimensional array,

    • {“linear”, “nearest”, “zero”, “slinear”, “quadratic”, “cubic”} for 1-dimensional array.

  • assume_sorted (bool, optional) – If False, values of x can be in any order and they are sorted first. If True, x has to be an array of monotonically increasing values.

  • kwargs (dict) – Additional keyword arguments passed to scipy’s interpolator. Valid options and their behavior depend on if 1-dimensional or multi-dimensional interpolation is used.

  • **coords_kwargs ({dim: coordinate, ...}, optional) – The keyword arguments form of coords. One of coords or coords_kwargs must be provided.

Returns

interpolated – New dataarray on the new coordinates.

Return type

DataArray

Notes

scipy is required.

See also

scipy.interpolate.interp1d(), scipy.interpolate.interpn()

Examples

>>> da = xr.DataArray([1, 3], [("x", np.arange(2))])
>>> da.interp(x=0.5)
<xarray.DataArray ()>
array(2.)
Coordinates:
    x        float64 0.5