Versions Compared

Key

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

Content

Table of Contents

Introduction

In this note we describe the python-based PyCSPadImage package which is intended to evaluate and provide access to the pixel coordinate arrays. In addition, it converts the CSPAD raw data from HDF5 file to the geometry-corrected 2-D image array. This package can be used in a stand-alone python code.

...

Below we assume that all standard environment variable settings are done (otherwise 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:

Code Block

log in to psana<XXXX>
kinit
cd <your-favorite-directory>

newrel ana-current <your-release-directory-name>
cd <your-release-directory-name>
sit_setup
addpkg PyCSPadImage HEAD

python PyCSPadImage/src/Examples.py 1

External parameters

...

Import modules

Code Block
import sys
import os
import numpy fnameas = '/reg/d/psdm/xpp/xpptut13/hdf5/xpptut13-r0150.h5' # to test XPP data
   fname = '/reg/d/psdm/cxi/cxitut13/hdf5/cxitut13-r1150.h5' # to test CXI data

Path to the directory with calibration types:

np
import PyCSPadImage.CalibPars          as calp
import PyCSPadImage.CSPadConfigPars    as ccp
import PyCSPadImage.CSPadImageProducer as cip
import PyCSPadImage.CSPADPixCoords     as pixcoor
import PyCSPadImage.PixCoords2x1       as pixcoor2x1
import PyCSPadImage.GlobalGraphics     as gg
import PyCSPadImage.GlobalMethods      as gm
import PyCSPadImage.HDF5Methods        as hm

External parameters

HDF5 data file:

Code Block
   fname = 
Code Block

   path_calib = '/reg/d/psdm/CXI/cxi80410/calib/CsPad::CalibV1/CxiDs1.0:Cspad.0/'
   path_calib = '/reg/d/psdm/xpp/xpptut13/calib/CsPad::CalibV1/XppGon.0:Cspad.0/'

Known dataset names

Code Block
  hdf5/xpptut13-r0150.h5' # to test XPP data
   dsnamefname = '/reg/d/psdm/cxi/cxitut13/hdf5/cxitut13-r1150.h5' # to test CXI data

Path to the directory with calibration types:

Code Block
   path_calib = '/reg/d/psdm/CXI/cxi80410/calib/CsPad::CalibV1/CxiDs1Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/CxiDs1.0:Cspad.0/data'
   dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/CxiDsd.0:Cspad.0/data'
   dsnamepath_calib = '/reg/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2d/psdm/xpp/xpptut13/calib/CsPad::CalibV1/XppGon.0:Cspad.0/data'

HDF5 dataset names for known CSPADs:

Code Block
  
   dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/XcsEndstationCxiDs1.0:Cspad.0/data'

Run and event number:

Code Block

    runnum = 628
    event  = 34

Import modules

dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/CxiDsd.0:Cspad.0/data'
   dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/XppGon.0:Cspad.0/data'
   dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/XcsEndstation.0:Cspad.0/data'

Interface to CalibPars.py

This class provides access to the CSPAD calibration parameters.

Code Block
       Regular instantiation:
           ALL parameters are OPTIONAL NAMED parameters;
           path  = '/reg/d/psdm/xpp/xpptut13/calib/CsPad::CalibV1/XppGon.0:Cspad.0/' 
Code Block

import sys
import os
import numpy as np

import PyCSPadImage.CalibPars          as calp
import PyCSPadImage.CSPadConfigPars    as ccp
import PyCSPadImage.CSPadImageProducer as cip
import PyCSPadImage.CSPADPixCoords     as pixcoor
import PyCSPadImage.PixCoords2x1       as pixcoor2x1

import PyCSPadImage.GlobalGraphics     as gg
import PyCSPadImage.GlobalMethods      as gm
import PyCSPadImage.HDF5Methods        as hm

Reconstruction of CSPAD image

CSPAD pixel coordinate arrays

...

Examples

Module Examples.py contains a few examples of how to use the PyCSPadImage package.

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

import sys
import os
import CalibPars    run   = 123
           calib = CalibPars(path, list_of_clib_types=['center', 'tilt', 'pedestals'])
           arr_pedestals = calib.getCalibPars('pedestals', run)
 
       Other option for instantiation:
 as calp
import CSPadConfigPars    as ccp
import CSPadImageProducer as cip
import GlobalGraphics calib    = CalibPars()
           asrun gg # For test purpose in= main123 only
import HDF5Methods- is an optional, named
    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/XppGoncalibdir = '/reg/d/psdm/CXI/cxi35711/calib'
           group    = 'CsPad::CalibV1'
           source   = 'CxiDs1.0:Cspad.0'
    fname, runnum = '/reg/d/psdm/xpp/xpp47712/hdf5/xpp47712-r0043.h5', 43     calib.setCalibPars (run, calibdir, group, source)

    dsname        = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/XppGon.0:Cspad.0/data'
    event   Get array of calibration parameters for specified type and run number:
           type = 0'center'

     print 'Load calibration parameters from', path_calib
 arr  = calpcalib.calibpars.setCalibParsForPathgetCalibPars (type[,run])

Interface to CSPadConfigPars.py

This class provides access to the CSPAD configuration parameters.

Code Block
 run=runnum, path=path_calib )

    print1. 'GetSets rawa CSPadbunch eventof %ddefault fromconfiguration fileparameters,
 %s \ndataset %s' % (event, fname, dsname)
