You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

Unable to render {include} The included page could not be found.
Unable to render {include} The included page could not be found.

About

This page provides examples for selected modules from Psana Module Catalog.

Auxiliary scripts

A few python scripts in ImgPixSpectra/data/ show how to process/plot the spectral array stored in the file.

  • PlotSpectralArrayFromFile.py - allows to plot content of the spectral array as a 2-d plot.
  • SpectralArray.py - provides access to the spectral array stored in the file. The class SpectralArray defined in this script is used in the PlotSpectralArrayFromFile.py.
  • MergeArrays.py - sums the arrays from different files defined in the list and saves resulting array in a single file with the same shape. In this script the list of files is hardwired in the get_list_of_input_file_names() method. The output file name, out_fname, is also hardwired in the call to spectra_merging(out_fname).

A few auxiliary scripts for example are located in the directory ImgAlgos/data:

  • psana.cfg - set non-default parameters to run psana for ImgAlgos::ImgPeakFinder and ImgAlgos::ImgPeakFilter
    The psana running this script saves images and peaks for event 115 in text files.
  • PlotCameraImageFromFile.py - Plots image and spectrum for image saved in file.
  • PlotCameraImageAndPeaks.py - Plots image with found peaks and spectrum.

Examples for package cspad_mod

Example for module cspad_mod::CsPad2x2Pedestals

Configuration file for pedestals calibration of two CSPAD2x2 simultaneously:

[psana]
files = /reg/d/psdm/xpp/xpptut13/xtc/e308-r0070-s02-c00.xtc \
        /reg/d/psdm/xpp/xpptut13/xtc/e308-r0070-s03-c00.xtc
          
modules = cspad_mod.CsPad2x2Pedestals:0 \
          cspad_mod.CsPad2x2Pedestals:1

#skip-events = 100
#events = 1111

[cspad_mod.CsPad2x2Pedestals:0]
source = DetInfo(XppGon.0:Cspad2x2.0)
output = pedestals-ave-xppi0513-r0070-Cspad2x2.0.dat
noise  = pedestals-rms-xppi0513-r0070-Cspad2x2.0.dat

[cspad_mod.CsPad2x2Pedestals:1]
source = DetInfo(XppGon.0:Cspad2x2.1)
output = pedestals-ave-xppi0513-r0070-Cspad2x2.1.dat
noise  = pedestals-rms-xppi0513-r0070-Cspad2x2.1.dat

Command to run this script:

psana -c psana-xppi0513-r0070-cspad2x2-pedestals.cfg

The xtc file name(s) may be passed as an argument:

psana -c psana-xppi0513-r0070-cspad2x2-pedestals.cfg /reg/d/psdm/xpp/xpptut13/xtc/e308-r0070-*.xtc

Output files contain results, which can be plotted for average values:

and rms values:

Example for package CSPadPixCoords

How to write the CSPad image in text file:

[psana]                                                               
files         = /reg/d/psdm/<instrument>/<experiment>/xtc/<file-name-1>.xtc
events        = 5

modules       = cspad_mod.CsPadCalib CSPadPixCoords.CSPadImageProducer ImgAlgos.ImgSaveInFile

[cspad_mod.CsPadCalib]
inputKey      = 
outputKey     = calibrated
doPedestals   = yes
doPixelStatus = no
doCommonMode  = no

#[CSPadPixCoords.CSPadInterpolImageProducer]
[CSPadPixCoords.CSPadImageProducer]
calibDir      = /reg/d/psdm/<instrument>/<experiment>/calib
typeGroupName = CsPad::CalibV1
source        = CxiDs1.0:Cspad.0
key           = calibrated
imgkey        = Image2D
tiltIsApplied = true

[ImgAlgos.ImgSaveInFile]
source        = CxiDs1.0:Cspad.0
#eventSave    = 1
saveAll       = true

See Package CSPadPixCoords

Example for module CSPadPixCoords::CSPad2x2ImageProducer

See Module CSPadPixCoords::CSPad2x2ImageProducer

Example of the configuration script for psana (cspad2x2-test.cfg):

[psana]
files         = /reg/d/psdm/<instrument>/<experiment>/xtc/<file-name-1>.xtc
events        = 5
modules       = CSPadPixCoords.CSPad2x2ImageProducer ImgAlgos.ImgSaveInFile

[CSPadPixCoords.CSPad2x2ImageProducer]
source         = DetInfo(:Cspad2x2)
inkey          = 
outimgkey      = Image
tiltIsApplied  = true
print_bits     = 15

[ImgAlgos.ImgSaveInFile]
source        = DetInfo(:Cspad2x2)
key           = Image
fname         = cspad2x2
saveAll       = true
#eventSave     = 5

Command to run:
psana -c cspad2x2-test.cfg
One of the saved files cspad2x2-<run>-<timestamp>.txt is plotted as an image by the command
./PlotCameraImageFromFile.py cspad2x2-<run>-<timestamp>.txt 0 1200

Configuration file for cspad2x2 with pedestal subtraction

Access to the CSPad2x2 aligned geometry is added on 2013-02-13
and is available for offline release > ana-0.9.1.

Example of <psana-config-file.cfg>:

[psana]
files    = /reg/d/psdm/mec/mec73313/xtc/e268-r0180-s02-c00.xtc
#calib-dir = ./calib

modules  = cspad_mod.CsPadCalib CSPadPixCoords.CSPad2x2ImageProducer ImgAlgos.ImgSaveInFile
events   = 5

[cspad_mod.CsPadCalib]
source        = DetInfo(MecTargetChamber.0:Cspad2x2.3)
inputKey      = 
outputKey     = calibrated_arr
doPedestals   = yes
doPixelStatus = no
doCommonMode  = no


