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.

Note

Please note, that LCLS main-stream data analysis framework is based on C++/python 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, are intended to produce the 2-D array with CSPAD image from raw XTC data. Precise CSPAD geometry is accounted in Psana using the calibration parameters supplied by the PSCalib package.

Package PyCSPadImage

Content

The python-based PyCSPadImage package consists of modules:

Status

Module

For

Description

(tick)

PixCoords2x1.py

2x1

defines the 2x1 section pixel coordinates

(tick)

CSPAD2x2CalibParsDefault.py

CSPAD2x2

defines default CSPAD2x2 calibration parameters

(tick)

CSPAD2x2CalibPars.py

CSPAD2x2

provides access to the CSPAD2x2 calibration parameters

(tick)

CSPAD2x2PixCoords.py

CSPAD2x2

evaluates the CSPAD2x2 pixel coordinates

(tick)

CSPAD2x2Examples.py

CSPAD2x2

CSPAD2x2 examples

(tick)

CSPadConfigPars.py

CSPAD

defines CSPAD configuration parameters

(tick)

CalibParsDefault.py

CSPAD

defines default calibration parameters

(tick)

CSPADCalibParsEvaluated.py

CSPAD

evaluates the center_global from other quad parametes

(tick)

CalibPars.py

CSPAD

provides access to the CSPAD calibration parameters

(tick)

CSPADPixCoords.py

CSPAD

evaluates the CSPAD pixel coordinates

(tick)

Examples.py

CSPAD

CSPAD examples

(plus)

CSPadImageProducer.py

CSPAD

Depricated

(tick)

GlobalGraphics.py

Utils

Graphical utils

(tick)

GlobalMethods.py

Utils

Global methods

(tick)

HDF5Methods.py

Utils

Common methods for operations with HDF5 files

(plus)

Alignment.py

Internal

It is used for alignment purpose

How to get this package

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
Wiki Markup
h1. Content
{toc}


h1. 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.