loads current coniguration parameters ds1evfrom = hm.getOneCSPadEventForTest( fname, dsname, event )hdf5 file or from external parameters.
    print 'ds1ev2.shape = ',ds1ev.shape

    print 'Make the CSPad image from raw array'
    cspadimg = cip.CSPadImageProducer(rotation=0, tiltIsOn=True, mirror=False)Provides access to current coniguration parameters
    3. Contains conversion methods for arrays between raw data and entire cspad.
    arr
 = cspadimg.getCSPadImage( ds1ev )Interface

    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)=========
    1.  Instatiation
    1.1 Default constructor sets default parameters for indPairsInQuads & quadNumsInEvent:

    print 'To EXIT the testconfig 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.' )

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 statements

Code Block

    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 CSPAD pixel coordinate arrays

Here we reproduce the test method
example_of_image_built_from_pix_coordinate_array_shaped_as_data()
from the module Examples.py.
This example shows how to get the CSPAD pixel coordinate arrays. In addition, it uses the getTestImageShapedAsData(ds1ev) (slow) method to produce image from the pixel coordinate arrays and data and plots this image.

Code Block

import sys
import CalibPars= CSPadConfigPars()

    1.2 Initialization of configuration parameters using hdf5 file, for example:
        fname  = '/reg/d/psdm/xpp/xpp66213/hdf5/xpp66213-r0150.h5'
        dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/XppGon.0:Cspad.0/data'

        config.setCSPadConfiguration( fname, dsname, event=0 ):

    1.3 Initialization of configuration parameters using external arrays, for example:        
        indPairs = np.arange(32)
        indPairs.shape = (4,8)
        quadNums = np.arange(4)

        config.setCSPadConfigArrays( indPairsInQuads=indPairs, quadNumsInEvent=quadNums )

   2.  Access methods:

    2.1 Access to indPairsInQuads and quadNumsInEvent:
        quadNums   as calp
import CalibParsEvaluated as cpe
import GlobalGraphics= config.getQuadNumsInEvent()
         as gg # For test purpose in main only
