"ValueError: chunksize cannot exceed dimension size" when trying to write xarray to netcdf

"ValueError: chunksize cannot exceed dimension size" when trying to write xarray to netcdf

尝试将 xarray 对象写入 netcdf 文件时出现以下错误:

"ValueError: chunksize cannot exceed dimension size"  

数据对我的内存来说太大了,需要分块。
套路基本如下:

import xarray as xr  
ds=xr.open_dataset("somefile.nc",chunks={'lat':72,'lon':144}  
myds=ds.copy()
#ds is 335 (time) on 720 on 1440 and has variable var  
def some_function(x):
  return x*2
myds['newvar']=xr.DataArray(np.apply_along_axis(some_function,0,ds['var']))  
myds.drop('var')  
myds.to_netcdf("somenewfile.nc")

所以基本上,我只是操纵内容并重写。然而,块似乎是坏的。与重新分块到一个阵列相同。我也不能重写 ds。 知道如何追踪错误或解决这个问题吗?

netCDF4 版本为 1.2.4
xarray(以前的 xray)版本是 0.8.2
dask 版本是 0.10.1

写指令引擎的问题。 如果您使用块,则需要将引擎从 netcdf4(默认)更改为 scipy!

myds.to_netcdf("somenewfile.nc",engine='scipy')

netcdf4 包无法写入此类文件。