I am using hppy python package (version 2.5.0) to access my hdf5 files.
I want to go through the contents of a file and do something with each data set.
Using the visit method:
import h5py def print_it(name): dset = f[name] print(dset) print(type(dset)) with h5py.File('test.hdf5', 'r') as f: f.visit(print_it)
for the test file, I get:
<HDF5 group "/x" (1 members)> <class 'h5py._hl.group.Group'> <HDF5 dataset "y": shape (100, 100, 100), type "<f8"> <class 'h5py._hl.dataset.Dataset'>
which tells me that the file has a data set and a group. However, there is no obvious way other than using type() to distinguish between data sets and groups. The h5py documentation, unfortunately, says nothing about this topic. They always assume that you know in advance what groups are and what data arrays, for example, because they created the data sets themselves.
I would like to have something like:
f = h5py.File(..) for key in f.keys(): x = f[key] print(x.is_group(), x.is_dataset())
How can I distinguish between groups and datasets while reading an unknown hdf5 file in Python with h5py? How can I get a list of all datasets, all groups, all links?
python hdf5 h5py
Trilarion Dec 17 '15 at 8:53 2015-12-17 08:53
source share