[CSPadPixCoords.CSPad2x2ImageProducer]
calibDir       = /reg/d/psdm/mec/mec73313/calib
typeGroupName  = CsPad2x2::CalibV1
#source        = DetInfo(MecTargetChamber.0:Cspad2x2.3)
source         = :Cspad2x2.3
inkey          = calibrated_arr
outimgkey      = Image
tiltIsApplied  = true
print_bits     = 15


[ImgAlgos.ImgSaveInFile]
source         = DetInfo(MecTargetChamber.0:Cspad2x2.3)
key            = Image
fname          = cspad2x2.3
saveAll        = true
print_bits     = 3
#eventSave     = 5

Example of psana configuration file to get cspad2x2 images for two detectors and save them in files, one in txt, another in tiff formats:

[psana]
files    = /reg/d/psdm/xpp/xpptut13/xtc/e308-r0008-s02-c00.xtc \
           /reg/d/psdm/xpp/xpptut13/xtc/e308-r0008-s03-c00.xtc

#modules = cspad_mod.CsPad2x2Pedestals

#calib-dir = ./calib
calib-dir = /reg/d/psdm/xpp/xpptut13/xtc/calib

modules  = cspad_mod.CsPadCalib:0 \ 
           cspad_mod.CsPadCalib:1 \ 
           CSPadPixCoords.CSPad2x2ImageProducer:0 \
           CSPadPixCoords.CSPad2x2ImageProducer:1 \ 
           ImgAlgos.ImgSaveInFile:0  \
           ImgAlgos.ImgSaveInFile:1

events   = 5

[cspad_mod.CsPadCalib:0]
source        = DetInfo(XppGon.0:Cspad2x2.0)
inputKey      = 
outputKey     = calibrated_arr0
doPedestals   = yes
doPixelStatus = no
doCommonMode  = yes

[cspad_mod.CsPadCalib:1]
source        = DetInfo(XppGon.0:Cspad2x2.1)
inputKey      = 
outputKey     = calibrated_arr1
doPedestals   = yes
doPixelStatus = no
doCommonMode  = yes


[CSPadPixCoords.CSPad2x2ImageProducer:0]
calibDir         = /reg/d/psdm/xpp/xpptut13/xtc/calib
typeGroupName    = CsPad2x2::CalibV1
source           = DetInfo(XppGon.0:Cspad2x2.0)
inkey            = calibrated_arr0
outimgkey        = Image
tiltIsApplied    = false
useWidePixCenter = false
print_bits       = 15

[CSPadPixCoords.CSPad2x2ImageProducer:1]
calibDir         = /reg/d/psdm/xpp/xpptut13/xtc/calib
typeGroupName    = CsPad2x2::CalibV1
source           = DetInfo(XppGon.0:Cspad2x2.1)
inkey            = calibrated_arr1
outimgkey        = Image
tiltIsApplied    = false
useWidePixCenter = false
print_bits       = 15



[ImgAlgos.ImgSaveInFile:0]
source         = DetInfo(:Cspad2x2.0)
key            = Image
fname          = cspad2x2.0
ftype          = txt
#ftype          = tiff
saveAll        = true
print_bits     = 3
#eventSave     = 5

[ImgAlgos.ImgSaveInFile:1]
source         = DetInfo(:Cspad2x2.1)
key            = Image
fname          = cspad2x2.1
#ftype          = txt
ftype          = tiff
saveAll        = true
print_bits     = 3
#eventSave     = 5

Example for package ImgPixSpectra

See Package ImgPixSpectra

Modules:

  • ImgPixSpectra::CSPadPixSpectra
  • ImgPixSpectra::MiniCSPadPixSpectra
  • ImgPixSpectra::CameraPixSpectra

Configuration file example for MiniCSPadPixSpectra:

[psana]
files         = /reg/d/psdm/<instrument>/<experiment>/<file-name>.xtc
modules       = ImgPixSpectra.MiniCSPadPixSpectra

[ImgPixSpectra.MiniCSPadPixSpectra]
source        = CxiSc1.0:Cspad2x2.0
amin          =   500.
amax          =  1000.
nbins         =   100
arr_fname     = mini-cspad-pix-spectra.txt

To get images from saved file one may execute the auxiliary script:

ImgPixSpectra/data/PlotSpectralArrayFromFile.py mini-cspad-pix-spectra.txt

generates image for limited range of pixels for CSPad, MiniCSPad, or Camera, respectively:

Examples for package ImgAlgos

See Package ImgAlgos

Example for module ImgAlgos::Tahometer

See Module ImgAlgos::Tahometer

Example of the psana configuration file:

[psana]           
files         = /reg/d/psdm/<INSTRUMENT>/<experiment>/xtc/<file-name-1>.xtc\
                /reg/d/psdm/<INSTRUMENT>/<experiment>/xtc/<file-name-2>.xtc

modules       = ImgAlgos.Tahometer

[ImgAlgos.Tahometer]
dn         = 10
print_bits = 7

Example for module ImgAlgos::PnccdImageProducer

See Module ImgAlgos::PnccdImageProducer

Example of the psana configuration file:

[psana]                                                               
files         = /reg/d/psdm/<INSTRUMENT>/<experiment>/xtc/<file-name-1>.xtc\
                /reg/d/psdm/<INSTRUMENT>/<experiment>/xtc/<file-name-2>.xtc
#skip-events = 100
events      =  5
modules = ImgAlgos.PnccdImageProducer ImgAlgos.ImgSaveInFile

[ImgAlgos.PnccdImageProducer]
source        = DetInfo(:pnCCD)
inkey         =
outimgkey     = imgpnccd
print_bits    = 1

