Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I traverse a hdf5 file using h5py

Tags:

h5py

How do I traverse all the groups and datasets of an hdf5 file using h5py?

I want to retrieve all the contents of the file from a common root using a for loop or something similar.

like image 786
Marcio Avatar asked Jun 30 '15 18:06

Marcio


People also ask

How do I explore HDF5 files?

Open a HDF5/H5 file in HDFView Open this file in HDFView. If you click on the name of the HDF5 file in the left hand window of HDFView, you can view metadata for the file. This will be located in the bottom window of the application.

How do I check my HDF5 data?

View Metadata of an HDF5 Object To view the metadata of a data object, Right click on the object and then select 'Show Properties'. A window will open and display metadata information such as name, type, attributes, data type, and data space.

How do I open an hd5 file in Python?

To use HDF5, numpy needs to be imported. One important feature is that it can attach metaset to every data in the file thus provides powerful searching and accessing. Let's get started with installing HDF5 to the computer. As HDF5 works on numpy, we would need numpy installed in our machine too.


1 Answers

visit() and visititems() are your friends here. Cf. http://docs.h5py.org/en/latest/high/group.html#Group.visit. Note that an h5py.File is also an h5py.Group. Example (not tested):

def visitor_func(name, node):
    if isinstance(node, h5py.Dataset):
         # node is a dataset
    else:
         # node is a group

with h5py.File('myfile.h5', 'r') as f:
    f.visititems(visitor_func)
like image 175
weatherfrog Avatar answered Sep 22 '22 14:09

weatherfrog