Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

These libraries can be easily imported somewhere around in the header top of the Python file, for example

...

Detailed desciption of the HDF5 file structure can be found in HDF5 or h5py
web sites. Breifly speaking, its structure resembles the file system directory tree. The top level of the HDF5 tree is a file;
file may contain groups and datasets; each group may contain other groups and datasets; each dataset contains the data objects, which in most cases can be associated with numpy types.
So, there are three type of items in HDF5 file: File, Group, and Dataset. Their names are used as an access keys.

...

Basic operations allows to access the dataset records from HDF5.
Here we assume that user knows explicitly the names of file and dataset and event number, for example

...

As in previous case we assume that all necessary parameters are defined,

Code Block
    file = h5py.File(hdf5_file_name, 'r')
    dsitem   = file[datasetitem_name]

where item stands for file, group of dataset.

Check if the HDF5 item is "File", "Group", or "Data"

Code Block
isFile    = isinstance(item, h5py.File)
isGroup   = isinstance(item, h5py.Group)
isDataset = isinstance(item, h5py.Dataset)

This In this example the standard Python method isinstance(...)}}returns {{True or False in each case, respectively.

...

  • For all HDF5 items:
    these parameters are available:
    Code Block
    dsitem.id      # for example: <GroupID [1] (U) 33554473>
    dsitem.ref     # for example: <HDF5 object reference>
    dsitem.parent  # for example: <HDF5 group "/Configure:0000/Run:0000/CalibCycle:0000" (5 members)>
    dsitem.file    # for example: <HDF5 file "cxi80410-r0587.h5" (mode r, 3.5G)>
    dsitem.name    # for example: /Configure:0000/Run:0000/CalibCycle:0000/Camera::FrameV1
    
  • Dataset
    Code Block
    ds.dtype     # for example: ('seconds', '<u4'), ('nanoseconds', '<u4')]
    ds.shape     # for example: (1186,)
    ds.value     # for example: (1297610252L, 482193420L)
    
  • Get item attributes for File or Group (if attributes available)
    In this example the item might be a group or file
    Code Block
    item.attrs          # for example: <Attributes of HDF5 object    #group or file
    dict_attributes    = group.attrs
    attrs_keys         = groupat 230141696>
    item.attrs.keys()
    attrs_values   # for example:  = group['start.seconds', 'start.nanoseconds']
    item.attrs.values()
    number_of_attrs # for example: = [1297608424L, 627075857L]
    len(groupitem.attrs)
    
    # For example, one of the file attributes is a run number:
    run_number         = file.attrs['runNumber']
    
  • Get group name and the list of daughters in the group
    Code Block
    list_of_item_names = group.items()
    print list_of_item_names
    
    or
    Code Block
    for key,val in dict(group).iteritems():
        print key, val
    

...

Time variable is stored in HDF5 as a tuple of two long integer numbers representing the seconds since 01/01/1970 and nanoseconds as a fraction of the second. Time can be is usually stored in the group attributes and/or in the data record with name "time", which can be extracted as shown below

...