How do I move an hdf5 file using h5py

How can I navigate all groups and datasets of an hdf5 file using h5py?

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

+5
source share
2 answers

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

 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) 
+8
source

Well, this is a kind of old thread, but I thought I would do my part. This is what I did in a similar situation. For a data structure created as follows:

 [group1] [group2] dataset1 dataset2 [group3] dataset3 dataset4 

I used:

 datalist = [] def returnname(name): if 'dataset' in name and name not in datalist: return name else: return None looper = 1 while looper == 1: name = f[group1].visit(returnname) if name == None: looper = 0 continue datalist.append(name) 

I did not find the h5py equivalent for os.walk.

0
source

All Articles