{note}
Please note, that LCLS main-stream data analysis framework is based on C+\+/python package [PCDS:Psana]. To work with CSPad images [PCDS:Psana] has several modules which are collected in the [CSPadPixCoords |PCDS:Psana CSPad Geometry  # Package CSPadPixCoords] package. Two of these modules, [CSPadImageProducer|PCDS:Psana CSPad Geometry # Module CSPadImageProducer] and [CSPadInterpolImageProducer|PCDS:Psana CSPad Geometry # Module CSPadInterpolImageProducer], are intended to produce the 2-D array with CSPAD image from raw XTC data. Precise CSPAD geometry is accounted in [PCDS:Psana] using the calibration parameters supplied by the [PSCalib|PCDS:Psana CSPad Geometry # Package PSCalib] package.
{note}


h1. Package PyCSPadImage

h3. Content
The {{python}}\-based *PyCSPadImage* package consists of modules:
|| Status || Module                         || For     || Description ||
|(/)      | {{PixCoords2x1.py}}             | 2x1      | defines the 2x1 section pixel coordinates  |
|(/)      | {{CSPAD2x2CalibParsDefault.py}} | CSPAD2x2 | defines default CSPAD2x2 calibration parameters   |
|(/)      | {{CSPAD2x2CalibPars.py}}        | CSPAD2x2 | provides access to the CSPAD2x2 calibration parameters   |
|(/)      | {{CSPAD2x2PixCoords.py}}        | CSPAD2x2 | evaluates the CSPAD2x2 pixel coordinates    |
|(/)      | {{CSPAD2x2Examples.py}}         | CSPAD2x2 | CSPAD2x2 examples   |
|(/)      | {{CSPadConfigPars.py}}          | CSPAD    | defines CSPAD configuration parameters   |
|(/)      | {{CalibParsDefault.py}}         | CSPAD    | defines default calibration parameters   |
|(/)      | {{CSPADCalibParsEvaluated.py}}  | CSPAD    | evaluates the *center_global* from other quad parametes  |
|(/)      | {{CalibPars.py}}                | CSPAD    | provides access to the CSPAD calibration parameters   |
|(/)      | {{CSPADPixCoords.py}}           | CSPAD    | evaluates the CSPAD pixel coordinates   |
|(/)      | {{Examples.py}}                 | CSPAD    | CSPAD examples   |
|(+)      | {{CSPadImageProducer.py}}       | CSPAD    | Depricated   |
|(/)      | {{GlobalGraphics.py}}           | Utils    | Graphical utils  |
|(/)      | {{GlobalMethods.py}}            | Utils    | Global methods   |
|(/)      | {{HDF5Methods.py}}              | Utils    | Common methods for operations with HDF5 files |
|(+)      | {{Alignment.py}}                | Internal | It is used for alignment purpose |


h3. How to get this package

Below we assume that all standard environment variable settings are done (otherwise see [PCDS: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}
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
{code}

h3. Import modules

{code}

Import modules

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
{code}



h3. External parameters

HDF5 data file:
{code}

External parameters

HDF5 data file:

Code Block
   fname = '/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
{code}   

Path to the directory with calibration types:
{code}

Path to the directory with calibration types:

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/'
{code}

HDF5 dataset names for known CSPADs:

Code Block
  

HDF5 dataset names for known CSPADs:
{code}  
   dsname = '/Configure: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'
   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'
{code}  
 

h3. Interface to {{

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/' 
           run   = 123
           calib = CalibPars(path, list_of_clib_types=['center', 'tilt', 'pedestals'])
           arr_pedestals = calib.getCalibPars('pedestals', run)
 
       Other option for instantiation:
           calib    = CalibPars()
           run      = 123  - is an optional, named
           calibdir = '/reg/d/psdm/CXI/cxi35711/calib'
           group    = 'CsPad::CalibV1'
           source   = 'CxiDs1.0:Cspad.0'
           calib.setCalibPars (run, calibdir, group, source)

       Get array of calibration parameters for specified type and run number:
           type = 'center'
           arr  = calib.getCalibPars (type[,run])
{code}


h3. Interface to {{

Interface to CSPadConfigPars.py

...

This

...

class

...

provides

...

access

...

to

...

the

...

CSPAD

...

configuration

...

parameters.

{
Code Block
}
    1. Sets a bunch of default configuration parameters,
       loads current coniguration parameters from hdf5 file or from external parameters.
    2. Provides access to current coniguration parameters
    3. Contains conversion methods for arrays between raw data and entire cspad.
    
    Interface
    =========
    1.  Instatiation
    1.1 Default constructor sets default parameters for indPairsInQuads & quadNumsInEvent:

        config = 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 = config.getQuadNumsInEvent()
        indPairs = 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 = config.getCSPadPixArrayShapedAsData(arr_entire_cspad)

    3.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:
        python PyCSPadImage/src/CSPadConfigPars.py <test-number>
        where <test-number> stands for  0, 1, 2, or 3
{code}


h3. Interface to {{ 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.
           xc    - np.array(...), shape=(3, 4, 8)) [um] if parameters are not specified.
           ycxc    - np.array(...), shape=(3, 4, 8)) [um]
           tiltyc    - np.array(...), shape=(4, 8)) [deg]
           coord = CSPADPixCoords(xc_um=xc, yc_um=yc, tilt_deg=tilt)


), shape=(3, 4, 8)) [um]
       1.2 Instantiation with regular calibrationtilt parameters:

           path  = '/reg/neh/home1/dubrovin/LCLS/CSPadAlignment-v01/calib-xpp-2013-01-29'
- np.array(...), shape=(4, 8)) [deg]
           coord =  run   = 123CSPADPixCoords(xc_um=xc, yc_um=yc, tilt_deg=tilt)


       1.2 Instantiation with regular calib = CalibPars(path, run)
calibration parameters:

           path  coord = CSPADPixCoords(calib)

 '/reg/neh/home1/dubrovin/LCLS/CSPadAlignment-v01/calib-xpp-2013-01-29'
      1.2 Access methods:
   run   = 123
    Get arrays of pixel coordinates in mu withcalib shape: [2,185,388]= CalibPars(path, run)
            X,coord Y = coord.get_cspad_pix_coordinate_arrays_um  (config=None)CSPADPixCoords(calib)

       1.2    or in integer pixelsAccess methods:
           iX,iY = coord.get_cspad_pix_coordinate_arrays_pix (config=None)

       1.3 Get image  
Get arrays of pixel coordinates in mu with shape: [2,185,388]
            X, imgY = coord.get_cspad_image(data,config)_pix_coordinate_arrays_um  (config=None)
      
{code}




h1. Examples

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

{html}
<!--
h3. Get and plot CSPAD image and spectrum
h3. Get CSPAD pixel coordinate arrays
h3. Get CSPAD pixel coordinate arrays without data base.
-->
{html}


h1. References

* [PCDS:CSPad image producer in Python] - earlier version description.
* [CSPAD Alignment]
* [CSPAD Geometry Software]
* [Package CSPadPixCoords|PCDS:Psana Module Catalog # Package CSPadPixCoords] for [PCDS:Psana]     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 package.

References