Skip to content
Open
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
19 changes: 19 additions & 0 deletions doc/user-guide/interpolation.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,25 @@ filled.interp(x=[0.5, 1.5, 2.5], method="cubic")
For the details of {py:meth}`~xarray.DataArray.interpolate_na`,
see {ref}`Missing values <missing_values>`.

(interp.dask)=

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the docstring is the right place for this level of detail.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sooo... You want me to just move it over or leave it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer moving it over but up to you


## Interpolating Dask arrays

{py:meth}`~xarray.DataArray.interp` works lazily on {ref}`Dask arrays <dask>`.
Each task needs the full extent of the dimensions being interpolated along,
so the chunks along these dimensions are merged into a single chunk.

With `method="linear"` or `"nearest"`, the data is first subset to the range
of the new coordinates, so only the chunks that are needed are read. This
requires the new coordinates to be in memory: if they are chunked, xarray does
not compute them in advance, so all chunks along the interpolated dimensions
are read and merged. If the new coordinates are cheap to compute, loading them
first can reduce the memory use considerably:

```python
da.interp(x=new_x.compute())
```

## Example

Let's see how {py:meth}`~xarray.DataArray.interp` works on real data.
Expand Down
5 changes: 5 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ Bug Fixes

Documentation
~~~~~~~~~~~~~
- Document how :py:meth:`Dataset.interp` and :py:meth:`DataArray.interp` handle
chunks of Dask arrays, and that loading chunked new coordinates first can
reduce the memory use for ``method="linear"`` and ``"nearest"``
(:pull:`11786`).
By `Michael Niklas <https://github.com/headtr1ck>`_.
- Add hidden intersphinx inventory entries for methods, properties and
attributes at the path where they are defined, e.g.
``xarray.core.dataarray.DataArray.sel``. This lets tools such as
Expand Down
6 changes: 6 additions & 0 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2436,6 +2436,12 @@ def interp(
- When interpolating along multiple dimensions with methods `linear` and `nearest`,
the process attempts to decompose the interpolation into independent interpolations
along one dimension at a time.
- For Dask arrays, the chunks along the interpolated dimensions are merged
into a single chunk. With methods `linear` and `nearest`, the data is
first subset to the range of the new coordinates, so only the chunks that
are needed are read. This only happens if the new coordinates are in
memory, so load chunked new coordinates first (e.g. with ``.compute()``)
if they are cheap to compute. See :ref:`interp.dask`.
- The specific interpolation method and dimensionality determine which
interpolant is used:

Expand Down
6 changes: 6 additions & 0 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3902,6 +3902,12 @@ def interp(
- When interpolating along multiple dimensions with methods `linear` and `nearest`,
the process attempts to decompose the interpolation into independent interpolations
along one dimension at a time.
- For Dask arrays, the chunks along the interpolated dimensions are merged
into a single chunk. With methods `linear` and `nearest`, the data is
first subset to the range of the new coordinates, so only the chunks that
are needed are read. This only happens if the new coordinates are in
memory, so load chunked new coordinates first (e.g. with ``.compute()``)
if they are cheap to compute. See :ref:`interp.dask`.
- The specific interpolation method and dimensionality determine which
interpolant is used:

Expand Down
Loading