Skip to content

Commit 6a6f2c8

Browse files
authored
Add multi-dimensional extrapolation example and mention different behavior of kwargs in interp (#3956)
* Add note for different behavior of kwargs in 1-d and n-d interpolation * Add multi-dimensional extrapolation example * Update whats-new.rst
1 parent 2c92f69 commit 6a6f2c8

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

doc/interpolation.rst

+7-1
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,14 @@ Additional keyword arguments can be passed to scipy's functions.
150150
151151
# fill 0 for the outside of the original coordinates.
152152
da.interp(x=np.linspace(-0.5, 1.5, 10), kwargs={'fill_value': 0.0})
153-
# extrapolation
153+
# 1-dimensional extrapolation
154154
da.interp(x=np.linspace(-0.5, 1.5, 10), kwargs={'fill_value': 'extrapolate'})
155+
# multi-dimensional extrapolation
156+
da = xr.DataArray(np.sin(0.3 * np.arange(12).reshape(4, 3)),
157+
[('time', np.arange(4)),
158+
('space', [0.1, 0.2, 0.3])])
159+
160+
da.interp(time=4, space=np.linspace(-0.1, 0.5, 10), kwargs={'fill_value': None})
155161
156162
157163
Advanced Interpolation

doc/whats-new.rst

+4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ Documentation
9898
(:pull:`3935`). By `Spencer Clark <https://github.com/spencerkclark>`_.
9999
- Updated the list of current core developers. (:issue:`3892`)
100100
By `Tom Nicholas <https://github.com/TomNicholas>`_.
101+
- Add example for multi-dimensional extrapolation and note different behavior
102+
of ``kwargs`` in :py:meth:`Dataset.interp` and :py:meth:`DataArray.interp`
103+
for 1-d and n-d interpolation (:pull:`3956`).
104+
By `Matthias Riße <https://github.com/risebell>`_.
101105

102106
Internal Changes
103107
~~~~~~~~~~~~~~~~

xarray/core/dataarray.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,9 @@ def interp(
13661366
first. If True, x has to be an array of monotonically increasing
13671367
values.
13681368
kwargs: dictionary
1369-
Additional keyword passed to scipy's interpolator.
1369+
Additional keyword arguments passed to scipy's interpolator. Valid
1370+
options and their behavior depend on if 1-dimensional or
1371+
multi-dimensional interpolation is used.
13701372
``**coords_kwargs`` : {dim: coordinate, ...}, optional
13711373
The keyword arguments form of ``coords``.
13721374
One of coords or coords_kwargs must be provided.

xarray/core/dataset.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2570,7 +2570,9 @@ def interp(
25702570
coordinates are assumed to be an array of monotonically increasing
25712571
values.
25722572
kwargs: dictionary, optional
2573-
Additional keyword passed to scipy's interpolator.
2573+
Additional keyword arguments passed to scipy's interpolator. Valid
2574+
options and their behavior depend on if 1-dimensional or
2575+
multi-dimensional interpolation is used.
25742576
**coords_kwargs : {dim: coordinate, ...}, optional
25752577
The keyword arguments form of ``coords``.
25762578
One of coords or coords_kwargs must be provided.

0 commit comments

Comments
 (0)