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

Compare with Current View Page History

« Previous Version 27 Next »

This script lives in /reg/g/psdm/tutorials/examplePython/areaDetAccess.py and demonstrates how to access calibrated "unassembled data" (3D array, no geometry applied) and "assembled images" (2D array, geometry applied).  Assembled/unassembled are only different for multi-panel detectors.  For monolithic 2D area detectors they are the same.

NOTE: there are many other python methods of the Detector object for Area Detectors (e.g. x,y pixel coordinates, pedestal values, masks).  One can see all the methods of a class using ipython tab completion, or /reg/g/psdm/sw/releases/ana-current/Detector/examples/ex_all_dets.py.

from psana import *
ds = DataSource('exp=xpptut15:run=54:smd')
det = Detector('cspad')
for nevent,evt in enumerate(ds.events()):
    # includes pedestal subtraction, common-mode correction, bad-pixel
    # suppresion, and returns an "unassembled" 3D array of cspad panels
    calib_array = det.calib(evt)
    # this is the same as the above, but also uses geometry to
    # create an "assembled" 2D image (including "fake pixels" in gaps)
    img = det.image(evt)
    break
import matplotlib.pyplot as plt
plt.imshow(img,vmin=-2,vmax=2)
plt.show()

You can find a version with more advanced graphics here.

The "image" method can also be used to convert any array with the "unassembled" shape into "assembled" format (that is, applying the geometry) with a line like this:

assembled_array = det.image(evt, unassembled_array)

This can be useful for plotting masks, or determining which pixels are "real" in the assembled image:

real_pixels = det.image(evt, np.ones_like(unassembled_array))

NOTE: as of psana version 0.19.0 the behavior of the area detector "calib" and "image" methods have been changed.  The new, more sustainable, policy is these methods will return the best corrections possible, which can change with new psana releases.  As an example, in ana-0.19.0 we include per-pixel gain corrections (when available from flat-field data) and the configurable 6.85x per-pixel gain correction for the CSPAD. If you would like your corrections to not change with new releases, you can "freeze" at a specific release using a command like "sit_setup ana-0.18.10" (the last version before this policy change) or you can perform individual corrections yourself using methods like det.pedestals() and det.gain().

  • No labels