Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Matrices of pixels for r0=3 and 4 and different dr values

Code Block
titler0=3, dr=0.1 and r0=4 dr=0.2 examples
collapsetrue
r0=3  dr=0.1 (4 pixels)   r0=3  dr=0.5 (12 pixels)   r0=3  dr=1 (24 pixels) 
0 0 0 0 0 0 0 0 0         0 0 0 0 0 0 0 0 0          0 0 0 0 1 0 0 0 0       
0 0 0 0 1 0 0 0 0         0 0 0 1 1 1 0 0 0          0 0 1 1 1 1 1 0 0       
0 0 0 0 0 0 0 0 0         0 0 0 0 0 0 0 0 0          0 1 0 0 0 0 0 1 0       
0 0 0 0 0 0 0 0 0         0 1 0 0 0 0 0 1 0          0 1 0 0 0 0 0 1 0       
0 1 0 0 + 0 0 1 0         0 1 0 0 + 0 0 1 0          1 1 0 0 + 0 0 1 1       
0 0 0 0 0 0 0 0 0         0 1 0 0 0 0 0 1 0          0 1 0 0 0 0 0 1 0       
0 0 0 0 0 0 0 0 0         0 0 0 0 0 0 0 0 0          0 1 0 0 0 0 0 1 0       
0 0 0 0 1 0 0 0 0         0 0 0 1 1 1 0 0 0          0 0 1 1 1 1 1 0 0       
0 0 0 0 0 0 0 0 0         0 0 0 0 0 0 0 0 0          0 0 0 0 1 0 0 0 0

r0=4  dr=0.2 (12 pixels)   r0=4  dr=0.3 (16 pixels)    r0=4  dr=0.5 (24 pixels)
0 0 0 0 0 0 0 0 0 0 0      0 0 0 0 0 0 0 0 0 0 0       0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 1 0 0 0 0      0 0 0 0 1 1 1 0 0 0 0       0 0 0 1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0      0 0 1 0 0 0 0 0 1 0 0       0 0 1 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0 0      0 0 0 0 0 0 0 0 0 0 0       0 1 0 0 0 0 0 0 0 1 0
0 1 0 0 0 0 0 0 0 1 0      0 1 0 0 0 0 0 0 0 1 0       0 1 0 0 0 0 0 0 0 1 0
0 1 0 0 0 + 0 0 0 1 0      0 1 0 0 0 + 0 0 0 1 0       0 1 0 0 0 + 0 0 0 1 0
0 1 0 0 0 0 0 0 0 1 0      0 1 0 0 0 0 0 0 0 1 0       0 1 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0 0      0 0 0 0 0 0 0 0 0 0 0       0 1 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0 0      0 0 1 0 0 0 0 0 1 0 0       0 0 1 0 0 0 0 0 1 0 0
0 0 0 0 1 1 1 0 0 0 0      0 0 0 0 1 1 1 0 0 0 0       0 0 0 1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0      0 0 0 0 0 0 0 0 0 0 0       0 0 0 0 0 0 0 0 0 0 0 

Matrices of pixels for r0=5 and 6 and different dr values

Code Block
titler0=5, dr=0.05 and r0=6, dr=0.2 examples
collapsetrue
r0=5  dr=0.05 (12 pixels)      r0=5  dr=0.5  (28 pixels)            
0 0 0 0 0 0 0 0 0 0 0 0 0      0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0 0 0      0 0 0 0 1 1 1 1 1 0 0 0 0
0 0 0 1 0 0 0 0 0 1 0 0 0      0 0 0 1 0 0 0 0 0 1 0 0 0
0 0 1 0 0 0 0 0 0 0 1 0 0      0 0 1 0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0      0 1 0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0      0 1 0 0 0 0 0 0 0 0 0 1 0
0 1 0 0 0 0 + 0 0 0 0 1 0      0 1 0 0 0 0 + 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0      0 1 0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0      0 1 0 0 0 0 0 0 0 0 0 1 0
0 0 1 0 0 0 0 0 0 0 1 0 0      0 0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0 0 0     0 0 0 0 0 1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0     0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Matrix of pixels for r0=7

Code Block
titler0=7, dr=2 example
collapsetrue
 r0=7  dr=2 (108 pixels)   
 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0
 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0
 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0
 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0
 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0
 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
 1 1 1 0 0 0 0 0 0 + 0 0 0 0 0 0 1 1 1
 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0
 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0
 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0
 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0
 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0

...

Code Block
# Import
import psana

# Initialize a detector object
det = psana.Detector(detInfo, env'myAreaDetectorName')
# Merges photons split among pixels and returns n-d array with integer number of photons per pixel.
nphotons_nda = det.photons(evt, adu_per_photon, nda_calib=None, mask=None, adu_per_photon=None)

The det.photons() function divides the pixel intensities (ADUs) by adu_per_photon, resulting in a fractional number of photons for each pixel. This function is a wrapper around photons() method in PyAlgos:

Code Block
# Import
from ImgAlgos.PyAlgos import photons

# Merges photons split among pixels and returns n-d array with integer number of photons per pixel.
nphotons_nda = photons(fphotons, maskadu_per_photon=30)

Sphinx doc

Method photons receives (float) n-d numpy array fphotons representing image intensity in terms of (float) fractional number of photons and an associated mask of bad pixels. Both arrays should have the same shape. Two lowest dimensions represent pixel rows and columns in 2-d pixel matrix arrays. Algorithm works with good pixels defined by the mask array (1/0 = good/bad pixel).  Array fphotons is represented with two arrays; An array containing whole number of photons (integer) and the leftover fractional number of photon array (float) of the same shape. Assuming the photons are only split between two adjacent pixels, we round up the adjacent pixels if they sum up to be above 0.9 photons. The algorithm is best explained using an example:

Let's say we measured the following ADUs on our detector. "adu_per_photon" is user-defined, but for this example let's set it to 1:

Code Block
ADUs (adu_per_photon=1):
0.0 3.5 0.1 0.2    
0.2 0.4 0.0 1.2
0.1 4.7 3.4 0.0
0.5 0.4 0.4 0.1    

...

To see how we get from ADUs to Photons, we split the ADUs into whole photons and fractional photons.

Code Block
ADUs               =  Whole photons   +    Fractional photons
 
Whole photons0.0 3.5 0.1 0.2     +    Fractional photons
0 3 0 0                0.0 0.5 0.1 0.2   
0.2 0.4 0.0 1.2    =     0 0 0 1    0.2 0.4  +       0.2 0.4 0.0 0.2
0.1 4.7 3.4 0.0          0 4 3 0              0.1 0.7 0.4 0.0
0.5 0.4 0.4 0.1          0 0 0 0              0.5 0.4 0.4 0.1

Assuming the photons are only split by two adjacent pixels, we search for a pixel that has at least 0.5 photons with an adjacent pixel that sum up to above 0.9 photons. In cases where a pixel has multiple adjacent pixels which sum up to above 0.9 photons, we take the largest adjacent pixel. If such an adjacent pair of pixels is found, then the adjacent pixel values are merged into one pixel. It is merged into the pixel with the larger value. (See "After merging adjacent pixels" example below).

...

Code Block
Fractional photons
0.0 0.5 0.1 0.2
0.2 0.4 0.0 0.2
0.1 0.7 0.4 0.0
0.5 0.4 0.4 0.1
 
After merging adjacent pixels:
0.0 0.9 0.1 0.02
0.2 0.0 0.0 0.02
0.1 1.1 0.0 0.0
0.9 0.0 0.4 0.1

Rounded whole photons:
0 1 0 0
0 0 0 0
0 1 0 0
1 0 0 0

...

References