[ImgAlgos.ImgSaveInFile]
source        = DetInfo(:pnCCD)
key           = imgpnccd
fname         = pnccd-img-ev
saveAll       = true
#eventSave     = 82
print_bits    = 1

This script saves text files with images like pnccd-img-ev-<run-date-time.nsec>.txt, which can be presented as:

Example for module ImgAlgos::CameraImageProducer

See Module ImgAlgos::CameraImageProducer

Example of the psana configuration file:

[psana]                                                               
files           = /reg/d/psdm/<INSTRUMENT>/<experiment>/xtc/<file-name-1>.xtc
modules         = ImgAlgos.CameraImageProducer ImgAlgos.ImgSaveInFile
events          = 5

[ImgAlgos.CameraImageProducer] 
source          = DetInfo(:Opal1000)
key_in          = 
key_out         = img
subtract_offset = true
print_bits      = 15

[ImgAlgos.ImgSaveInFile]
source        = DetInfo(:Opal1000)
key           = img
fname         = img-from-my-experiment
saveAll       = true
#eventSave     = 1

This script saves text files with images like img-from-my-experiment-<run-date-time.nsec>.txt, which can be drawn by the python script

./ImgAlgos/data/PlotCameraImageFromFile.py <filename>.txt <Amin> <Amax>

Example for module ImgAlgos::PrincetonImageProducer

See Module ImgAlgos::PrincetonImageProducer

Example of the psana configuration file:

[psana]                                                               
files         = /reg/d/psdm/<INSTRUMENT>/<experiment>/xtc/<file-name-1>.xtc\
                /reg/d/psdm/<INSTRUMENT>/<experiment>/xtc/<file-name-2>.xtc
modules       = ImgAlgos.PrincetonImageProducer \
                ImgAlgos.ImgSaveInFile
events          = 3

[ImgAlgos.PrincetonImageProducer] 
source          = DetInfo(:Princeton)
key_in          = 
key_out         = img
subtract_offset = true
print_bits      = 31

[ImgAlgos.ImgSaveInFile]
source        = DetInfo(:Princeton)
key           = img
fname         = img-xcs
saveAll       = true
print_bits    = 31

Example for module ImgAlgos::ImgAverage

See Module ImgAlgos::ImgAverage

The ImgAverage module can be used for evaluation of averaged pedestals or background using dedicated runs. Typical configuration file may looks like this:

[psana]                                                               
files   = /reg/d/psdm/<instrument>/<experiment>/xtc/<file-name>.xtc
modules = ImgAlgos.CameraImageProducer \
          ImgAlgos.ImgAverage
events  = 1000

[ImgAlgos.CameraImageProducer] 
source          = DetInfo(:Opal1000)
key_in          = 
key_out         = img
subtract_offset = true
print_bits      = 1

[ImgAlgos.ImgAverage] 
source          = DetInfo(:Opal1000)
key             = img
avefile         = img-ave.dat
rmsfile         = img-rms.dat
print_bits      = 31
evts_stage1     = 100
evts_stage2     = 100
gate_width1     = 200
gate_width2     = 20

Example for module ImgAlgos::ImgMaskEvaluation

See Module ImgAlgos::ImgMaskEvaluation

Configuration parameters for psana:

[ImgAlgos.ImgMaskEvaluation] 
source          = DetInfo(:Opal1000)
key             = img
file_mask_satu	= img-mask-satu.dat
file_mask_nois	= img-mask-nois.dat
file_mask_comb	= img-mask-comb.dat
file_frac_satu	= img-frac-satu.dat
file_frac_nois	= img-frac-nois.dat
thre_satu   	= 400   
frac_satu       = 0
dr              = 1
thre_SoN        = 3
frac_nois       = 0.05
print_bits      = 63

In this example parameters were chosen in order to get a small number of "noisy" pixel just due to statistics.

Typical image:

Plots for fraction of noisy pixels:

Plots for fraction of saturated pixels:

Masks: noisy, saturated, and combined:

Example for module ImgAlgos::ImgCalib

See Module ImgAlgos::ImgCalib

[ImgAlgos.CameraImageProducer] 
source          = DetInfo(:Opal1000)
key_in          = 
key_out         = img
subtract_offset = true
print_bits      = 1

[ImgAlgos.ImgCalib] 
source          = DetInfo(:Opal1000)
key_in          = img
key_out         = calibrated
fname_peds      = <pedestal-file-name>
fname_mask      = <mask-file-name>
fname_bkgd      = 
fname_gain      = 
print_bits      = 31

Example of the mask file and resulting image:

Example for module ImgAlgos::ImgRadialCorrection

See Module ImgAlgos::ImgRadialCorrection

[psana]
files = /reg/d/psdm/<instrument>/<experiment>/xtc/<file-name-1>.xtc \
        /reg/d/psdm/<instrument>/<experiment>/xtc/<file-name-2>.xtc \
        ...
        /reg/d/psdm/<instrument>/<experiment>/xtc/<file-name-N>.xtc
skip-events = 500
events      = 10
modules = cspad_mod.CsPadCalib \
#         ImgAlgos.CSPadBkgdSubtract \
          CSPadPixCoords.CSPadImageProducer \
          ImgAlgos.ImgRadialCorrection \
          ImgAlgos.ImgSaveInFile:1
 

[cspad_mod.CsPadCalib]
inputKey      = 
outputKey     = calibrated
doPedestals   = yes
doPixelStatus = no
doCommonMode  = no

[ImgAlgos.CSPadBkgdSubtract]
source        = DetInfo(CxiDs1.0:Cspad.0)
inputKey      = calibrated
outputKey     = bkgd_subtracted_arr
bkgd_fname    = <the-file-name-with-background-array>
norm_sector   = 0
print_bits    = 0

