Introduction
The mainstream data analysis framework is based on C++ package Psana. To work with CSPad images Psana has several modules which are collected in the CSPadPixCoords package. Two of these modules, CSPadImageProducer and CSPadInterpolImageProducer, produce the 2-D array with CSPad image from raw data (currently XTC, but HDF5 will be available soon). Precise CSPad geometry is accounted using the calibration parameters supplied by the PSCalib package.
In this note we describe the PyCSPadImage package which converts the raw data in geometry-corrected 2-D array with CSPad image for HDF5 data in python
.
PyCSPadImage package
Consists of python modules (in alphabetic order):
CSPadConfigPars.py
- provides access to the CSPad configuration parametersCSPadImageProducer.py
- receives raw CSPad data 3-D array, uses calibration parameters, produces the 2-D image arrayCalibPars.py
- provides access to the CSPad calibration parametersCalibParsDefault.py
- defines the default CSPad calibration parametersExamples.py
- contains examples of how to get the CSPad 2-D image array with corrected geometryGlobalGraphics.py
- a set of useful methods for interactive graphicGlobalMethods.py
- a set of misceleneous global modulesHDF5Methods.py
- a set of methods to work with HDF5 files
How to get this package
Below we assume that all standard environment variable settings are done (oservice see Analysis Workbook. Account Setup). In order to copy the PyCSPadImage package from SVN
repository and run a simple test one has to use commands:
login to psanaXXXX kinit cd <your-favorite-directory> newrel ana-current <your-release-directory-name> cd <your-release-directory-name> sit_setup addpkg PyCSPadImage HEAD cd PyCSPadImage/src/ <==== All source-code files are located here python Examples.py
Example
Module Examples.py
demonstrates of how to use the PyCSPadImage package. The essential part of the example can be presented as:
import sys import os import CalibPars as calp import CSPadConfigPars as ccp import CSPadImageProducer as cip import GlobalGraphics as gg # For test purpose in main only import HDF5Methods as hm # For test purpose in main only #---------------------------------------------- def main_example_xpp() : print 'Start test in main_example_xpp()' path_calib = '/reg/d/psdm/xpp/xpp47712/calib/CsPad::CalibV1/XppGon.0:Cspad.0' fname = '/reg/d/psdm/xpp/xpp47712/hdf5/xpp47712-r0043.h5' dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/XppGon.0:Cspad.0/data' event = 0 print 'Load calibration parameters from', path_calib calp.calibpars.setCalibParsForPath ( run = 1, path = path_calib ) print 'Get raw CSPad event %d from file %s \ndataset %s' % (event, fname, dsname) ds1ev = hm.getOneCSPadEventForTest( fname, dsname, event ) print 'ds1ev.shape = ',ds1ev.shape print 'Make the CSPad image from raw array' cspadimg = cip.CSPadImageProducer() arr = cspadimg.getImageArrayForCSPadElement( ds1ev ) print 'Plot CSPad image' gg.plotImage(arr,range=(0,2000),figsize=(11.6,10)) gg.move(200,100) gg.plotSpectrum(arr,range=(0,2000)) gg.move(50,50) print 'To EXIT the test click on "x" in the top-right corner of each plot window.' gg.show()
Let us consider in detail what needs to be done in order to produce the CSPad image.
First, all necessary modules need to be imported:
import CalibPars as calp import CSPadConfigPars as ccp import CSPadImageProducer as cip import GlobalGraphics as gg # For test purpose in main only import HDF5Methods as hm # For test purpose in main only
Then, the path to the calibration data types, the HDF5 data file name, and the dataset name in HDF5 structure need to be defined:
path_calib = '/reg/d/psdm/xpp/xpp47712/calib/CsPad::CalibV1/XppGon.0:Cspad.0' fname = '/reg/d/psdm/xpp/xpp47712/hdf5/xpp47712-r0043.h5' dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/XppGon.0:Cspad.0/data'
- In principal, the path to the calibration data types can be defined automatically, but there is a chance that user would want to keep calibration files in non-standard place.
- The CSPad dataset can be also found automatically, but there might be more than one CSPad detector in experiment...
Then, calibration parameters need to be loaded:
calp.calibpars.setCalibParsForPath ( run = 1, path = path_calib )
- Currently, the calibration parameters are defined through the "singleton" object
calp.calibpars
.
If more than one CSPad is going to be used simultaneously, then different sets of calibration parameters
need to be loaded and thecalp.calibpars
needs to be de-referenced whenever it is necessary. - Run needs to be specified if there are more than one calibration file available for different run ranges.
Then, the raw CSPad dataset needs to be extracted:
ds1ev = hm.getOneCSPadEventForTest( fname, dsname, event )
It is recommended to use this method, which also loads correct configuration parameters from HDF5 file.
Default version of the configuration parameters can be wrong, if not all 2x1 are in use.
Finally the 2-D image array can be obtained
cspadimg = cip.CSPadImageProducer() arr = cspadimg.getImageArrayForCSPadElement( ds1ev )
and used, for example for plotting
gg.plotImage(arr,range=(0,2000),figsize=(11.6,10)) gg.plotSpectrum(arr,range=(0,2000)) gg.show()