Page History
Content
Table of Contents |
---|
Example for module NDArrDropletFinder
See description of the module in Module ImgAlgos::NDArrDropletFinder
...
which defines parameters of a few modules with functionality as follows.
Script functionality
CSPadPixCoords.CSPad2x2NDArrProducer
- get raw data forXppGon.0:Cspad2x2.0
and put them in the event store as ndarray with keynda_raw
ImgAlgos.NDArrCalib
- get ndarray with keynda_raw
, applies a bunch of intensity corrections, and saves in the event store the ndarray with keynda_clb:as_data
CSPadPixCoords.CSPad2x2NDArrReshape
- re-shuffle cspad2x2 pixels shaped as data [185,388,2] to "natural" ndarray format [2,185,388]ImgAlgos.NDArrDropletFinder
- gets calibrated and shaped as two 2-d segments ndarraynda_clb
, applies smearing (ifsigma
>0), find droplets (wide peaks), and saves them in the event store and in the file (iffname_prefix
is not empty).
Remarks about parameters
- For each new set of smearing parameters (if applied,
sigma
>0) the droplet-finder parameters need to be re-tuned. - Number of windows per sensor is unlimited but the should not overlap each other in order to get rid of duplication of found peaks in the overlapping regions.
- Parameter
low_value = −0.1
is set for demonstration purpose - in order to distinguish on plot sensors' pixels from image bins. - Parameter
fname_prefix = test
is set in demonstration purpose in order to save image and peak data files for browser
Running script with psana
This file can be executed by the command
...
This job generates a bunch of files for all events with names like test-xppd7114-r0081-e000006-<suffix>.txt
, where <suffix>
stands for raw
(data), smeared
(if requested), and peaks
. Using browser ImgAlgos/data/PlotNDArrayAndPeaks.py launched by the command (from release directory):
Code Block |
---|
ImgAlgos/data/PlotNDArrayAndPeaks.py -i test-xppd7114-r0081-e000009-smeared.txt
### or ###
ImgAlgos/data/PlotNDArrayAndPeaks.py -i test-xppd7114-r0081-e000009-raw.txt |
one may get images like:
Fig.1: Image of cspad2x2, containing two 2x1 segments. Droplet-finder is applied to the calibrated and smeared data in three windows.
Format of the ndarray of droplets
Content of the record for each droplet is defined by the structure of six components
...
Code Block |
---|
0 127 137 5.01175 60.1614 20 0 129 166 4.55816 52.7998 20 0 155 131 4.09197 48.5101 20 1 105 17 3.65102 17.5217 6 1 145 49 3.87695 30.5501 15 1 116 249 3.07719 20.5181 11 1 139 325 3.60641 60.2324 27 ... |
Access droplet data in python
Example of the python script psana-xppd7114-r0081-cspad2x2-NDArrDropletFinder.py
:
Code Block |
---|
#!/usr/bin/env python import sys import numpy as np import psana psana.setConfigFile('psana-xppd7114-r0081-cspad2x2-NDArrDropletFinder.cfg') dsname = 'exp=xppd7114:run=81' print """Data source: %s""" % dsname ds = psana.DataSource(dsname) evnum_max = 50 #------------------------------ for evnum, evt in enumerate(ds.events()) : evtid = evt.get(psana.EventId) if evnum > evnum_max : break nda_droplets = evt.get(psana.ndarray_float32_2, psana.Source('DetInfo(XppGon.0:Cspad2x2.0)'), 'nda_droplets') nda_smeared = evt.get(psana.ndarray_float64_3, psana.Source('DetInfo(XppGon.0:Cspad2x2.0)'), 'nda_sme') nda_calibrated = evt.get(psana.ndarray_float64_3, psana.Source('DetInfo(XppGon.0:Cspad2x2.0)'), 'nda_clb') print print 50*'=', '\nEvent: %d' % evnum if (nda_smeared is not None) : print 'nda_smeared.shape = ', nda_smeared.shape if (nda_calibrated is not None) : print 'nda_calibrated.shape = ', nda_calibrated.shape if (nda_droplets is not None) : print 'nda_droplets.shape = ', nda_droplets.shape for droplet in nda_droplets : seg, row, col, amax, atot, npix = droplet print ' seg:%2d row:%3d col:%3d amax:%8.1f atot:%8.1f npix:%2d' % \ (seg, row, col, amax, atot, npix) |
...
In order to eliminate too excessive printout from psana modules, set parameters print_bits = 0
or 1 in the configuration file.
Get latest version (if needed)
.
Examples for exp=cxif5315:run=165
Example 1
Shows how to get ndarray with CSPAD data in psana, calibrate it, find peaks (droplets) in imaging data and plot them offline.
Configuration file: psana-cxif5315-r0165-cspad-ds2-NDArrDropletFinder.cfg
ROI Mask: roi_mask_nda.txt
Command to run job:
Code Block |
---|
psana -c psana-cxif5315-r0165-cspad-ds2-NDArrDropletFinder.cfg |
Command to see results:
Code Block |
---|
ImgAlgos/data/PlotNDArrayAndPeaks.py -g /reg/d/psdm/CXI/cxif5315/calib/CsPad::CalibV1/CxiDs2.0:Cspad.0/geometry/1-end.data -i test-cxif5315-r0165-e000001-raw.txt |
Example 2
Shows how to get ndarray with CSPAD data in psana, calibrate it, prepare and apply mask, find peaks (droplets) in imaging data and plot them offline.
Configuration file: psana-cxif5315-r0165-cspad-ds2-NDArrDropletFinder-v2.cfg
ROI Mask: roi_mask_nda-v2.txt is produced in calibman (tab ROI
):
image without mask for event 10:(dark is subtracted).
mask production stages in the mask editor:
Use this mask-ndarray roi_mask_nda-v2.txt in the NDArrDropletFinder with additional list of segment windows:
Code Block |
---|
windows = 0 0 185 0 388 \
1 0 185 0 388 \
8 0 185 0 388 \
9 0 185 0 388 \
16 0 185 0 388 \
17 0 185 0 388 \
24 0 185 0 388 \
25 0 185 0 388 |
which contains 8 closest to the beam 2x1 sensors.
Command:
Code Block |
---|
psana -c psana-cxif5315-r0165-cspad-ds2-NDArrDropletFinder-v2.cfg |
produces files with image and list of peaks for all requested events, which can be viewed by the command
Code Block |
---|
ImgAlgos/data/PlotNDArrayAndPeaks.py -g /reg/d/psdm/CXI/cxif5315/calib/CsPad::CalibV1/CxiDs2.0:Cspad.0/geometry/1-end.data -i test-cxif5315-r0165-e000001-raw.txt |
This viewer shows images like:
Example 3
Example 3 has the same functionality as Example 2. Also this example shows how to
- gets raw ndarray with CSPAD data, subtract pedestals and background, apply common mode correction, apply mask, find peaks,
- access psana data structures from the python script,
- reconstruct CSPAD image,
- apply selection to the list of droplets and make the list of "bold" beaks,
- skip events without "bold" peaks,
- and interactively plot images with overlayed peaks.
file with mask: roi_mask_nda_v3.txt
file with background: bkgd-cxif5315-r0165.dat obtained by averaging calibrated ndarray with module ImgAlgos.NDArrAverage over 1000 events:
psana configuration file: psana-cxif5315-r0165-cspad-ds2-NDArrDropletFinder-v3.cfg - download
python script for interactive psana: psana-cxif5315-r0165-cspad-ds2-NDArrDropletFinder-v3.py.txt - download
Interactive job can be launched by the command:
Code Block |
---|
python psana-cxif5315-r0165-cspad-ds2-NDArrDropletFinder-v3.py |
- which does all work and plots images with peaks like - background is not subtracted, or - background is subtracted
Get latest version
Release ana-current (ana-0.13.18 or later) has the latest version of all necessary packages.
In case of any packages updates relative to the current release, the new version of the code can be tested from local release directory (test_release_directory
)Until the psana release > ana-0.13.13 is created, one has to work from local release directory:
Code Block |
---|
ssh psana kinit cd <one-of-your-directories> newrel ana-current test_release_directory cd test_release_directory sit_setup addpkg ImgAlgos HEAD addpkg pdscalibdata HEAD addpkg PSCalib HEAD addpkg CSPadPixCoords<other-package-name> HEAD scons ... psana -c psana-xppd7114-r0081-cspad2x2-NDArrDropletFinder.cfg |
Note |
---|
Packages PSCalib and CSPadPixCoords need to be added because they have been modified on the top of ana-0.13.13 release. They need to be compiled together due to dependency between packages. |
References