Recently I have started working with .hdf5
files and still can't figure out how to properly use external links.
I have got a few .hdf5
files. Each file has got the same structure e.g. same keys and data types. I want to merge them into one file but keep them separate with a different key for each file.
Here's what I do:
myfile = h5py.File("/path_to_the_directory/merged_images.hdf5", 'w')
myfile['0.000'] = h5py.ExternalLink("img_000.hdf5", "/path_to_the_directory/images")
myfile['0.001'] = h5py.ExternalLink("img_001.hdf5", "/path_to_the_directory/images")
myfile.flush()
Then I try to read it with:
myfile = h5py.File("/path_to_the_directory/merged_images.hdf5", 'r')
keys = list(myfile.keys())
print(keys)
print(list(myfile[keys[0]]))
The line print(keys)
gives me ['0.000', '0.001']
. So, I believe the file's structure is okay.
And the next lines gives me an exception:
KeyError: "Unable to open object (unable to open external file, external link file name = 'img_000.hdf5')"
Am I doing something wrong? The documentation is pretty poor and I haven t found a relevant use-case there.