3

我正在尝试组合多个具有相同尺寸的 netCDF 文件,它们的尺寸如下:

OrderedDict([(u'lat', <type 'netCDF4._netCDF4.Dimension'>: name = 'lat', size = 720
), (u'lon', <type 'netCDF4._netCDF4.Dimension'>: name = 'lon', size = 1440
), (u'time', <type 'netCDF4._netCDF4.Dimension'>: name = 'time', size = 96
), (u'nv', <type 'netCDF4._netCDF4.Dimension'>: name = 'nv', size = 2
)])
OrderedDict([(u'lat', <type 'netCDF4._netCDF4.Dimension'>: name = 'lat', size = 720
), (u'lon', <type 'netCDF4._netCDF4.Dimension'>: name = 'lon', size = 1440
), (u'time', <type 'netCDF4._netCDF4.Dimension'>: name = 'time', size = 96
), (u'nv', <type 'netCDF4._netCDF4.Dimension'>: name = 'nv', size = 2
)])
OrderedDict([(u'lat', <type 'netCDF4._netCDF4.Dimension'>: name = 'lat', size = 720
), (u'lon', <type 'netCDF4._netCDF4.Dimension'>: name = 'lon', size = 1440
), (u'time', <type 'netCDF4._netCDF4.Dimension'>: name = 'time', size = 96
), (u'nv', <type 'netCDF4._netCDF4.Dimension'>: name = 'nv', size = 2
)])
OrderedDict([(u'lat', <type 'netCDF4._netCDF4.Dimension'>: name = 'lat', size = 720
), (u'lon', <type 'netCDF4._netCDF4.Dimension'>: name = 'lon', size = 1440
), (u'time', <type 'netCDF4._netCDF4.Dimension'>: name = 'time', size = 96
), (u'nv', <type 'netCDF4._netCDF4.Dimension'>: name = 'nv', size = 2
)])
OrderedDict([(u'lat', <type 'netCDF4._netCDF4.Dimension'>: name = 'lat', size = 720
), (u'lon', <type 'netCDF4._netCDF4.Dimension'>: name = 'lon', size = 1440
), (u'time', <type 'netCDF4._netCDF4.Dimension'>: name = 'time', size = 96
), (u'nv', <type 'netCDF4._netCDF4.Dimension'>: name = 'nv', size = 2
)])
OrderedDict([(u'lat', <type 'netCDF4._netCDF4.Dimension'>: name = 'lat', size = 720
), (u'lon', <type 'netCDF4._netCDF4.Dimension'>: name = 'lon', size = 1440
), (u'time', <type 'netCDF4._netCDF4.Dimension'>: name = 'time', size = 96
), (u'nv', <type 'netCDF4._netCDF4.Dimension'>: name = 'nv', size = 2
)])
OrderedDict([(u'lat', <type 'netCDF4._netCDF4.Dimension'>: name = 'lat', size = 720
), (u'lon', <type 'netCDF4._netCDF4.Dimension'>: name = 'lon', size = 1440
), (u'time', <type 'netCDF4._netCDF4.Dimension'>: name = 'time', size = 96
), (u'nv', <type 'netCDF4._netCDF4.Dimension'>: name = 'nv', size = 2
)])

但是,在使用 open_mfdataset 时,我收到此错误:

xr.open_mfdataset(path_file, decode_times=False)

*** ValueError: cannot infer dimension to concatenate: supply the ``concat_dim`` argument explicitly

如何修复此错误?我的尺寸在所有文件中都相同

4

2 回答 2

3

出现此错误消息可能是因为您有两个具有相同变量和坐标值的文件,并且 xarray 不知道是否应该将它们沿新维度堆叠在一起,或者只是检查以确保没有值冲突。

如果显式调用禁用所有连接尝试会open_mfdataset很好concat_dim=None此更改应使其进入 xarray (v0.9.0) 的下一个版本。

同时,您可以通过单独打开文件并明确合并它们来解决此问题,例如,

def open_mfdataset_merge_only(paths, **kwargs):
    if isinstance(paths, basestring):
        paths = sorted(glob(paths))
    return xr.merge([xr.open_dataset(path, **kwargs) for path in paths])

在幕后,这基本上就是所有open_mfdataset正在做的事情。

于 2016-09-19T01:14:22.357 回答
1

http://xarray.pydata.org/en/stable/generated/xarray.open_mfdataset.html

xarray.open_mfdataset(paths, chunks=None, concat_dim=None, preprocess=None, engine=None, lock=None, **kwargs)

看起来它需要你提供一个concat_dim参数。从您的数据中推断它有问题。

连接文件的维度。此参数与数据集对象一起传递给 xarray.auto_combine()。如果您想要连接的维度不是原始数据集中的维度,您只需要提供此参数,例如,如果您想要沿第三个维度堆叠二维数组的集合。

这些 3d 数组是否要沿新的第四维堆叠?

于 2016-09-18T21:21:28.157 回答