I am wondering if there is a simple way to check if a node exists within an HDF5 file using h5py.
I couldn't find anything in the docs, so right now I'm using exceptions, which is ugly.
# check if node exists # first assume it exists e = True try: h5File["/some/path"] except KeyError: e = False # now we know it doesn't
To add context: I'm using this to determine if a node exists before trying to create a new node with the same name.
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.
An HDF5 file is a container for two kinds of objects: datasets , which are array-like collections of data, and groups , which are folder-like containers that hold datasets and other groups. The most fundamental thing to remember when using h5py is: Groups work like dictionaries, and datasets work like NumPy arrays.
All strings in HDF5 hold encoded text.You can't store arbitrary binary data in HDF5 strings. Not only will this break, it will break in odd, hard-to-discover ways that will leave you confused and cursing.
Creating HDF5 filesThe first step to creating a HDF5 file is to initialise it. It uses a very similar syntax to initialising a typical text file in numpy. The first argument provides the filename and location, the second the mode. We're writing the file, so we provide a w for write access.
e = "/some/path" in h5File
does it. This is very briefly mentioned in the Group
documentation.
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