Interpolate with lazy indexes

Hey,

Currently, interpolating using indexes as dask arrays with da.interp is not possible.

import dask.array as da
import xarray as xr
import numpy as np
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.interp(x=[0, 0.75, 1.25, 1.75])  # working
ds.interp(x=da.from_array(np.array([0, 0.75, 1.25, 1.75]))) # not working, raises TypeError

I understand this is a well known feature (Slow initilization of dataset.interp · Issue #4739 · pydata/xarray · GitHub).

However, are there any tricks to circumvent this? Have some of you experienced and solved this?

Calling compute on the indexes before interpolation can be penalizing if indexes are obtained following many computations and a large graph.

Thanks a lot,

Hi @louislt,

Are you sur this is a Dask Array issue? Dask Array does not provide an interp function if I’m not mistaken. I’m wondering if it would not be better for you to open an Xarray issue? Or discussing this in Pangeo discourse forum?

Hi @guillaumeeb,

oh yes this is indeed a xarray issue… Sorry for the mistake, I’ll move the discussion to the appropriate forum. Thanks for your answer!

1 Like