将 xarray 的内置 interp 函数与 dask 一起使用时出错

Error when using xarray's built in interp function with dask

我正在尝试将 xarray 的 interp 函数与 chunk 函数一起使用,这是一个 dask 数组功能。

http://xarray.pydata.org/en/stable/interpolation.html 'Example' 下的示例为例,我可以很好地使用 interp 函数。我用来执行此操作的简化代码是:

at = xr.tutorial.open_dataset('air_temperature').isel(time=0)

x = np.linspace(240, 300, 100)
z = np.linspace(20, 70, 100)
lat = xr.DataArray(z, dims=['z'], coords={'z': z})
lon = xr.DataArray((x[:, np.newaxis]-270)/np.cos(z*np.pi/180)+270,
                    dims=['x', 'z'], coords={'x': x, 'z': z})

dsi = at.interp(lon=lon, lat=lat)

当我尝试通过以下方式修改上面的代码来将此 interp 函数与 xarray 块组合时,问题出现了:

at = xr.tutorial.open_dataset('air_temperature').isel(time=0)
at = at.chunk({'lat':10})        # added chunking inducing a dask array

x = np.linspace(240, 300, 100)
z = np.linspace(20, 70, 100)
lat = xr.DataArray(z, dims=['z'], coords={'z': z})
lon = xr.DataArray((x[:, np.newaxis]-270)/np.cos(z*np.pi/180)+270,
                    dims=['x', 'z'], coords={'x': x, 'z': z})

dsi = at.interp(lon=lon, lat=lat)

代码在第

行失败
dsi = at.interp(lon=lon, lat=lat)

我得到的错误是:

ValueError: 无法同时指定 drop_axis 和 new_axis

我认为正在发生的事情是 interp 函数正在替换坐标,而 dask 无法处理这个问题。这是一个需要在 xarray 中修复的错误还是我做错了什么?

此问题现已解决。事实证明,问题是由使用过时版本的 dask (0.13) 引起的。通过更新到 dask 版本 0.24.0,上述错误不再发生。

请参阅 github 线程以获取更多说明:

https://github.com/pydata/xarray/issues/3342