Versions Compared

Key

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

Introduction

Below is a simple building block example of saving data to an hdf5 file while going through events.

...

Code Block
languagepython
import numpy as np
import psana
import h5py

NUM_EVENTS_TO_WRITE=20

ds = psana.DataSource('exp=xppdaq12xpptut15:run=54:smd')

h5out = h5py.File("simple_saved_data_for_xppdaq12_run54_cspad.h5", 'w')
saved = h5out.create_dataset('saved',(0,), dtype='f8', chunks=True, maxshape=(None,))

cspad = psana.Detector('cspad', ds.env())

for idx, evt in enumerate(ds.events()):
    if idx > NUM_EVENTS_TO_WRITE: break
    calib = cspad.calib(evt)
    if (calib is None): continue
    saved.resize((idx+1,))
    saved[idx] = np.sum(calib)

h5out.close()
        

Good tools to inspect an h5 files are h5ls and h5dump. For example, doing:

...