import HDF5Methods        as hm # For test purpose in main only
#----------------------------------------------
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/CXI/cxi80410/hdf5/cxi80410-r0628.h5',  628
    dsname        = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/CxiDs1.0:Cspad.0/data'
    path_calib    = '/reg/d/psdm/CXI/cxi80410/calib/CsPad::CalibV1/CxiDs1.0:Cspad.0'
    RangeindPairs = config.getIndPairsInQuads()
        config.printCSPadConfigPars()

    2.2 Access to static class parameters:    
        import CSPadConfigPars as ccp
        my_wid2x1 = ccp.CSPadConfigPars().wid2x1
        etc...

    3.  Conversions between entire (4,8,185,388) and shaped as data (N<32,185,388) cspad pixel array shapes:

    3.1 Conversion of the entire cspad pixel array arr_entire_cspad with shape (4,8,185,388)
        in to the arr_raw_data, shaped as data (N<32,185,388):
        arr_raw_data = (1000,3500config.getCSPadPixArrayShapedAsData(arr_entire_cspad)
 
    calp.calibpars.setCalibParsForPath (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 plotted3.2 Conversion of the cspad pixel array arr_raw_data shaped as data (N<32,185,388)
        in to the entire cspad pixel array arr_entire_cspad with shape (4,8,185,388):
        arr_entire_cspad = getCSPadPixArrayFromArrayShapedAsData(arr_raw_data)

    4.  Tests
        To test CSPadConfigPars from release directory use command:
    ds1ev = hm.getOneCSPadEventForTest( fname, dsname, event=0 ) # returns array with shape=(29, 185, 388)
    arr = cpe.cpeval.getTestImageShapedAsData(ds1ev)
    gg.plotImage(arr,range=Range,figsize=(11.6,10))
    gg.move(200,100)
    gg.show()
#----------------------------------------------
if __name__ == "__main__" :
    example_of_image_built_from_pix_coordinate_array_shaped_as_data()
    sys.exit ( 'End of test.' )

Get CSPAD pixel coordinate arrays without data base.

Use class CSPadPixCoordsWODB.py
Essentialy user has to provide 4 arrays for 2x1 alignment. For example see
def main_test_cspad() :

python PyCSPadImage/src/CSPadConfigPars.py <test-number>
        where <test-number> stands for  0, 1, 2, or 3

Interface to CSPADPixCoords.py

Class for generation of CSPad pixel coordinate array with and without data base

Code Block
    Interface
    =========
       1.0 Instantiation with default parameters taken from optical measurement for XPP on 2013-01-29:
           coord = CSPADPixCoords()

       1.1 Instantiation with external geometry parameters:
 
           All parameters optional. Default values will be used if parameters are not specified.
  
Code Block

    xc_um = 109.92 * np.array(
         xc   [[ 473.38,  685.26,  155.01,  154.08,  266.81,   53.95,  583.04,  582.15],   - np.array(...), shape=(3, 4, 8)) [um]
           yc  [ 989.30, - 987.12, 1096.93,  884.11, 1413.16, 1414.94, 1500.83, 1288.02],  
np.array(...), shape=(3, 4, 8)) [um]
           tilt    [1142.59,  930.23, 1459.44, 1460.67, 1347.57, 1559.93, 1032.27, 1033.44],  
- np.array(...), shape=(4, 8)) [deg]
           coord = CSPADPixCoords(xc_um=xc, yc_um=yc, tilt_deg=tilt)


  [ 626.78,  627.42,  5161.03,2 Instantiation 729.15,with regular 198.28,  198.01,  115.31,  327.66]])calibration parameters:

    yc_um = 109.92 * np.array(
     path  = '/reg/neh/home1/dubrovin/LCLS/CSPadAlignment-v01/calib-xpp-2013-01-29'
    [[1028.07, 1026.28, 1139.46,  926.91, 1456.78, 1457.35, 1539.71, 1327.89],   run   = 123
           calib  [1180.51= CalibPars(path,  967.36, 1497.74, 1498.54, 1385.08, 1598.19, 1069.65, 1069.93],  
    run)
           coord = CSPADPixCoords(calib)

       1.2  [ 664.89,  666.83,  553.60,  765.91,  237.53,  236.06,  152.17,  365.47],  
             [ 510.38,  722.95,  193.33,  193.41,  308.04,   95.25,  625.28,  624.14]])

    orient_deg = np.array(
                    [[  90.,   90.,    0.,    0.,  270.,  270.,    0.,    0.],
                     [   0.,    0.,  270.,  270.,  180.,  180.,  270.,  270.],
                     [  90.,   90.,    0.,    0.,  270.,  270.,    0.,    0.],
                     [   0.,    0.,  270.,  270.,  180.,  180.,  270.,  270.]])
 
    tilt_deg = np.array(
                    [[0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],  
                     [0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],  
                     [0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],  
                     [0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]])
Note

ALL arrays are shown here FOR TEST PURPOSE ONLY !!! and they are not consistent with any real detector. The orient_deg is not consistent with real orientation as well...

These arrays of alignment parameters are used for initialization of the CSPadPixCoordsWODB class object, which can be used to get X,Y-coordinate arrays as shown below:

Code Block

    w = CSPadPixCoordsWODB(xc_um, yc_um, orient_deg, tilt_deg)
    X,Y = wAccess methods:
           Get arrays of pixel coordinates in mu with shape: [2,185,388]
            X, Y = coord.get_cspad_pix_coordinate_arrays_pixum  ()

where X.shape = Y.shape = (4, 8, 185, 388) and obviously can be re-shaped to (32, 185, 388). Then, it is easy to produce image of coordinate arrays using numpy 2D histogramming method:

Code Block

    xsize = X.max() + 1
    ysize = Y.max() + 1
    Img, Xedges, Yedges = np.histogram2d(X.flatten(), Y.flatten(), bins=[xsize,ysize], range=[[0,xsize],[0,ysize]], normed=False, weights=None)

Image RemovedImage Removed

config=None)
           or in integer pixels:
           iX,iY = coord.get_cspad_pix_coordinate_arrays_pix (config=None)

       1.3 Get image  
           img = coord.get_cspad_image(data,config)     

Examples

Module Examples.py contains a few examples of how to use the PyCSPadImage packageIn order to get an image of intensity the weights array needs to be provided.

References