Skip to content

Commit 4e1be1b

Browse files
author
Louis Stenger
committed
Fix kwargs used for extrapolation in docs
The current version of xarray tries to call scipy's interp1d whenever possible, and kwargs used in the user guide should reflect this. Fixes pydata#6617
1 parent 3b242a1 commit 4e1be1b

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

doc/user-guide/interpolation.rst

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,12 @@ It is now possible to safely compute the difference ``other - interpolated``.
132132
Interpolation methods
133133
---------------------
134134

135-
We use :py:class:`scipy.interpolate.interp1d` for 1-dimensional interpolation and
136-
:py:func:`scipy.interpolate.interpn` for multi-dimensional interpolation.
135+
We use :py:class:`scipy.interpolate.interp1d` for 1-dimensional interpolation.
136+
For multi-dimensional interpolation, an attempt is first made to decompose the
137+
interpolation in a series of 1-dimensional interpolations, in which case
138+
:py:class:`scipy.interpolate.interp1d` is used. If a decomposition cannot be
139+
made (e.g. with advanced interpolation), :py:func:`scipy.interpolate.interpn` is
140+
used.
137141

138142
The interpolation method can be specified by the optional ``method`` argument.
139143

@@ -165,7 +169,7 @@ Additional keyword arguments can be passed to scipy's functions.
165169
[("time", np.arange(4)), ("space", [0.1, 0.2, 0.3])],
166170
)
167171
168-
da.interp(time=4, space=np.linspace(-0.1, 0.5, 10), kwargs={"fill_value": None})
172+
da.interp(time=4, space=np.linspace(-0.1, 0.5, 10), kwargs={"fill_value": "extrapolate"})
169173
170174
171175
Advanced Interpolation
@@ -198,23 +202,26 @@ For example:
198202
y = xr.DataArray([0.1, 0.2, 0.3], dims="z")
199203
da.sel(x=x, y=y)
200204
201-
# advanced interpolation
202-
x = xr.DataArray([0.5, 1.5, 2.5], dims="z")
203-
y = xr.DataArray([0.15, 0.25, 0.35], dims="z")
205+
# advanced interpolation, without extrapolation
206+
x = xr.DataArray([0.5, 1.5, 2.5, 3.5], dims="z")
207+
y = xr.DataArray([0.15, 0.25, 0.35, 0.45], dims="z")
204208
da.interp(x=x, y=y)
205209
206210
where values on the original coordinates
207-
``(x, y) = ((0.5, 0.15), (1.5, 0.25), (2.5, 0.35))`` are obtained by the
208-
2-dimensional interpolation and mapped along a new dimension ``z``.
211+
``(x, y) = ((0.5, 0.15), (1.5, 0.25), (2.5, 0.35), (3.5, 0.45))`` are obtained
212+
by the 2-dimensional interpolation and mapped along a new dimension ``z``. Since
213+
no keyword arguments are passed to the interpolation routine, no extrapolation
214+
is performed resulting in a ``nan`` value.
209215

210216
If you want to add a coordinate to the new dimension ``z``, you can supply
211-
:py:class:`~xarray.DataArray` s with a coordinate,
217+
:py:class:`~xarray.DataArray` s with a coordinate. Extrapolation can be achieved
218+
by passing additional arguments to SciPy's ``interpnd`` function,
212219

213220
.. ipython:: python
214221
215-
x = xr.DataArray([0.5, 1.5, 2.5], dims="z", coords={"z": ["a", "b", "c"]})
216-
y = xr.DataArray([0.15, 0.25, 0.35], dims="z", coords={"z": ["a", "b", "c"]})
217-
da.interp(x=x, y=y)
222+
x = xr.DataArray([0.5, 1.5, 2.5, 3.5], dims="z", coords={"z": ["a", "b", "c", "d"]})
223+
y = xr.DataArray([0.15, 0.25, 0.35, 0.45], dims="z", coords={"z": ["a", "b", "c", "d"]})
224+
da.interp(x=x, y=y, kwargs={"fill_value": None})
218225
219226
For the details of the advanced indexing,
220227
see :ref:`more advanced indexing <more_advanced_indexing>`.

0 commit comments

Comments
 (0)