xarray.Dataset.interp (original) (raw)

Dataset.interp(coords=None, method='linear', assume_sorted=False, kwargs=None, method_non_numeric='nearest', **coords_kwargs)[source]#

Interpolate a Dataset onto new coordinates.

Performs univariate or multivariate interpolation of a Dataset onto new coordinates, utilizing either NumPy or SciPy interpolation routines.

Out-of-range values are filled with NaN, unless specified otherwise via kwargs to the numpy/scipy interpolant.

Parameters:

Returns:

interpolated (Dataset) – New dataset on the new coordinates.

Notes

Examples

ds = xr.Dataset( ... data_vars={ ... "a": ("x", [5, 7, 4]), ... "b": ( ... ("x", "y"), ... [[1, 4, 2, 9], [2, 7, 6, np.nan], [6, np.nan, 5, 8]], ... ), ... }, ... coords={"x": [0, 1, 2], "y": [10, 12, 14, 16]}, ... ) ds <xarray.Dataset> Size: 176B Dimensions: (x: 3, y: 4) Coordinates:

1D interpolation with the default method (linear):

ds.interp(x=[0, 0.75, 1.25, 1.75]) <xarray.Dataset> Size: 224B Dimensions: (x: 4, y: 4) Coordinates:

1D interpolation with a different method:

ds.interp(x=[0, 0.75, 1.25, 1.75], method="nearest") <xarray.Dataset> Size: 224B Dimensions: (x: 4, y: 4) Coordinates:

1D extrapolation:

ds.interp( ... x=[1, 1.5, 2.5, 3.5], ... method="linear", ... kwargs={"fill_value": "extrapolate"}, ... ) <xarray.Dataset> Size: 224B Dimensions: (x: 4, y: 4) Coordinates:

2D interpolation:

ds.interp(x=[0, 0.75, 1.25, 1.75], y=[11, 13, 15], method="linear") <xarray.Dataset> Size: 184B Dimensions: (x: 4, y: 3) Coordinates: