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

Compare with Current View Page History

« Previous Version 12 Next »

Content

Code location

In LCLS software release code of the class RadialBkgd resides in the package pyimgalgos.

Auto-generated documentation for class RadialBkgd

Initialization

from pyimgalgos.RadialBkgd import RadialBkgd
rb = RadialBkgd(xarr, yarr, mask=None, radedges=None, nradbins=100, phiedges=(0,360), nphibins=32)

See parameters' description in Auto-generated documentation for class RadialBkgd.

Input n-d arrays can be obtained through the Detector (AreaDetector) interface or directly through the class working with geometre:

from PSCalib.GeometryAccess import GeometryAccess
geo = GeometryAccess(fname_geo)
xarr, yarr, zarr = geo.get_pixel_coords()
iX, iY = geo.get_pixel_coord_indexes()
mask = geo.get_pixel_mask(mbits=0377) # mask for 2x1 edges, two central columns, and unbound pixels with their neighbours 
...

 

Algorithm

Intention

This algorithm is intended to subtract background from images with quasi-symmetric radial distribution of intensities.

For example, pure water ring background from exp=cxij4716:run=22:

To evaluate background in data, n-d array of data is split for 2-d bins in polar coordinate frame, total intensity and number of involved pixels are counted for each bin and converted to the average bin intensity.

Then this averaged intensity is per-pixel subtracted form data n-d array.

Description

Input per-pixel coordinates passed in numpy arrays xarr, yarr are used to evaluate per-pixel radius and polar angle:

rad = rb.pixel_rad()
phi = rb.pixel_phi()

Binning parameters radedges, nradbins, phiedges, nphibins are used to initialize 2-d bins using class HBins. Initialization with default binning parameters covers entire detector coordinate space.

Non-default binning, for example like

rb = RadialBkgd(X, Y, mask, nradbins=3, nphibins=8, phiedges=(-20, 240), radedges=(10000,80000))

defines angular pixel coordinates with correct offset relative to minimal angle,

and gives 3 bins in radial direction from 10mm to 80mm and 8 bins in angle from -20 to 240 degree:

rad = rb.pixel_rad()
iseq = rb.pixel_iseq()

Pixels masked by the n-d array passed in the parameter mask are excluded from this algorithm and are not corrected.

Averaged background intensity for default and non-default binning cases (nphibins=8, nradbins=500):

bkgd = rb.bkgd_nda(nda)

Background subtraction

Background subtracted data for default (nradbins=100, nphibins=32) and non-default binning cases (nradbins=500, nphibins=1), and (nradbins=500, nphibins=8, phiedges=(-20, 240)):

res = rb.subtract_bkgd(nda)

Polarization correction

  • For good statistical precision of the background averaging 2-d bins should contain large number of pixels. However large bins produces significant binning artifacts which are seen in resulting image.
  • The main reason for angular bins is a variation of intensity with angle due to polarization effect. The beam polarization effect can be eliminated with appropriate correction.
  • Method for polarization correction factor:

    def polarization_factor(rad, phi_deg, z) :
        """Returns per-pixel polarization factors, assuming that detector is perpendicular to Z.
        """
        phi = np.deg2rad(phi_deg)
        ones = np.ones_like(rad)
        theta = np.arctan2(rad, z)
        pol = 1 - np.sqrt(np.fabs(np.sin(theta)*np.cos(phi)))
        return divide_protected(ones, pol, vsub_zero=0)


    Then, radial background can be estimated for a single angular bins (ring-shaped radial bins):

pf = polarization_factor(rb.pixel_rad(), rb.pixel_phi(), z)
res = rb.subtract_bkgd(nda * pf)

For z=1m we get polarization correction factor, corrected data (water-ring) sample, and background subtracted data as follows.

 

Effect of polarization is somehow accounted, but most likely the sample-to-detector distance 1m is not correct.

 

The data set exp=cxij4716:run=22 was collected at sample-to-detector distance z=94mm. In this case polarization correction formula gives distribution for correction factor and "corrected" data averaged over all 14636 events:

 

So, it looks like polarization correction formula is wrong

 

 

CSPAD "dopping" artifacts

arr = load_txt(fname_nda)
rb = RadialBkgd(X, Y, mask, nradbins=500, nphibins=1)
pf = gu.reshape_to_2d(polarization_factor(rb.pixel_rad(), rb.pixel_phi(), 0.5e6))
nda = rb.subtract_bkgd(arr * pf) * mask.flatten()

Polarization corrected, radial background subtracted image, array spectra, and zoomed parts of the image with potential artifact candidates:

References

 

  • No labels