Versions Compared

Key

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

...

We do not assume we know the size of the image array returned by the Detector image function, thus we do not create the dataset to hold the cspad projections until the first projection is formed.

For the large cspad data, we use horizontal projection, we create the chunksize after seeing the first image we will project. We target a chunk size of 12. Given the dimensions of the 16MB, but cap the number of horizontal projections in a chunk at 2048. Since the horizontal projection is small, we end up with a chunksize of 2048. When saving full images, you may find that targeting a 16MB chunk may put to few images in a chunk. In that case targeting larger chunk sizes, say 100MB, may be more optimal. 

In addition, we demonstrate how to compress the horizontal projection dataset. In addition, we demonstrate how to compress the horizontal projection dataset. Note - compressing significantly slows down saving the data.

Code Block
languagepython
import numpy as np
import math
import psana
import h5py

LASER_ON_EVR_CODE = 92 
NUM_EVENTS_TO_WRITE=20

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

h5out = h5py.File("saved_data_for_xppdaq12_run54_cspad.h5", 'w')
eventDataGroup = h5out.create_group('EventData')
evtSecDs 
LASER_ON_EVR_CODE = 92
NUM_EVENTS = 10
 
ds = psana.DataSource('exp=xpptut15:run=54:smd')
 
chunkSizeSmallData = 2048
h5out = h5py.File("saved_data_for_xpptut15_run54_cspad_hproj.h5", 'w')
eventDataGroup = h5out.create_group('EventData')
evtSecDs = eventDataGroup.create_dataset('event_seconds',
  (0,), dtype='i4', chunks=(chunkSizeSmallData,), maxshape=(None,))
evtNanoDs = eventDataGroup.create_dataset('event_nanoseconds',
  (0,), dtype='i4', chunks=(chunkSizeSmallData,), maxshape=(None,))
evtFiducialsDs = eventDataGroup.create_dataset('event_secondsfiducials',
  (0,), dtype='i4', chunks=(chunkSizeSmallData,), maxshape=(None,))
ebeamL3Ds                     = eventDataGroup.create_dataset('ebeam_L3',
  (0,), dtype='i4f4', chunks=True(chunkSizeSmallData,), maxshape=(None,))
evtNanoDslaserOnDs = eventDataGroup.create_dataset('eventlaser_nanosecondson',
                          (0,), dtype='i4i1', chunks=True, maxshape=(NonechunkSizeSmallData,))
ebeamL3Ds, maxshape= eventDataGroup.create_dataset('ebeam_L3',
                          (0,), dtype='f4', chunks=True, maxshape=(None,))
laserOnDs = eventDataGroup.create_dataset('laser_on',
                          (0,), dtype='i1', chunks=True, maxshape=(None,))
cspadHprojDs = None # will create once we see first cspad and know dimensions

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


nextDsIdx = -1
for evt in ds.events():
    eventId = evt.get(psana.EventId)
    evr = evt.get(psana.EvrData.DataV4, psana.Source('evr0'))
    ebeam = evt.get(psana.Bld.BldDataEBeamV7, psana.Source('EBeam'))

    # use new detector xface for cspad image
    cspadImage = cspad.image(evt)

    # check for event that has everything we want to write
    if (eventId is None) or (evr is None) or \
       (ebeam is None) or (cspadImage is None):
(None,))
cspadHprojDs = None # will create once we see first cspad and know dimensions
 
cspad = psana.Detector('cspad', ds.env())
nextDsIdx = -1
for evtIdx, evt in enumerate(ds.events()):
  if evtIdx >= NUM_EVENTS:
    break
  eventId = evt.get(psana.EventId)
  evr = evt.get(psana.EvrData.DataV4, psana.Source('evr0'))
  ebeam = evt.get(psana.Bld.BldDataEBeamV7, psana.Source('EBeam'))
  cspadImage = cspad.image(evt)
 
  # check for event that has everything we want to write
  if (cspadImage is None) or (eventId is None) or \
     (evr is None) or (ebeam is None):
    continue
  hproj = np.sum(cspadImage,0)
  if cspadHprojDs is None:
    mbPerEvent = (len(hproj) * hproj.dtype.itemsize)/float(1<<20)
    targetChunkMb = 16.0
    chunkSize = min(2048, max(1,int(math.floor(targetChunkMb/mbPerEvent))))
    cspadHprojDs = eventDataGroup.create_dataset('cspad_hproj',
                                     continue

    nextDsIdx += 1

    cspadHproj = np.sum(cspadImage, 0)
 (0,len(hproj)), dtype=cspadImage.dtype,
     if cspadHprojDs is None:
        cspadHprojDs = eventDataGroup.create_dataset('cspadHproj',
                               chunks=(0chunkSize, len(cspadHprojhproj)), 

                                                 maxshape=(None,len(hproj)),
   chunks=True, 
                               maxshape=(None, len(cspadHproj)),
             compression='gzip',
                  compression='gzip',
                               compression_opts=1)
  nextDsIdx += 1
  
  evtSecDs.resize((nextDsIdx+1,))
    evtNanoDs.resize((nextDsIdx+1,))
  evtFiducialsDs.resize((nextDsIdx+1,))
  ebeamL3Ds.resize((nextDsIdx+1,))
    laserOnDs.resize((nextDsIdx+1,))
    cspadHprojDs.resize((nextDsIdx+1, len(cspadHprojhproj)))

    evtSecDs[nextDsIdx] = eventId.time()[0]
    evtNanoDs[nextDsIdx] = eventId.time()[1]
  evtFiducialsDs[nextDsIdx] = eventId.fiducials()
  ebeamL3Ds[nextDsIdx] = ebeam.ebeamL3Energy()
    laserOnDs[nextDsIdx] = evr.present(LASER_ON_EVR_CODE)
    cspadHprojDs[nextDsIdx,:] = cspadHproj[:]

    if nextDsIdx >= NUM_EVENTS_TO_WRITE: 
        break
hproj
 
summaryGroup = h5out.create_group('Summary')
summaryGroup.create_dataset('l3average', data = np.average(ebeamL3Ds[:]))
h5out.close()
        

...