Page History
...
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
CSPAD geometry is varying for different detectors, experiments, or even runs. In order to keep track on all these variations LCLS offline has a simple calibration data base, which works as explained in CSPad Alignment. In order to get correct CSPAD alignment parameters the pass to the calibration directory should be specified like thisHDF5 data file:
Code Block |
---|
fname path_calib = '/reg/d/psdm/CXIxpp/cxi80410/calib/CsPad::CalibV1/CxiDs1.0:Cspad.0' |
If the detector configuration was changed during the experiment, then more than one calibration file should be available for the run ranges with stable configuration.
In order to access correct calibration file the run number should be provided, for example
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:
Code Block |
---|
runnum = 628
|
Data for CSPAD image and the detector configuration can be obtained from the HDF5 file, dataset name, and event number for example
Code Block |
---|
fname path_calib = '/reg/d/psdm/CXI/cxi80410/calib/CsPad::CalibV1/CxiDs1.0:Cspad.0/' path_calib = '/reg/d/psdm/xpp/CXIxpptut13/cxi80410/hdf5/cxi80410-r0628.h5calib/CsPad::CalibV1/XppGon.0:Cspad.0/' |
Known dataset names
Code Block |
---|
' dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/CxiDs1.0:Cspad.0/data' dsname event = 34 |
Note |
---|
|
In further description we assume that this set of external parameters is defined.
Import modules
In code snippets below we use definitions of modules and libraries as follows
Code Block |
---|
import numpy as np
import CalibPars as calp
import CalibParsEvaluated as cpe
import CSPadConfigPars as ccp
import CSPadImageProducer as cip
import GlobalGraphics as gg
import HDF5Methods as hm
|
Reconstruction of CSPAD image
Entire code example for image reconstruction is
Code Block |
---|
calp.calibpars.setCalibParsForPath ( run=runnum, path=path_calib )
ds1ev = hm.getOneCSPadEventForTest( fname, dsname, event )
cspadimg = cip.CSPadImageProducer(rotation=0, tiltIsOn=True, mirror=True)
arr = cspadimg.getCSPadImage( ds1ev )
|
First, one has to set the correct version of the calibration parameters
Code Block |
---|
calp.calibpars.setCalibParsForPath ( run=runnum, path=path_calib )
|
Then, one need in CSPAD dataset for event,
Code Block |
---|
ds1ev = hm.getOneCSPadEventForTest( fname, dsname, event )
|
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. |
Then, one has to initialize the object of the class CSPadImageProducer
Code Block |
---|
cspadimg = cip.CSPadImageProducer(rotation=0, tiltIsOn=True, mirror=True)
|
with optional parameters
rotation
integer from 0 to 3 parameters for CSPAD orientation as 90*rotation
degree.tiltIsOn
=True
orFalse
- to account or not the tiny tilt angle of 2x1 sections.mirror
=True
orFalse
- to mirror reflect or not the image.
Finally the method
Code Block |
---|
arr = cspadimg.getCSPadImage( ds1ev )
|
returns the 2-d numpy array with CSPAD image, which can be plotted using for example matplotlib
.
CSPAD pixel coordinate arrays
CSPAD pixel coordinate arrays can be evaluated/returned in two different shapes:
- for entire CSPAD with shape=(4,8,185,388)
- for data-driven shape=(Nseg,185,388), where Nseg?32 if some quads/segments are missing in data.
To get pixel coordinate arrays shaped for entire CSPAD use code:
Code Block |
---|
calp.calibpars.setCalibParsForPath ( run=runnum, path=path_calib )
cpe.cpeval.evaluateCSPadPixCoordinates (rotation=0, mirror=False)
xpix, ypix = cpe.cpeval.getCSPadPixCoordinates_pix()
|
where the parameters rotation
and mirror
have the same meaning as before,
xpix and ypix are the coordinate (in pixels) arrays with shape = (4,8,185,388).
Method xpix_um, ypix_um = cpe.cpeval.getCSPadPixCoordinates_um()
returns pixel coordinates in micrometer.
To get CSPAD pixel coordinate arrays shaped as in data use code:
Code Block |
---|
calp.calibpars.setCalibParsForPath ( run=runnum, path=path_calib )
cpe.cpeval.evaluateCSPadPixCoordinatesShapedAsData(fname,dsname,rotation=0,mirror=False)
xpix, ypix = cpe.cpeval.getCSPadPixCoordinatesShapedAsData_pix()
|
where xpix and ypix are the coordinate (in pixels) arrays with shape = (Nseg,185,388).
Note that the fname
and dsname
need to be specified in order to get configuration of the data array.
Method xpix_um, ypix_um = cpe.cpeval.getCSPadPixCoordinatesShapedAsData_um()
returns pixel coordinates in micrometer.
The coordinate arrays extracted for both shapes are tested in module Examples.py
by the methods
example_of_image_built_from_pix_coordinate_array_shaped_as_data()
and
example_of_image_built_from_pix_coordinate_array_for_entire_cspad()
,
where images are reconstructed through the pixel coordinate arrays in
cpe.cpeval.getTestImageShapedAsData(ds1ev)
and
cpe.cpeval.getTestImageForEntireArray(ds1ev)
, respectively.
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. |
...
= '/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'
|
Run and event number:
Code Block |
---|
runnum = 628
event = 34
|
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
|
Reconstruction of CSPAD image
CSPAD pixel coordinate arrays
Code Block |
---|
Examples
Module Examples.py
contains a few examples of how to use the PyCSPadImage package.
...