Versions Compared

Key

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

...

Code Block
    fname  = '/reg/d/psdm/CXI/cxi80410/hdf5/cxi80410-r0628.h5'
    dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/CxiDs1.0:Cspad.0/data'
    event  = 34
Note
  • 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.

In further description we assume that this set of external parameters is defined.

...

this method returns the CSPAD data as a numpy array for one event, ds1ev.shape=(Nseg, 185, 388), where Nseg?32.

Note

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.

Then, one has to initialize the object of the class CSPadImageProducer

...

Note

The last two methods use implicit loops over all pixels, that works pretty slow in Python. These modules are used for test only and are not recommended for real applications.

...

Examples

Module Examples.py demonstrates contains a few examples of how to use the PyCSPadImage package. The essential part of the example can be presented as:

Get and plot CSPAD image and spectrum

There are two equivalent examples defined by the methods main_example_xpp() and main_example_cxi()
for XPP and CXI experimental data, respectively.

The essential part of these examples can be presented as:

Code Block
Code Block
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, runnum = '/reg/d/psdm/xpp/xpp47712/hdf5/xpp47712-r0043.h5', 43
    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=runnum, 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(rotation=0, tiltIsOn=True, mirror=False)
    arr = cspadimg.getCSPadImage( 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()
#----------------------------------------------
if __name__ == "__main__" :
    main_example_xpp()
    sys.exit ( 'End of test.' )

Let us consider in detail what needs to be done in order to produce the CSPad image.

This is working example, which can be copied, pasted in <file-name>.py file and executed.

Note

Appropriate permission is required to access particular experimental data.

In addition to the description above, the statementsFirst, all necessary modules need to be imported:

Code Block
import CalibPars     gg.plotImage(arr,range=(0,2000),figsize=(11.6,10)) 
    gg.move(200,100)
    gg.plotSpectrum(arr,range=(0,2000))
    gg.move(50,50)
    gg.show()

allow to plot the CSPAD 2-d array as image and spectrum, move graphical windows to specified position and show all graphics.

Get and CSPAD pixel coordinate arrays

Code Block

import sys

import CalibPars          as calp
import CalibParsEvaluated as cpe

import GlobalGraphics      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:

Code Block

    path_calib = '/reg/d/psdm/xpp/xpp47712/calib/CsPad::CalibV1/XppGon.0:Cspad.0'
    fname      = '/#----------------------------------------------
def example_of_image_built_from_pix_coordinate_array_shaped_as_data() :
    """Some CSPAD segments may be missing in the dataset
    """   
    fname, runnum = '/reg/d/psdm/xppCXI/xpp47712cxi80410/hdf5/xpp47712cxi80410-r0043r0628.h5',  628
    dsname        = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/XppGonCxiDs1.0:Cspad.0/data'
Note
  • 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:

Code Block
    path_calib    = '/reg/d/psdm/CXI/cxi80410/calib/CsPad::CalibV1/CxiDs1.0:Cspad.0'
    Range         = (1000,3500)
 
    calp.calibpars.setCalibParsForPath ( run  = 1, path = path_calib )
Note
  • 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 the calp.calibpars needs to be de-referenced whenever it is necessary.
  • Run number 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:

Code Block
 (run=runnum, path=path_calib)
    #cpe.cpeval.printCalibParsEvaluated('center_global')
    cpe.cpeval.evaluateCSPadPixCoordinatesShapedAsData(fname,dsname,rotation=0)
    # At this point pixel coordinates are available and can be extracted:
    xpix, ypix = cpe.cpeval.getCSPadPixCoordinatesShapedAsData_pix()
    print 'xpix =\n', xpix

    # Test image from pixel coordinate and data arrays can be produced and plotted:
    ds1ev = hm.getOneCSPadEventForTest( fname, dsname, event=0 ) # returns array with shape=(29, 185, )
Note

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 as a numpy array

Code Block

    cspadimg = cip.CSPadImageProducer(rotation=0, tiltIsOn=True, mirror=False388)
    arr = cpe.cpeval.getTestImageShapedAsData(ds1ev)
    gg.plotImage(arr,range=Range,figsize=(11.6,10))
    gg.move(200,100)
    arr = cspadimg.getCSPadImage( ds1ev )

and used, for example for plotting

Code Block

    gg.plotImage(arr,range=(0,2000),figsize=(11.6,10))
    gg.plotSpectrum(arr,range=(0,2000)gg.show()
#----------------------------------------------
if __name__ == "__main__" :
    example_of_image_built_from_pix_coordinate_array_shaped_as_data()
    ggsys.show(exit ( 'End of test.' )

References