<HDF5 dataset "name": shape (), type "|f8"> in python

>>>fSM = h5py.File(filenames, 'r')
<KeysViewHDF5 [Frequency', 'cycle']>

<HDF5 dataset "baseFrequency": shape (), type "<f8">


<HDF5 dataset "baseFrequency": shape (), type "|f8">, what is the meaning about 'shape()'? blank? And, how to get some values of specific keys, correctly? Thanks!!!

HDF5 using in Python


  • Have you read the h5py documentation? HDF5 uses groups and datasets to organize the data. Groups are like file folders and datasets are the data files.

    • h5py uses dictionary syntax with group objects. So, keys() gives the names of the objects in group.
    • h5py uses NumPy array syntax with dataset objects. So, shape is the shape of the dataset.

    This is what your code does:

    • fSM.keys() prints the root level objects (which could be groups or datasets).
    • fSM['Frequency'] prints the 'Frequency' object attributes. It is a dataset of float values. However, based on shape (), it has an undefined shape (and no data values). It's strange (to me) that it prints the dataset name as "baseFrequency" when it is named 'Frequency'. That will take some diagnosis (assuming it's not a typo in your post.
    • fSM['acquisition']['drivefield']['baseFrequency']._is_empty references a dataset named 'baseFrequency' that is in group 'drivefield' that is a group under the 'acquisition' group. ._is_empty checks to see if it is empty. The False value indicates it is not empty.
    • One last point: The output of the 1st line is NOT consistent with the last line. The first line only shows objects named 'Frequency' and 'cycle' and the last line references a root level group named 'acquisition'. I suspect there are code segments missing from your post. OR, you are mixing output from multiple files.

    Before you start coding you need to understand the file schema (groups and datasets). The easist way to do that (for a new user) is to open the file with the HDFView utility from The HDF Group. That way you can "see" the file structure. Otherwise you need to write some code to inspect the schema.