Lil*_*ina 6 python linux hdf5 h5py anaconda
我以前从未使用过 HDF5 文件,为了开始使用,我收到了一些示例文件。我一直在检查所有基础知识h5py,查看这些文件中的不同组、它们的名称、键、值等。一切正常,直到我想查看组中保存的数据集。我得到了他们的.shape和.dtype,但是当我尝试通过索引访问随机值(例如grp["dset"][0])时,出现以下错误:
IOError Traceback (most recent call last)
<ipython-input-45-509cebb66565> in <module>()
1 print geno["matrix"].shape
2 print geno["matrix"].dtype
----> 3 geno["matrix"][0]
/home/sarah/anaconda/lib/python2.7/site-packages/h5py/_hl/dataset.pyc in __getitem__(self, args)
443 mspace = h5s.create_simple(mshape)
444 fspace = selection._id
--> 445 self.id.read(mspace, fspace, arr, mtype)
446
447 # Patch up the output for NumPy
/home/sarah/anaconda/lib/python2.7/site-packages/h5py/h5d.so in h5py.h5d.DatasetID.read (h5py/h5d.c:2782)()
/home/sarah/anaconda/lib/python2.7/site-packages/h5py/_proxy.so in h5py._proxy.dset_rw (h5py/_proxy.c:1709)()
/home/sarah/anaconda/lib/python2.7/site-packages/h5py/_proxy.so in h5py._proxy.H5PY_H5Dread (h5py/_proxy.c:1379)()
IOError: Can't read data (Can't open directory)
Run Code Online (Sandbox Code Playgroud)
我已在h5py Google 群组中发布了此问题,其中有人建议我未安装的数据集上可能存在过滤器。但 HDF5 文件是仅使用 gzip 压缩创建的,据我了解,这应该是一个可移植的标准。
有人知道我在这里可能会缺少什么吗?我什至无法在任何地方找到此错误或类似问题的描述,并且可以使用 HDFView 软件轻松打开该文件(包括有问题的数据集)。
编辑
显然,出现此错误是因为由于某种原因,gzip 压缩过滤器在我的系统上不可用。如果我尝试使用 gzip 压缩创建示例文件,则会发生这种情况:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-33-dd7b9e3b6314> in <module>()
1 grp = f.create_group("subgroup")
----> 2 grp_dset = grp.create_dataset("dataset", (50,), dtype="uint8", chunks=True, compression="gzip")
/home/sarah/anaconda/lib/python2.7/site-packages/h5py/_hl/group.pyc in create_dataset(self, name, shape, dtype, data, **kwds)
92 """
93
---> 94 dsid = dataset.make_new_dset(self, shape, dtype, data, **kwds)
95 dset = dataset.Dataset(dsid)
96 if name is not None:
/home/sarah/anaconda/lib/python2.7/site-packages/h5py/_hl/dataset.pyc in make_new_dset(parent, shape, dtype, data, chunks, compression, shuffle, fletcher32, maxshape, compression_opts, fillvalue, scaleoffset, track_times)
97
98 dcpl = filters.generate_dcpl(shape, dtype, chunks, compression, compression_opts,
---> 99 shuffle, fletcher32, maxshape, scaleoffset)
100
101 if fillvalue is not None:
/home/sarah/anaconda/lib/python2.7/site-packages/h5py/_hl/filters.pyc in generate_dcpl(shape, dtype, chunks, compression, compression_opts, shuffle, fletcher32, maxshape, scaleoffset)
101
102 if compression not in encode:
--> 103 raise ValueError('Compression filter "%s" is unavailable' % compression)
104
105 if compression == 'gzip':
ValueError: Compression filter "gzip" is unavailable
Run Code Online (Sandbox Code Playgroud)
有人有这方面的经验吗?HDF5库以及h5py包的安装似乎没有出错......
h5py当找不到打开文件所需的插件时会发生此错误。对于许多常见的插件,可以通过添加以下内容来解决:
import hdf5plugin
Run Code Online (Sandbox Code Playgroud)
在使用 h5py 库之前。您不必hdf5plugin直接使用该库,只需导入它即可。不同的导入可能适合您,具体取决于文件使用的插件 - 如果此错误消息更具描述性,将会很有帮助。