Versions Compared

Key

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

This script lives in /reg/g/psdmsdf/group/lcls/ds/ana/tutorials/examplePython3psana1_examples/radInteg.py and demonstrates how to do an angular integration of a 2D area-detector image.  If you don't have a 2D image, but instead have pixel values and positions, consider using the more general BinnedStatistic1D/BinnedStatistic2D/BinnedStatisticDD classes in skbeam.core.accumulators.binned_statistic (not documented here, but documentation is available within within IPython).

This method for doing radial integrations is part of the world-reusable scikit-beam project hosted by BNL.  This goal of this python library is to provide low-level building-blocks that can be easily installed around the world enabling scientists to reuse familiar tools at different laboratories.

...

Code Block
from skbeam.core.accumulators.binned_statistic import RadialBinnedStatistic, RPhiBinnedStatistic
import numpy as np
img = np.reshape(np.arange(9),(3,3))
print ('Image:\n',img)
mask = np.ones_like(img)
mask[1][1]=0
print(f'\nMask:\n{mask}')
radbinstat = RadialBinnedStatistic(img.shape, bins=3,
                                   statistic='sum',
                                   origin=(0,0),
                                   range = (0,2),
                                   mask=mask)
rphibinstat = RPhiBinnedStatistic(img.shape, bins=(3,1),
                                  statistic='sum',
                                  origin=(0,0),
                                  range = ((0,2),(0,np.pi/3)))
rphibinstat_mask = RPhiBinnedStatistic(img.shape, bins=(3,1),
                                       statistic='sum',
                                       origin=(0,0),
                                       range = ((0,2),(0,np.pi/3)),
                                       mask=mask)
print('\nAngular integration with mask:')
print(radbinstat(img))
print('\nBin edges and centers:')
print(radbinstat.bin_edges)
print(radbinstat.bin_centers)
print('\n2D R/Phi Angular integration (1 phi bin) with phi range and mask:')
print(rphibinstat_mask(img))
print('\n2D R/Phi Angular integration (1 phi bin) with phi range and no mask:')
print(rphibinstat(img))
print('\nR/Phi bin edges:')
print(rphibinstat.bin_edges[0])
print(rphibinstat.bin_edges[1])

...