访问Xarray DataSet时出现HDF5警告。

12
我希望了解以下情况下引起警告信息的原因:
在先前的操作中,我使用`xarray.to_netcdf()`创建了一些NetCDF文件并将它们保存到磁盘上。
在jupyter notebook中懒加载这些数据集是完全没有问题的,且出现以下情况时我不会收到警告/错误消息:
通过`ds = xarray.open_mfdataset('/path/to/files/*.nc')`打开这些`.nc`文件
通过`ds.time.values`将维度数据加载到内存中
通过`ds.sel(time=starttime)`进行惰性选择
我似乎能够做到我想要的关于计算记忆数据的所有操作。但是,当出现以下情况时,我经常会收到相同的一组错误:
通过`ds.sel(time=starttime).SCALAR_DATA.plot()`加载用于绘图的数据
通过`ts = pd.Series(ds.SCALAR_DATA.loc[:,y,x], index=other_data.index)`提取/加载数据
请注意,尽管出现这些警告,但我执行的操作确实导致所期望的结果(图形、时间序列结构等)。
生成以下错误的共同点似乎是从已打开的数据集中加载数据。编辑后:经过进一步的实验,我的工作环境中软件包的版本可能会导致某些依赖于HDF5的任务之间发生冲突。
以下错误会重复出现若干次。
HDF5-DIAG: Error detected in HDF5 (1.12.2) thread 1:
  #000: H5A.c line 528 in H5Aopen_by_name(): can't open attribute
    major: Attribute
    minor: Can't open object
  #001: H5VLcallback.c line 1091 in H5VL_attr_open(): attribute open failed
    major: Virtual Object Layer
    minor: Can't open object
  #002: H5VLcallback.c line 1058 in H5VL__attr_open(): attribute open failed
    major: Virtual Object Layer
    minor: Can't open object
  #003: H5VLnative_attr.c line 130 in H5VL__native_attr_open(): can't open attribute
    major: Attribute
    minor: Can't open object
  #004: H5Aint.c line 545 in H5A__open_by_name(): unable to load attribute info from object header
    major: Attribute
    minor: Unable to initialize object
  #005: H5Oattribute.c line 494 in H5O__attr_open_by_name(): can't locate attribute: '_QuantizeBitGroomNumberOfSignificantDigits'
    major: Attribute
    minor: Object not found

...

HDF5-DIAG: Error detected in HDF5 (1.12.2) thread 2:
  #000: H5A.c line 528 in H5Aopen_by_name(): can't open attribute
    major: Attribute
    minor: Can't open object
  #001: H5VLcallback.c line 1091 in H5VL_attr_open(): attribute open failed
    major: Virtual Object Layer
    minor: Can't open object
  #002: H5VLcallback.c line 1058 in H5VL__attr_open(): attribute open failed
    major: Virtual Object Layer
    minor: Can't open object
  #003: H5VLnative_attr.c line 130 in H5VL__native_attr_open(): can't open attribute
    major: Attribute
    minor: Can't open object
  #004: H5Aint.c line 545 in H5A__open_by_name(): unable to load attribute info from object header
    major: Attribute
    minor: Unable to initialize object
  #005: H5Oattribute.c line 476 in H5O__attr_open_by_name(): can't open attribute
    major: Attribute
    minor: Can't open object
  #006: H5Adense.c line 394 in H5A__dense_open(): can't locate attribute in name index
    major: Attribute
    minor: Object not found


任何对可能导致这些问题的建议将不胜感激。

好问题,这些可能是异常情况,但肯定会不经提示地出现,没有记录器或其他请求被发出。虽然我理解最小重现示例的价值,但我开始认为在我的工作环境中,HDF5及其依赖项之间可能存在一些软件包版本兼容性问题。 - jpolly
当让conda解决环境中所有软件包的依赖关系后,警告信息消失了。以前,我手动在环境中安装大多数软件包(如xarray、netcdf4、rioxarray等)。这种方法导致了上述错误。我不知道这是否构成了对问题的“答案”,但是使用conda安装这些软件包已经解决了问题,没有警告信息出现。 - jpolly
是的,这正是我想建议的。请注意,一次性安装它们意味着它们优先从兼容的渠道和版本中选择,因此conda确保您在软件包之间具有一致的编译器标志和版本。 - Michael Delgado
各位有关于这个问题的任何更新吗?我也遇到了同样的问题,代码可以正常运行,但是出现了很多这样的消息。我已经在CentOS 7.9上通过PiP单独安装了所有地理包库(C,C ++,NC,HDF4,HDF5 ...),以及Python 3.9。谢谢。 - PDash
1
如果您的环境中存在冲突的通道,或者在基本环境中存在冲突的通道(例如使用anaconda安装),即使使用conda也可能会出现此问题。请参阅此问题(jpolly的答案中也有链接):HDF5 error when opening NC files in python with xarray - Michael Delgado
显示剩余2条评论
3个回答

8

5

我最近几天一直在遇到类似的错误,最终发现限制我的dask客户端每个工作线程只使用1个线程可以解决这个问题,即:

import xrarray as xr
from dask.distributed import Client
c = Client(n_workers=os.cpu_count()-2, threads_per_worker=1)

ds = xr.open_mfdataset('/path/to/files/*.nc')
ds.sel(.... )

如果jpolly的解决方案对你没有用(在我的情况下,我没有使用conda...),那么这个方法可能值得一试。

2
conda解决各个软件包之间的依赖关系,最终成为了解决这些警告的方法。当我手动安装各种软件包时,没有仔细指定版本或让conda解决依赖关系时,警告仍然存在。编辑:在此答案中有一个很好的解释。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接