我有两个(更多)netCDF文件,我想使用xarray中的open_mfdataset
函数动态连接。如果我使用open_dataset
单独打开它们,打印的结构如下:
Dimensions: (lat: 103, lon: 241, time: 365)
Coordinates:
* lon (lon) float64 5.75 5.771 5.792 5.812 5.833 5.854 5.875 5.896 ...
* lat (lat) float64 45.75 45.77 45.79 45.81 45.83 45.85 45.88 45.9 ...
* time (time) datetime64[ns] 2014-01-01 2014-01-02 2014-01-03 ...
Data variables:
TabsD (time, lat, lon) float64 nan nan nan nan nan nan nan nan nan ...
表示第一个文件,
Dimensions: (lat: 103, lon: 241, time: 31)
Coordinates:
* lon (lon) float64 5.75 5.771 5.792 5.812 5.833 5.854 5.875 5.896 ...
* lat (lat) float64 45.75 45.77 45.79 45.81 45.83 45.85 45.87 45.9 ...
* time (time) datetime64[ns] 2015-01-01 2015-01-02 2015-01-03 ...
Data variables:
TabsD (time, lat, lon) float64 nan nan nan nan nan nan nan nan nan ...
第二个。现在的问题是,当我将文件名放在flist
并执行data = xr.open_mfdataset(flist, concat_dim='time', cache=False)
时,我得到了这个错误回溯:
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.3.2\helpers\pydev\pydevd.py", line 1591, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.3.2\helpers\pydev\pydevd.py", line 1018, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.3.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/*/Documents/myfile.py", line 110, in <module>
data = xr.open_mfdataset(flist, concat_dim='time', cache=False)
File "C:\Program Files\Anaconda3\lib\site-packages\xarray\backends\api.py", line 514, in open_mfdataset
combined = auto_combine(datasets, concat_dim=concat_dim, compat=compat)
File "C:\Program Files\Anaconda3\lib\site-packages\xarray\core\combine.py", line 396, in auto_combine
concatenated = [_auto_concat(ds, dim=dim) for ds in grouped]
File "C:\Program Files\Anaconda3\lib\site-packages\xarray\core\combine.py", line 396, in <listcomp>
concatenated = [_auto_concat(ds, dim=dim) for ds in grouped]
File "C:\Program Files\Anaconda3\lib\site-packages\xarray\core\combine.py", line 332, in _auto_concat
return concat(datasets, dim=dim)
File "C:\Program Files\Anaconda3\lib\site-packages\xarray\core\combine.py", line 120, in concat
return f(objs, dim, data_vars, coords, compat, positions)
File "C:\Program Files\Anaconda3\lib\site-packages\xarray\core\combine.py", line 273, in _dataset_concat
combined = concat_vars(vars, dim, positions)
File "C:\Program Files\Anaconda3\lib\site-packages\xarray\core\variable.py", line 1442, in concat
return Variable.concat(variables, dim, positions, shortcut)
File "C:\Program Files\Anaconda3\lib\site-packages\xarray\core\variable.py", line 998, in concat
data = duck_array_ops.concatenate(arrays, axis=axis)
File "C:\Program Files\Anaconda3\lib\site-packages\xarray\core\duck_array_ops.py", line 48, in f
return getattr(module, name)(*args, **kwargs)
File "C:\Program Files\Anaconda3\lib\site-packages\dask\array\core.py", line 1871, in concatenate
raise ValueError("Block shapes do not align")
ValueError: Block shapes do not align
我已经尝试过了:
chunks={'time':10}
(30,40,100等...)chunks={'lat':10, 'lon':10}
基本相同的结果。
这里的诀窍是什么?
答案 0 :(得分:0)
你所描述的行为不应该发生。
我的猜测是,您的某些文件实际上具有不同的维度大小,但是您从dask获得了无法提供信息的错误消息。
您所描述的错误消息不再出现在最新版本的dask中,因此也可能已修复此行为。请更新到xarray / dask的最新版本,然后重试。