Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if node exists in h5py

Tags:

python

h5py

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.

like image 249
troy.unrau Avatar asked Aug 01 '12 06:08

troy.unrau


People also ask

How do I view HDF5?

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.

What is h5py file in Python?

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.

Can HDF5 store strings?

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.

How do I create a h5py file?

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.


1 Answers

e = "/some/path" in h5File 

does it. This is very briefly mentioned in the Group documentation.

like image 188
Danica Avatar answered Sep 23 '22 16:09

Danica