You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Objective

Libraries

  • Python
  • h5py
  • NumPy
  • SciPy
  • MatPlotLib
#!/usr/bin/env python
import h5py
import numpy as np
import scipy as sp
import scipy.ndimage as spi
import matplotlib.pyplot as plt

Basic operations

  • Open file, get dataset, get array for current event, and close file:
    file    = h5py.File(hdf5_file_name, 'r')   # Open hdf5 file in read-only mode
    dataset = file[dataset_name]
    arr1ev  = dataset[event_number]
    file.close()

where we assume that all necessary parameters were defined earlier, for example

    hdf5_file_name = '/reg/d/psdm/XPP/xppcom10/hdf5/xppcom10-r0546.h5'
    dataset_name   = '/Configure:0000/Run:0000/CalibCycle:0000/Camera::FrameV1/XppSb4Pim.1:Tm6740.1/image'
    event_number   = 5

The arr1ev is returned as a NumPy object. There are many methods which allow to manipulate with this object. For example, one can

  • print array shape and content:
    print 'arr1ev.shape =', arr1ev.shape
    print 'arr1ev =\n',     arr1ev

Advanced operations

  • Get item attributes
  • Get group name and the list of daughters
  • Check if the HDF5 item is "File", "Group", or "Data"

Code examples

  • Example 1, basic operations:
#!/usr/bin/env python

import h5py
import numpy as np

eventNumber = 5

file    = h5py.File('/reg/d/psdm/XPP/xppcom10/hdf5/xppcom10-r0546.h5', 'r')
dataset = file['/Configure:0000/Run:0000/CalibCycle:0000/Camera::FrameV1/XppSb4Pim.1:Tm6740.1/image']
arr1ev  = dataset[eventNumber]
file.close()

print 'arr1ev.shape =', arr1ev.shape
print 'arr1ev =\n',     arr1ev
  • Example 2, advanced operations:
Needs to be added
  • No labels