[CSPadPixCoords.CSPadImageProducer]
calibDir      = /reg/d/psdm/<instrument>/<experiment>/calib
typeGroupName = CsPad::CalibV1
source        = CxiDs1.0:Cspad.0
key           = calibrated
imgkey        = current_img
#tiltIsApplied = true

[ImgAlgos.ImgRadialCorrection]
source        = DetInfo(CxiDs1.0:Cspad.0)
inkey         = current_img
outkey        = r_cor_img
xcenter       = 866
ycenter       = 857
rmin          = 100
rmax          = 810
n_phi_bins    = 60
event         = 0
print_bits    = 3

[ImgAlgos.ImgSaveInFile:1]
source        = CxiDs1.0:Cspad.0
key           = r_cor_img
fname         = <file-name-for-image-array>
#saveAll       = true
eventSave     = 8

Note: the option of the background subtraction (ImgAlgos.CSPadBkgdSubtract) is commented out in this configuration file . In order to evoke this option, the comment sign (#) should be removed from the list of modules and the key=bkgd_subtracted_arr should be used in CSPadPixCoords.CSPadImageProducer.

Calibrated image and spectrum:

Calibrated and radial-corrected image, spectrum, and subtracted r-phi65 distribution for n_phi_bins=65:

Calibrated and radial-corrected image, spectrum, and subtracted r-phi12 distribution for n_phi_bins=12:

Example for module ImgAlgos::ImgPeakFinder

See Module ImgAlgos::ImgPeakFinder

Configuration file example:

[psana]                                                               
files         = /reg/d/psdm/<instrument>/<experiment>/xtc/<file-name-1>.xtc \
                /reg/d/psdm/<instrument>/<experiment>/xtc/<file-name-2>.xtc \
                ...
                /reg/d/psdm/<instrument>/<experiment>/xtc/<file-name-N>.xtc

modules       = ImgAlgos.ImgPeakFinder PrintSeparator

#skip-events  = 500
events        = 120

[ImgAlgos.ImgPeakFinder] 
source         = DetInfo(:Opal1000)
key            = 
peaksKey       =  peaks
threshold_low  =  20
threshold_high =  50
sigma          =  1.5
smear_radius   =  2
peak_radius    =  3
xmin           =  200
xmax           =  800
ymin           =  100
ymax           =  900
testEvent      =  115
print_bits     =  0
finderIsOn     =  true
  • This algorithm consumes ~15 ms/event on psana0101 for full Opal1000 (1024x1024) camera image.
  • Smearing algorithm use a "safety margin" which is currently set to 10 pixels (offset from each boarder of the full image size).

Image on different stages of this algorithm:

  1. raw image,
  2. image in the window with amplitudes above the threshold_low
    • few peaks at the edges were discarded by the window limits,
    • image still contains many 1-photon pixels, which need to be eliminated,
  3. smeared image,
  4. raw image with found peaks (marked by the red circles)
  5. zoom of the previous plot.

Example for module ImgAlgos::ImgPeakFilter

[ImgAlgos.ImgPeakFilter] 
source         = DetInfo(:Opal1000)
key            = peaks
threshold_peak = 5
threshold_total= 0
n_peaks_min    = 10
print_bits     = 11
fname          = img
selection_mode = SELECTION_ON

Example for module ImgAlgos::ImgPeakFinderAB

See Module ImgAlgos::ImgPeakFinderAB

Configuration file example:

[psana]                                                               
files   = /reg/d/psdm/<instrument>/<experiment>/xtc/<file-name>.xtc
modules = ImgAlgos.CameraImageProducer \
          ImgAlgos.ImgPeakFinderAB
events  = 10

[ImgAlgos.CameraImageProducer] 
source          = DetInfo(:Opal1000)
key_in          = 
key_out         = img
subtract_offset = true
print_bits      = 1

[ImgAlgos.ImgPeakFinderAB]
source                 = DetInfo(:Opal1000)
key                    = img
key_peaks_out          = peaks
#key_signal_out        = signal-arr
#hot_pix_mask_inp_file = ana-misc-exp/mask.dat
#hot_pix_mask_out_file = noise-mask-out.dat
#frac_noisy_evts_file  = noise-frac-out.dat
evt_file_out           = tmp/img-

rmin                =    10
dr                  =     1
SoNThr_noise        =     3
SoNThr_signal       =     3
frac_noisy_imgs     =   0.9
peak_npix_min       =     3
peak_npix_max       =   100
peak_amp_tot_thr    =     0.
peak_SoN_thr        =     4.
event_npeak_min     =     5
event_npeak_max     =  1000
event_amp_tot_thr   =     0.
nevents_mask_update =     0
nevents_mask_accum  =    50
selection_mode      = SELECTION_ON
out_file_bits       =    15
print_bits          =   513

Results:

Example for module ImgAlgos::ImgHitFinder

See Module ImgAlgos::ImgHitFinder

ImgHitFinder in regular mode needs in file with pedestals (offset) to correct the image and file with threshold.
In amo74213 run 93 these files can be obtained directly from data, discarding signal hits as outliers using
ImgAlgos.ImgAverage module as follows with configuration file:

# File: psana-amo74213-r0093-opal-img-average.cfg

[psana]
#files = /reg/d/psdm/AMO/amo74213/xtc/e269-r0093-s05-c00.xtc
files = exp=amo74213:run=93:xtc

modules = ImgAlgos.CameraImageProducer \
          ImgAlgos.ImgAverage
skip-events = 0
events      = 1000

[ImgAlgos.CameraImageProducer] 
source          = DetInfo(:Opal1000)
key_in          = 
key_out         = img
subtract_offset = true
print_bits      = 1

[ImgAlgos.ImgAverage] 
source          = DetInfo(:Opal1000)
key             = img
avefile         = img-ave-for-peds
rmsfile         = img-rms-for-thre
evts_stage1     = 100
evts_stage2     = 100
gate_width1     = 50
gate_width2     = 10
print_bits      = 31

Run psana using command:

psana -c psana-amo74213-r0093-opal-img-average.cfg

At the end of this procedure two files will be created:

  • img-ave-for-peds-r0093.dat - may be used for pedestal subtraction:
  • img-rms-for-thre-r0093.dat - may be used multiplied by number of rms as a threshold:

The file with accumulated hit pixels can be obtained using configuration file:

# File: psana-amo74213-r0093-opal-img-hit-finder.cfg

[psana]
#files = /reg/d/psdm/AMO/amo74213/xtc/e269-r0093-s05-c00.xtc
files = exp=amo74213:run=93:xtc

modules = ImgAlgos.CameraImageProducer \
          ImgAlgos.ImgHitFinder \
          ImgAlgos.ImgAverage
skip-events = 0
events      = 1000

[ImgAlgos.CameraImageProducer] 
source          = DetInfo(:Opal1000)
key_in          = 
key_out         = img
subtract_offset = true
print_bits      = 1

[ImgAlgos.ImgHitFinder] 
source           = DetInfo(:Opal1000)
key_in           = img
key_out          = img_hits
fname_peds       = img-ave-for-peds-r0093.dat
fname_mask       = 
fname_gain       = 
fname_thre       = img-rms-for-thre-r0093.dat
masked_value     = 0
thre_mode        = 3
thre_param       = 5
thre_below_value = 0
thre_above_value = 1
win_row_min      = 10
win_row_max      = 1000
win_col_min      = 10
win_col_max      = 1000
print_bits       = 39

[ImgAlgos.ImgAverage] 
source          = DetInfo(:Opal1000)
key             = img_hits
sumfile         = img-sum-result
#avefile         = img-ave-result
#rmsfile         = img-rms-result
print_bits      = 25

and run it by the command:

psana -c psana-amo74213-r0093-opal-img-hit-finder.cfg

Which creates the file: img-sum-result-r0093.dat (thre_mode = 3):

img-sum-result-r0093.dat (thre_mode = 2):

Example for module ImgAlgos::ImgSpectra

See Module ImgAlgos::ImgSpectra
Configuration file for psana:

[psana]                                                               
files = /reg/d/psdm/<instrument>/<experiment>/xtc/<file-name>.xtc

modules       =  ImgAlgos.CameraImageProducer \
                 ImgAlgos.ImgSpectra \
                 ImgAlgos.ImgSaveInFile:2
#                ImgAlgos.ImgSaveInFile
#                psana_examples.DumpOpal1k \

events          = 100

[ImgAlgos.CameraImageProducer] 
source          = DetInfo(:Opal1000)
key_in          = 
key_out         = img
subtract_offset = true
print_bits      = 1

[ImgAlgos.ImgSpectra] 
source          = DetInfo(:Opal1000)
key_in          = img
key_out         = spectra
sig_band_rowc   = 512.
ref_band_rowc   = 552.
sig_band_tilt   =   0.
ref_band_tilt   =   0.
sig_band_width  =  10 
ref_band_width  =  10 
print_bits      =  3

[ImgAlgos.ImgSpectraProc] 
source          = DetInfo(:Opal1000)
key_in          = spectra
print_bits      =  15

[ImgAlgos.ImgSaveInFile:2]
source        = DetInfo(:Opal1000)
key           = spectra
fname         = spec-xppi0412
saveAll       = true

[ImgAlgos.ImgSaveInFile]
source        = DetInfo(:Opal1000)
key           = img
fname         = img-xppi0412
saveAll       = true

This script can be used in order to produce text files with image and spectral array:

or graphics for several images:

Example for module ImgAlgos::ImgSpectraProc

See Module ImgAlgos::ImgSpectraProc
Configuration file for psana:

[ImgAlgos.ImgSpectraProc] 
source          = DetInfo(:Opal1000)
key_in          = spectra
print_bits      =  15

For each event it prints something similar to:

[info:ImgAlgos.ImgSpectraProc] Spectral array shape =3, 1024
[info:ImgAlgos.ImgSpectraProc] Image spectra for run=0060 Evt=000100
Column:       0     100     200     300     400     500     600     700     800     900    1000
Signal:    1211    4062   11150   17070   16406   12949    7991    5168    3968    3542    3811
Refer.:     933    3485   10425   17128   17791   13522    8315    5000    3390    2967    3193
Diff. :   0.259   0.153   0.067  -0.003  -0.081  -0.043  -0.040   0.033   0.157   0.177   0.176
[info:ImgAlgos.ImgSpectraProc] Run=0060 Evt=000100 Time=20120507-125420.982421325 done...

Example for module ImgAlgos::ImgSaveInFile

modules = ... ImgAlgos.ImgSaveInFile:1 ...

[ImgAlgos.ImgSaveInFile:1]
source         = DetInfo(:Opal1000)   # or CxiDs1.0:Cspad.0
key            = img
fname          = my-img
#ftype          = txt
#ftype          = bin
#ftype          = png
ftype          = tiff
#eventSave     = 5
saveAll        = true

See Module ImgAlgos::ImgSaveInFile

Example for module ImgPeakFinder and ImgPeakFilter for CSPad

Module ImgAlgos::ImgPeakFinder works on image. In order to apply this algorithm to CSPad the image should be produced. In next example the image is produced using consequtive modules cspad_mod.CsPadCalib, ImgAlgos.CSPadMaskApply, and CSPadPixCoords.CSPadImageProducer:

[psana]
files   = /reg/d/psdm/<instrument>/<experiment>/xtc/<file-name-1>.xtc \
          ...
          /reg/d/psdm/<instrument>/<experiment>/xtc/<file-name-N>.xtc

events      =  1000
experiment  = cxii0212
calib-dir   = ana-cxii0212/calib

modules = cspad_mod.CsPadCalib \
          ImgAlgos.CSPadMaskApply \
          CSPadPixCoords.CSPadImageProducer \
          ImgAlgos.ImgPeakFinder \
          ImgAlgos.ImgPeakFilter \
          ImgAlgos.ImgSaveInFile:1

[cspad_mod.CsPadCalib]
inputKey      = 
outputKey     = calibrated
doPedestals   = yes
doPixelStatus = no
doCommonMode  = yes

[ImgAlgos.CSPadMaskApply]
source            = DetInfo(CxiDs1.0:Cspad.0)
inkey             = calibrated
outkey            = masked_arr
mask_fname        = <your-local-directory>/<mask-file-name>.dat
masked_amp        =  0
print_bits        =  5
mask_control_bits = 15

[CSPadPixCoords.CSPadImageProducer]
calibDir       = /reg/d/psdm/<instrument>/<experiment>/calib
typeGroupName  = CsPad::CalibV1
source         = CxiDs1.0:Cspad.0
key            = masked_arr
imgkey         = img
print_bits     =  0
#tiltIsApplied  = true

[ImgAlgos.ImgPeakFinder] 
source         = DetInfo(CxiDs1.0:Cspad.0)
key            = img
peaksKey       = peaks
threshold_low  = 2
threshold_high = 5
sigma          = 1.5
smear_radius   = 5
peak_radius    = 7
xmin           = 20
xmax           = 1700
ymin           = 20
ymax           = 1700
#testEvent      = 5
print_bits     = 3
#finderIsOn     = true

[ImgAlgos.ImgPeakFilter] 
source         = DetInfo(CxiDs1.0:Cspad.0)
key            = peaks
threshold_peak = 5
threshold_total= 0
n_peaks_min    = 10
print_bits     = 11
fname          = cspad-img
selection_mode = SELECTION_ON

[ImgAlgos.ImgSaveInFile:1]
source         = CxiDs1.0:Cspad.0
key            = img
fname          = cspad-img
#eventSave     = 1
saveAll        = true

Example for module ImgAlgos::CSPadArrAverage

See Module ImgAlgos::CSPadArrAverage

Configuration file example for evaluation of pedestals:

[psana]
modules = ImgAlgos.CSPadArrAverage
files   = <path-to-the-dark-run-file>.xtc

[ImgAlgos.CSPadArrAverage]
source  = DetInfo(CxiDs1.0:Cspad.0)
key     =
avefile = cspad-pedestals-ave.dat
rmsfile = cspad-pedestals-rms.dat
print_bits  = 15
evts_stage1 = 100
evts_stage2 = 100
gate_width1 = 100
gate_width2 =  10

Configuration file example for evaluation of background:

[psana]
files       = <path-to-the-background-run-file>.xtc
modules     = cspad_mod.CsPadCalib ImgAlgos.CSPadArrAverage
skip-events = 500
events      = 1000000

[cspad_mod.CsPadCalib]
inputKey      = 
outputKey     = calibrated
doPedestals   = yes
doPixelStatus = no
doCommonMode  = no

[ImgAlgos.CSPadArrAverage]
source  = DetInfo(CxiDs1.0:Cspad.0)
key     = calibrated
avefile = cspad-background-ave.dat
rmsfile = cspad-background-rms.dat
print_bits  = 15

Images of the CSPad arrays for averaged and rms values, respectively, in one of the CXI runs:

Example for module ImgAlgos::CSPadBkgdSubtract

See Module ImgAlgos::CSPadBkgdSubtract

[psana]
files = /reg/d/psdm/<instrument>/<experiment>/xtc/<file-name-1>.xtc \
        /reg/d/psdm/<instrument>/<experiment>/xtc/<file-name-2>.xtc \
        ...
        /reg/d/psdm/<instrument>/<experiment>/xtc/<file-name-N>.xtc
skip-events = 500
events      = 10
modules     = cspad_mod.CsPadCalib ImgAlgos.CSPadBkgdSubtract

[cspad_mod.CsPadCalib]
inputKey      = 
outputKey     = calibrated
doPedestals   = yes
doPixelStatus = no
doCommonMode  = no


[ImgAlgos.CSPadBkgdSubtract]
source        = DetInfo(CxiDs1.0:Cspad.0)
inputKey      = calibrated
outputKey     = bkgd_subtracted
bkgd_fname    = <the-file-name-with-background-array>
norm_sector   = 0
print_bits    = 3

The file with the background array, bkgd_fname, was obtained by averaging 1000 events using module CSPadArrAverage. Subtraction is done with normalization for norm_sector=0.
Event image and pixel amplitude spectrum before and after the background subtraction are shown in plots:

Other event with better subtracted background:

Example for Module ImgAlgos::CSPadMaskApply

See Module ImgAlgos::CSPadMaskApply

The array for mask contains zeros and ones for masked and passed pixels, respectively, and has a shape of full-size CSPad array 4*8*185388.
For example, it can be generated by the command

./MakePixelMask.py <input-background-cspad-arr-file-name> <threshold> <output-file-name> 

for the averaged background amplitude array <input-background-cspad-arr-file-name> abtained as a result of ImgAlgos::CSPadArrAverage module.

Plots show the averaged background, and the mask arrays generated from this background for three thresholds 10, 20, and 30 EDU:

The best results in filtering can be achieved in combination of modiles:

modules = cspad_mod.CsPadCalib \
          ImgAlgos.CSPadBkgdSubtract \
          ImgAlgos.CSPadMaskApply \
          ...
[cspad_mod.CsPadCalib]
inputKey      = 
outputKey     = calibrated_arr
doPedestals   = yes
doPixelStatus = no
doCommonMode  = no

[ImgAlgos.CSPadBkgdSubtract]
source        = DetInfo(CxiDs1.0:Cspad.0)
inputKey      = calibrated_arr
outputKey     = bkgd_subtracted_arr
bkgd_fname    = ana-cxi49012/cspad-cxi49012-r0025-background-ave.dat
norm_sector   = 0
print_bits    = 0

[ImgAlgos.CSPadMaskApply]
source            = DetInfo(CxiDs1.0:Cspad.0)
inkey             = bkgd_subtracted_arr
outkey            = masked_arr
mask_fname        = ana-cxi49012/cspad-cxi49012-r0025-mask-40.dat
masked_amp        =  0
print_bits        =  3
mask_control_bits =  1

where

  • cspad_mod.CsPadCalib - subtracts the pedestals from raw CSPad data,
  • ImgAlgos.CSPadBkgdSubtract - subtracts the background,
  • ImgAlgos.CSPadMaskApply - apply the mask.

In the test with images for background represented by the water and solvent rings this filter provides the background suppression factor about 100.
The background images that still pass this filter have significantly larger intensity with respect to averaged background:

Input parameter mask_control_bits allows to control masking regions of 2x1. For example, if all edges need to be masked, then use mask_control_bits = 15, which gives image array like:

where red regions/lines of pixels of amplitude=8 are masked.

Example for module ImgAlgos::CSPadArrNoise

See Module ImgAlgos::CSPadArrNoise

[psana]
modules = cspad_mod.CsPadCalib ImgAlgos.CSPadArrNoise

files   = /reg/d/psdm/cxi/cxi49012/xtc/e158-r0020-s00-c00.xtc \
          /reg/d/psdm/cxi/cxi49012/xtc/e158-r0020-s01-c00.xtc \
          /reg/d/psdm/cxi/cxi49012/xtc/e158-r0020-s02-c00.xtc \
          /reg/d/psdm/cxi/cxi49012/xtc/e158-r0020-s03-c00.xtc \
          /reg/d/psdm/cxi/cxi49012/xtc/e158-r0020-s04-c00.xtc \
          /reg/d/psdm/cxi/cxi49012/xtc/e158-r0020-s05-c00.xtc

#skip-events = 1000
events      = 10

[cspad_mod.CsPadCalib]
inputKey      = 
outputKey     = calibrated
doPedestals   = yes
doPixelStatus = no
doCommonMode  = no

[ImgAlgos.CSPadArrNoise]
source          = DetInfo(CxiDs1.0:Cspad.0)
key             = calibrated
statusfile      = ana-cxi49012/cspad-cxi49012-r0020-noise-status.dat
maskfile        = ana-cxi49012/cspad-cxi49012-r0200-noise-mask.dat
print_bits      = 255
rmin            = 3
dr              = 1
SoNThr          = 3
frac_noisy_imgs = 0.15

Index map in median algorithm for rmin=3, dr=1:

CSPadArrNoise::printMatrixOfIndexesForMedian():
 0 0 0 0 1 0 0 0 0
 0 0 1 1 1 1 1 0 0
 0 1 0 0 0 0 0 1 0
 0 1 0 0 0 0 0 1 0
 1 1 0 0 + 0 0 1 1
 0 1 0 0 0 0 0 1 0
 0 1 0 0 0 0 0 1 0
 0 0 1 1 1 1 1 0 0
 0 0 0 0 1 0 0 0 0

Pixel status (fraction of events where S/N > SoNThr):

For cspad-cxi49012-r0020 with parameters from confguration file (frac_noisy_imgs=0.15) we get, depending on number of events:

Nnoisy, Ntotal, Nnoisy/Ntotal pixels =94585 2296960 0.041 for 10 events
Nnoisy, Ntotal, Nnoisy/Ntotal pixels =2112 2296960 0.00092 for 100 events

Pixel mask for noisy pixels with |S/N| > SoNThr:

Example for Module ImgAlgos::CSPadArrPeakFinder

See Module ImgAlgos::CSPadArrPeakFinder

[psana]
files   = \
   /reg/d/psdm/cxi/cxi49012/xtc/e158-r0150-s00-c00.xtc \
   /reg/d/psdm/cxi/cxi49012/xtc/e158-r0150-s01-c00.xtc \
   /reg/d/psdm/cxi/cxi49012/xtc/e158-r0150-s02-c00.xtc \
   /reg/d/psdm/cxi/cxi49012/xtc/e158-r0150-s03-c00.xtc \
#   /reg/d/psdm/cxi/cxi49012/xtc/e158-r0150-s04-c00.xtc \ suddenly it became unavailable...
   /reg/d/psdm/cxi/cxi49012/xtc/e158-r0150-s05-c00.xtc

#skip-events = 1000
#events      = 200

modules = cspad_mod.CsPadCalib \
          ImgAlgos.CSPadMaskApply \
          ImgAlgos.CSPadArrPeakFinder

[cspad_mod.CsPadCalib]
inputKey      = 
outputKey     = calibrated
doPedestals   = yes
doPixelStatus = no
doCommonMode  = no

[ImgAlgos.CSPadMaskApply]
source            = DetInfo(CxiDs1.0:Cspad.0)
inkey             = calibrated
outkey            = masked_arr
mask_fname        = ana-cxi49012/cspad-cxi49012-r0150-mask-badregs.dat
#mask_fname        = ana-cxi49012/cspad-cxi49012-r0150-mask-bkgd.dat
#mask_fname        = ana-cxi49012/cspad-cxi49012-r0150-mask-rects.dat
masked_amp        =  8
print_bits        =  1
mask_control_bits = 15

[ImgAlgos.CSPadArrPeakFinder]
source            = DetInfo(CxiDs1.0:Cspad.0)
key               = masked_arr
key_peaks_out     = peaks

hot_pix_mask_inp_file = ana-cxi49012/cspad-cxi49012-r0150-noise-mask.dat
hot_pix_mask_out_file = ana-cxi49012/cspad-cxi49012-r0150-noise-mask-out.dat
frac_noisy_evts_file  = ana-cxi49012/cspad-cxi49012-r0150-noise-frac.dat

evt_file_out      = tmp/cspad-ev-

rmin              =     3
dr                =     1
SoNThr            =     3
frac_noisy_imgs   =   0.1

peak_npix_min     =     4
peak_npix_max     =    25
peak_amp_tot_thr  =   100.

event_npeak_min   =    10
event_amp_tot_thr =  1000.

nevents_mask_update = 100
nevents_mask_accum  =  50

selection_mode    = SELECTION_ON
out_file_bits     =    15
print_bits        =    512

Results:

[info:TimeInterval::startTime] Start time: 2012-06-12 15:32:02
[info:ImgAlgos.CSPadArrPeakFinder]   N processed events = 1000  N selected = 55  Fraction of selected = 0.055
[info:ImgAlgos.CSPadArrPeakFinder]   N processed events = 2000  N selected = 62  Fraction of selected = 0.031
[info:ImgAlgos.CSPadArrPeakFinder]   N processed events = 3000  N selected = 81  Fraction of selected = 0.027
[info:ImgAlgos.CSPadArrPeakFinder]   N processed events = 4000  N selected = 95  Fraction of selected = 0.02375
[info:ImgAlgos.CSPadArrPeakFinder]   N processed events = 5000  N selected = 150  Fraction of selected = 0.03
[info:ImgAlgos.CSPadArrPeakFinder]   N processed events = 6000  N selected = 265  Fraction of selected = 0.0441667
[info:ImgAlgos.CSPadArrPeakFinder]   N processed events = 7000  N selected = 404  Fraction of selected = 0.0577143
[info:ImgAlgos.CSPadArrPeakFinder] ===== JOB SUMMARY =====
[info:TimeInterval::stopTime] Time to process 7945 events is 3747.48 sec, or 0.471678 sec/event

Selected events

ev-007713:

ev-008944:

Example for module ImgAlgos::CSPadArrPeakAnalysis

See Module ImgAlgos::CSPadArrPeakAnalysis

Example of the psana configuration file:

modules = cspad_mod.CsPadCalib \
          ImgAlgos.CSPadMaskApply \
          ImgAlgos.CSPadArrPeakFinder \
          ImgAlgos.CSPadArrPeakAnalysis

# ...configuration parameters of other modules...

[ImgAlgos.CSPadArrPeakAnalysis]
source             = DetInfo(CxiDs1.0:Cspad.0)
key                = peaks
print_bits         = 7
fname_root         = file.root

After execution in psana the file.root containing histogram(s) and ntuple(s) will be produced. Then, auxiliary script in root, running by the commend
root -q -f proc.C
produces the plots with histograms:

Example for TimeStampFilter and XtcOutputModule

This example demonstrates how to run psana with the time stamp filter and event writer in xtc file.
Both modules are available in psana library and they need only to be described in the configuration file. For example, the configuration file tstamp-filter-and-event-writer.cfg may looks like:

[psana]                                                               
files         = /reg/d/psdm/<INSTRUMENT>/<experiment>/xtc/e158-r0021-s00-c00.xtc \
                /reg/d/psdm/<INSTRUMENT>/<experiment>/xtc/e158-r0021-s01-c00.xtc \
                /reg/d/psdm/<INSTRUMENT>/<experiment>/xtc/e158-r0021-s02-c00.xtc \
                /reg/d/psdm/<INSTRUMENT>/<experiment>/xtc/e158-r0021-s03-c00.xtc \
                /reg/d/psdm/<INSTRUMENT>/<experiment>/xtc/e158-r0021-s04-c00.xtc \
                /reg/d/psdm/<INSTRUMENT>/<experiment>/xtc/e158-r0021-s05-c00.xtc

skip-events   = 10
events        = 100
modules       = ImgAlgos.TimeStampFilter  PSXtcOutput.XtcOutputModule 

[PSXtcOutput.XtcOutputModule]
dirName       = ./test_out

[ImgAlgos.TimeStampFilter]
tsinterval    = 2012-02-02 18:17:00.409143728 / 2012-02-02 18:17:00.525853474
filterIsOn    = true
print_bits    = 11

Command to run psana is:
psana -c ./tstamp-filter-and-event-writer.cfg
For this configuration file psana will skip 10 events and loop over the next 100 events from the /reg/d/psdm/<INSTRUMENT>/<experiment>/xtc/e158-r0021-s0*-c00.xtc files and run consecutively modules = ImgAlgos.TimeStampFilter PSXtcOutput.XtcOutputModule. Parameters of these modules are described in the bottom part of the configuration file. Module TimeStampFilter passes events from the specified time interval and prints some useful information. Module XtcOutputModule will write passed events in the file with auto-generated name ./test_out/e158-r0021.xtcf.

See also: Module ImgAlgos::TimeStampFilter and PSXtcOutput::PSXtcOutput

  • No labels