如何使用python合并多个hdf5文件?

时间:2017-02-15 10:02:19

标签: python merge hdf5

我有几个hdf5文件,每个文件都有一个数据集。我想将它们全部合并到一个新的hdf5文件(all_data.h5)中,并将每个数据集分成新的hdf5文件。

例如:

a.h5 has "a_data" dataset and b.h5 has "b_data" dataset.

我想将这两个h5文件合并到新的h5文件(all_data.h5)中。换句话说,

all_data.h5 has "a_data" dataset and "b_data" dataset

我不想将数据集连接成单个数据集。

我找到了一个相关问题,但对如何执行它们并不是很了解:Combining hdf5 files

我想在那里添加评论,但由于我的声誉不够,所以我决定开一个新主题。

我甚至尝试了使用ipython和h5copy的问题解决方案之一,但在此行之后返回错误

import h5py
import os

d_names = os.listdir(os.getcwd())
d_struct = {}

for i in d_names:
    f = h5py.File(i, 'r+')
    d_struct[i] = f.keys()
    f.close() #an error occurred after this line

错误是

---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)
<ipython-input-5-1a819956017b> in <module>()
      1 for i in d_names:
----> 2     f = h5py.File(i,'r+')
      3     d_struct[i] = f.keys()
      4     f.close()
      5

/Users/Fang/workspace/my_project/the_data/all_data/venv/lib/python2.7/site-packages/h5py/_hl/files.pyc in __init__(self, name, mode, driver, libver, userblock_size, swmr, **kwds)
    270
    271                 fapl = make_fapl(driver, libver, **kwds)
--> 272                 fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
    273
    274                 if swmr_support:

/Users/Fang/workspace/my_project/the_data/all_data/venv/lib/python2.7/site-packages/h5py/_hl/files.pyc in make_fid(name, mode, userblock_size, fapl, fcpl, swmr)
     92         fid = h5f.open(name, flags, fapl=fapl)
     93     elif mode == 'r+':
---> 94         fid = h5f.open(name, h5f.ACC_RDWR, fapl=fapl)
     95     elif mode in ['w-', 'x']:
     96         fid = h5f.create(name, h5f.ACC_EXCL, fapl=fapl, fcpl=fcpl)

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/Users/travis/build/MacPython/h5py-wheels/h5py/h5py/_objects.c:2687)()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/Users/travis/build/MacPython/h5py-wheels/h5py/h5py/_objects.c:2645)()

h5py/h5f.pyx in h5py.h5f.open (/Users/travis/build/MacPython/h5py-wheels/h5py/h5py/h5f.c:1933)()

IOError: Unable to open file (File signature not found)

我没有尝试解决方案中提供的整个脚本。

感谢您的帮助。

0 个答案:

没有答案