I have a h5py file storing numpy arrays, but I got Object doesn't exist error
when trying to open it with the dataset name I remember, so is there a way I can list what datasets the file has?
with h5py.File('result.h5','r') as hf: #How can I list all dataset I have saved in hf?
Open a HDF5/H5 file in HDFView hdf5 file on your computer. 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.
Within one HDF5 file, you can store a similar set of data organized in the same way that you might organize files and folders on your computer. However in a HDF5 file, what we call "directories" or "folders" on our computers, are called groups and what we call files on our computer are called datasets .
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.
You have to use the keys method. This will give you a List of unicode strings of your dataset and group names. For example:
Datasetnames=hf.keys()
Another gui based method would be to use HDFView. https://support.hdfgroup.org/products/java/release/download.html
The other answers just tell you how to make a list of the keys under the root group, which may refer to other groups or datasets.
If you want something closer to h5dump but in python, you can do something like that:
import h5py def descend_obj(obj,sep='\t'): """ Iterate through groups in a HDF5 file and prints the groups and datasets names and datasets attributes """ if type(obj) in [h5py._hl.group.Group,h5py._hl.files.File]: for key in obj.keys(): print sep,'-',key,':',obj[key] descend_obj(obj[key],sep=sep+'\t') elif type(obj)==h5py._hl.dataset.Dataset: for key in obj.attrs.keys(): print sep+'\t','-',key,':',obj.attrs[key] def h5dump(path,group='/'): """ print HDF5 file metadata group: you can give a specific group, defaults to the root group """ with h5py.File(path,'r') as f: descend_obj(f[group])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With