Page History
...
source
(default: "DetInfo(SxrBeamline.0:Opal1000.1)" ) – source of data for Opal camera
orsource
(default: "DetInfo(:Princeton)" ) – source of data for Princeton camera
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. For example, the command
generates image for limited range of pixels for CSPad, MiniCSPad, or Camera, respectively:Code Block ImgPixSpectra/data/PlotSpectralArrayFromFile.py mini-cspad-pix-spectra.txt
SpectralArray.py
- provides access to the spectral array stored in the file. Theclass SpectralArray
defined in this script is used in thePlotSpectralArrayFromFile.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 theget_list_of_input_file_names()
method. The output file name,out_fname
, is also hardwired in the call tospectra_merging(out_fname)
.
Package ImgAlgos
This packages contains a few psana
modules for image processing
Module ImgAlgos::CSPadCommonModeCorrection
See also Example for Package ImgPixSpectra.
Package ImgAlgos
This packages contains a few psana
modules for image processing
Module ImgAlgos::CSPadCommonModeCorrection
Alternative to the cspad_mod.CsPadCalib
algorithm for the common mode correction.
Takes the CSPad data array with subtracted pedestals, evaluate the average amplitude for each 2x1 section for amplitudes below the threshold, and subtract it from all pixel amplitudes. This algorithm consumes about 30 ms/event on psana0205.
Module configuration parameters:
source
(default: "DetInfo(:Cspad)" ) – source of data for CSPadinputKey
(default: "calibrated" ) – key for input data, by default expects data fromcspad_mod.CsPadCalib
outputKey
(default: "cm_subtracted" ) – output key for the next data processing stageampthr
(default: 30 ) – threshold to exclude the large pixel amplitudes in average
Module ImgAlgos::ImgPixAmpFilter
The ImgAlgos::ImgPixAmpFilter is a filter for event selection.
This filter counts the number of image pixels in the specified window with amplitude exceeding the threshold
. If the number of high-amplitude pixels exceed the numPixMin
, the event is passed for further analysis.
The algorithm performance was tested for CSPad images. This algorithm consumes up to 15 ms/event on psana0205 for full CSPad (1650x1650) window size. For smaller window consumed time is negligible, comparing to the image reconstruction time, which is ~70 ms/event (for cspad_mod.CsPadCalib
and CSPadPixCoords::CSPadImageProducer
) Alternative to the cspad_mod.CsPadCalib
algorithm for the common mode correction.
Takes the CSPad data array with subtracted pedestals, evaluate the average amplitude for each 2x1 section for amplitudes below the threshold, and subtract it from all pixel amplitudes. This algorithm consumes about 30 ms/event on psana0205.
Module configuration parameters:
source
(default: "DetInfo(:Cspad)") – source of data for CSPadinputKey
key
(default: "calibratedImage2D") – key for input image data, by default expects data fromcspad_mod.CsPadCalib
outputKey
(default: "cm_subtracted" ) – output key for the next data processing stageampthr
(default: 30 ) – threshold to exclude the large pixel amplitudes in average
Module ImgAlgos::ImgPixAmpFilter
The ImgAlgos::ImgPixAmpFilter is a filter for event selection.
This filter counts the number of image pixels in the specified window with amplitude exceeding the threshold
. If the number of high-amplitude pixels exceed the numPixMin
, the event is passed for further analysis.
The algorithm performance was tested for CSPad images. This algorithm consumes up to 15 ms/event on psana0205 for full CSPad (1650x1650) window size. For smaller window consumed time is negligible, comparing to the image reconstruction time, which is ~70 ms/event (for cspad_mod.CsPadCalib
and CSPadPixCoords::CSPadImageProducer
) on psana0205.
Module configuration parameters:
source
(default: "DetInfo(:Cspad)") – source of datakey
(default: "Image2D") – key for input image datathreshold
(default: 10) – minimal threshold on pixel amplitudenumPixMin
(default: 100) – minimal number of pixels with amplitude above the thresholdfilterIsOn
(default: true) – On/Off the filterxmin
(default: 0) – minimal column numberxmax
(default: 100000) – maximal column numberymin
(default: 0) – minimal row numberymax
(default: 100000) – maximal row numberprint_bits
(default: 0) – verbosity:- =0 - print nothing,
- +1 - input pars,
- +2 - summary,
- +4 - per event number of pixels above the threshold
- +8 - event ID.
Remarks:
- The default
key
("Image2D") stands for theCSPadPixCoords::Image2D<double>
image object. Otherkey
names work for thendarray<double,2>
image object. - The
xmin
,xmax
,ymin
,ymax
(in pixels) defines the window in the image for pixel counting. Default values means the entire image range. - The
threshold
,numPixMin
, and the window extents have to be adjusted for particular experiment.
Module ImgAlgos::ImgPeakFinder
This algorithm was motivated by users of amo42112:
1. Select the pixels in the window xmin
, xmax
, ymin
, ymax
with amplitudes above the threshold_low
.
2. Smear image for selected pixels, using 2-d matrix of weights over pixels
from -smear_radius
to +smear_radius
around each smeared pixel amplitude.
The matrix of weights is defined by the 2-d Gaussian function of width sigma
.
3. Find peaks as pixels with absolute-maximal amplitude above the threshold_high
in the center of the matrix -peak_radius
to +peak_radius
.
4. Put the vector of found peaks in the event with key peaksKey
. Each entry of this vector has an object of the struct Peak
, containing x, y positions, peak pixel amplitude, the total amplitude in the matrix, defined by the peak_radius
, and the number of pixels in the matrix above threshold_low
:
threshold
(default: 10) – minimal threshold on pixel amplitudenumPixMin
(default: 100) – minimal number of pixels with amplitude above the thresholdfilterIsOn
(default: true) – On/Off the filterxmin
(default: 0) – minimal column numberxmax
(default: 100000) – maximal column numberymin
(default: 0) – minimal row numberymax
(default: 100000) – maximal row numberprint_bits
(default: 0) – verbosity:- =0 - print nothing,
- +1 - input pars,
- +2 - summary,
- +4 - per event number of pixels above the threshold
- +8 - event ID.
Remarks:
- The default
key
("Image2D") stands for theCSPadPixCoords::Image2D<double>
image object. Otherkey
names work for thendarray<double,2>
image object. - The
xmin
,xmax
,ymin
,ymax
(in pixels) defines the window in the image for pixel counting. Default values means the entire image range. - The
threshold
,numPixMin
, and the window extents have to be adjusted for particular experiment.
Module ImgAlgos::ImgPeakFinder
This algorithm was motivated by users of amo42112:
1. Select the pixels in the window xmin
, xmax
, ymin
, ymax
with amplitudes above the threshold_low
.
2. Smear image for selected pixels, using 2-d matrix of weights over pixels
from -smear_radius
to +smear_radius
around each smeared pixel amplitude.
The matrix of weights is defined by the 2-d Gaussian function of width sigma
.
3. Find peaks as pixels with absolute-maximal amplitude above the threshold_high
in the center of the matrix -peak_radius
to +peak_radius
.
4. Put the vector of found peaks in the event with key peaksKey
. Each entry of this vector has an object of the struct Peak
, containing x, y positions, peak pixel amplitude, the total amplitude in the matrix, defined by the peak_radius
, and the number of pixels in the matrix above threshold_low
:
Code Block |
---|
struct Peak{
double x;
double y;
double ampmax; // amplitude in the peak masimum
double amptot; // total amplitude in the range of {{peak_radius}}
unsigned npix; // number of pixels in the range |
Code Block |
struct Peak{ double x; double y; double ampmax; // amplitude in the peak masimum double amptot; // total amplitude in the range of {{peak_radius}} unsigned npix; // number of pixels in the range of {{peak_radius}} } ; |
Module configuration parameters:
...
- 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:
- raw image,
- 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,
- smeared image,
- raw image with found peaks (marked by the red circles)
- zoom of the previous plot.
See also Example for Module ImgAlgos::ImgPeakFinder.
Module Module ImgAlgos::ImgPeakFilter
This module use results and should work after the ImgAlgos::ImgPeakFinder
.
It gets the vector of peaks for the source
and key
, loops over all founded peaks and counts the number of peaks above the thresholds threshold_peak
and threshold_total
. If the filterIsOn
is "on" ("true" or "yes" state) and the number of found peaks exceeds the n_peaks_min
the event is passed for further analysis/processing.
...
- If the
first
and/orlast
event numbers are defined, then the filter will select events in this range only. - If the
evtstring
is defined, only listed events of event ranges will be selected. For example, theevtstring
parameter can be defined as
that means the list of events:Code Block 2,5,11-15,20-25,29,30
In theCode Block 2 5 11 12 13 14 15 20 21 22 23 24 25 29 30
evtstring
parameter the comma "," and sign minus "-" as a dash are the only allowed separators. Blank spaces are also allowed. Other characters may abort the program. Theevtstring
mode has higher priority than the 1st mode.
ThefilterIsOn
allows easy turn on/off this filter in*.cfg
file.
Auxiliary scripts for ImgAlgos package
A few auxiliary scripts for example are located in the directory ImgAlgos/data
:
psana.cfg
- set non-default parameters to runpsana
forImgAlgos::ImgPeakFinder
andImgAlgos::ImgPeakFilter
Thepsana
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.
Module ImgAlgos::CSPadArrAverage
Module ImgAlgos::CSPadArrAverage
Wiki Markup |
---|
Wiki Markup |
This module averages the CSPad data array and saves two files for averaged and rms values in CSPad format \[5920=4*8*185\]\[388\]. In contrast to the [cspad_mod.CsPadPedestals|PCDS:Psana Module Catalog#Modulecspadmod.CsPadPedestals], the input data can be specified with a {{key}}, that allows to average CSPad array for already pre-processed data, for example {{"calibrated"}}. This feature can be used to evaluate the averaged signal or background event. Implemented algorithm of averaging allows to eliminate large statistical fluctuations in the pixel amplitude spectrum. In advanced case averaging may have up to three stages, depending on configuration parameters: |
...
Default version of the configuration parameters works the same way as cspad_mod.CsPadPedestals. In this case module gets raw events and stage 0 continues for entire input data sample.
Example of the configuration file for evaluation of pedestals:
Code Block |
---|
[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
|
Example of the configuration file for evaluation of background:
Code Block |
---|
[psana]
modules = cspad_mod.CsPadCalib ImgAlgos.CSPadArrAverage
files = <path-to-the-background-run-file>.xtc
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
|
See also Example for Module ImgAlgos::CSPadArrAverage.Images of the CSPad arrays for averaged and rms values, respectively, in one of the CXI runs:
Module ImgAlgos::CSPadBkgdSubtract
...
source
(default: "DetInfo(:Cspad)") – input source of datainputKey
(default: " " ) – key for input data, by default use raw dataoutputKey
(default: "bkgd_subtracted" ) – output key for the next data processing stageWiki Markup {{bkgd_fname}} (default: "cspad_background.dat" ) -- file with CSPad array \[4*8*185\]\[388\] of averaged background
norm_sector
(default: 0) – CSPad sector in quad from 0 to 7print_bits
(default: 0) – module verbosity:- =0 - print nothing,
- +1 - input pars,
- +2 - event ID,
- +4 - normalization factor for each event,
- +8 - part of the background array.
...
- of
...
- the background array.
See also Example for Module ImgAlgos::CSPadBkgdSubtract.
...
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:
Module ImgAlgos::ImgRadialCorrection
...
source
(default: "DetInfo()") – input source of datainkey
(default: " " ) – key for input data, by default use raw dataoutkey
(default: "rad_corrected" ) – output key for further image processingxcenter
(default: 850) – x coordinate of the image centerycenter
(default: 850) – y coordinate of the image centerrmin
(default: 10) – radius minimal image is not processed for r<rminrmax
(default:1000) – radius maximal image is not processed for r>rmaxn_phi_bins
(default: 12) – number of angular sectors for the background averaging.event
(default: 0) – test event for print/saveprint_bits
(default: 0) – module verbosity:- =0 - print nothing,
- +1 - input pars,
- +2 - summary,
- +4 - event ID,
- +8 - info about input image type (ndarray<double,2> or Image2D<double>).
Example of the module application
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:
See also Example for Module ImgAlgos::ImgRadialCorrection.