Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Add descrioption for CSPad pedestal operations

...

where item stands for file, group of dataset.

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

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

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

Get information about HDF5 item

  • For all HDF5 items:
    these parameters are available:
    Code Block
    item.id      # for example: <GroupID [1] (U) 33554473>
    item.ref     # for example: <HDF5 object reference>
    item.parent  # for example: <HDF5 group "/Configure:0000/Run:0000/CalibCycle:0000" (5 members)>
    item.file    # for example: <HDF5 file "cxi80410-r0587.h5" (mode r, 3.5G)>
    item.name    # for example: /Configure:0000/Run:0000/CalibCycle:0000/Camera::FrameV1
    

...

  • Get the list of daughters in the group
    Code Block
    list_of_item_names = group.items()
    print list_of_item_names
    
    or convert the group in dictionary and iterate over their key and values,
    Code Block
    for key,val in dict(group).iteritems():
        print key, val
    

Extract time

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 is usually stored in the group attributes and/or in the data record with name "time", which can be extracted as shown below

...

  • from the time data record
    Code Block
    time_dataset = file['/Configure:0000/Run:0000/CalibCycle:0002/Acqiris::DataDescV1/XppLas.0:Acqiris.0/time']
    
    index = 0                   # this is an index in the dataset
    time_arr = time_dataset[index]  # get the time tuple consisting of seconds and nanoseconds
    time_sec  = time_arr[0]
    time_nsec = time_arr[1]
    

Operations with CSPad pedestals

Most generic way to subtract the CSPad pedestals is to use Translator, as described in CsPad calibration in translator. In this case the HDF5 file has the CSPad image data with already subtracted pedestals. If the job execution time is not an issue, the pedestals can be subtracted in code, as explained in this section

How to find the files with CSPad pedestals

CSPad pedestals are usually calibrated using the "dark" runs. If they were calibrated, the files for appropriate run range, <run-range>.dat, can be found in the directory
/reg/d/psdm/<INSTRUMENT>/<experiment>/calib/<calib-version>/<source>/pedestals/
or directly in HDF5 dataset
/Configure:0000/CsPad::CalibV1/XppGon.0:Cspad.0/pedestals

How to calibrate CSPad pedestals

If the CSPad pedestals were not calibrated, they can be easily calibrated, as explained in
the description of the CsPadPedestals psana module. Essentially, one need to run the psana for cspad_mod.CsPadPedestals module, using the command
psana -m cspad_mod.CsPadPedestals input-files.xtc
which by default produce two files:

  • cspad-pedestals.dat – for average values and
  • cspad-noise.dat – for standard deviation values
    These files can be accessible in code as explained below.

Get CSPad pedestal array

The file with pedestal values can be read in code as a [numpy] array:

Code Block

import numpy as np
ped_fname = '/reg/d/psdm/<INS>/<experiment>/calib/<calib-version>/<source>/pedestals/<run-range>.dat'
ped_arr = np.loadtxt(ped_fname, dtype=np.float32)
ped_arr.shape = (32, 185, 388) # raw shape is (5920, 388)

In this example the pedestal file is loaded from the standard calib directory. For your own pedestal file the path name should be changed.

Subtract CSPad pedestals

Assuming that the CSPad event array [ds1ev] and the pedestal array ped_arr are available,
the pedestals can be subtracted by the single operation for [numpy] arrays:

Code Block

if ds1ev.shape == ped_arr.shape : ds1ev -= ped_arr
Note

This operation will only be valid if the CSPad data array is completely filled (all sensors are available) and its shape is equal to (32, 185, 388). Otherwise, the pedestal subtraction can be done in a loop over available sensors, taking into account the CSPad configuration.

Code examples

Example 1: Basic operations

...