python - 尝试将 xarray 写入 netcdf 时出现 "ValueError: chunksize cannot exceed dimension size"

标签 python python-xarray netcdf4

尝试将 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")

所以基本上,我只是操纵内容并重写。然而, block 似乎很糟糕。与重新分块到一个数组相同。我也无法重写 ds。 知道如何追踪错误或解决这个问题吗?

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

最佳答案

这是写入命令中引擎的问题。 如果您使用 block ,您需要将引擎从 netcdf4(默认)更改为 scipy!

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

netcdf4 软件包无法写入此类文件。

关于python - 尝试将 xarray 写入 netcdf 时出现 "ValueError: chunksize cannot exceed dimension size",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39900011/

相关文章:

函数的 Python 'self'

python - Flask,将表单中的数据保存到json文件

python - 我想生成连续的日期

python - 用多个空格分割的复杂字符串

python - 在 python 中使用 xarray 重命名 netcdf 全局属性

hdf5 -\[错误-101\] NetCDF : HDF error when opening netcdf file

python - 了解 xarray groupby

python - 从 Xarray 中的 `xr.Dataset` 获取值(点、向量、数组等)? ( python 3)

r - 使用 r 中的栅格包聚合季节性方法

python - Python 找不到 netCDF4 导入