Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi-dimensional extrapolation example and mention different behavior of kwargs in interp #3956

Merged
merged 3 commits into from
Apr 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion doc/interpolation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,14 @@ Additional keyword arguments can be passed to scipy's functions.

# fill 0 for the outside of the original coordinates.
da.interp(x=np.linspace(-0.5, 1.5, 10), kwargs={'fill_value': 0.0})
# extrapolation
# 1-dimensional extrapolation
da.interp(x=np.linspace(-0.5, 1.5, 10), kwargs={'fill_value': 'extrapolate'})
# multi-dimensional extrapolation
da = xr.DataArray(np.sin(0.3 * np.arange(12).reshape(4, 3)),
[('time', np.arange(4)),
('space', [0.1, 0.2, 0.3])])

da.interp(time=4, space=np.linspace(-0.1, 0.5, 10), kwargs={'fill_value': None})


Advanced Interpolation
Expand Down
4 changes: 4 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ Documentation
(:pull:`3935`). By `Spencer Clark <https://github.com/spencerkclark>`_.
- Updated the list of current core developers. (:issue:`3892`)
By `Tom Nicholas <https://github.com/TomNicholas>`_.
- Add example for multi-dimensional extrapolation and note different behavior
of ``kwargs`` in :py:meth:`Dataset.interp` and :py:meth:`DataArray.interp`
for 1-d and n-d interpolation (:pull:`3956`).
By `Matthias Riße <https://github.com/risebell>`_.

Internal Changes
~~~~~~~~~~~~~~~~
Expand Down
4 changes: 3 additions & 1 deletion xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,9 @@ def interp(
first. If True, x has to be an array of monotonically increasing
values.
kwargs: dictionary
Additional keyword passed to scipy's interpolator.
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.
Expand Down
4 changes: 3 additions & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2570,7 +2570,9 @@ def interp(
coordinates are assumed to be an array of monotonically increasing
values.
kwargs: dictionary, optional
Additional keyword passed to scipy's interpolator.
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.
Expand Down