This code is located in /reg/g/psdm/tutorials/examplePython3/mask.py and demonstrates how to access detector-specific masks as well as user-generated masks (see below).

  • "calib": run-number-dependent user-defined masks deployed to the experiment's calibration directory
  • "status": bad pixels as determined from calibman dark-run analysis
  • "edges": edges of ASICS
  • "central": for a CSPAD the center rows of pixels of a 2x1 ASIC. which are larger than the other pixels
  • "unbond': unbonded pixels
  • "unbondnbrs": the 4 nearest neighbors of unbonded pixels
  • "unbondnbrs8": the 8 neighbors of unbonded pixels
from psana import *
import numpy as np
runnum = 54
ds = DataSource('exp=xpptut15:run=%d:smd'%runnum)
det = Detector('cspad')
mask = det.mask(runnum,calib=True,status=True,edges=True,central=True,unbond=True,unbondnbrs=True)
for nevent,evt in enumerate(ds.events()):
    calib_array = det.calib(evt)
    # apply the mask
    calib_masked = calib_array * mask
    break
# make a 2D image (with geometry) out of any correctly-shaped array
mask_image = det.image(runnum,mask)
import matplotlib.pyplot as plt
plt.imshow(mask_image,vmin=-2,vmax=2,interpolation='none')
plt.show()

Drawing a User-Defined Mask on an Image

To draw a mask on an image and save a file that is usable in python, use the psocake tool, as described here.  It can also be useful to use psocake to generate the sum or max of each pixel over many events ("generate powder pattern") as shown here and draw on that.  This powder-pattern will be generated in batch and then the resulting data can be viewed in psocake and drawn on.

Deploying A Run-Dependent User-Mask

A mask of the appropriate unassembled shape can be deployed to the experiment-specific calib directory by copying the file generated above to a directory like  /reg/d/psdm/xpp/xpptut15/calib/CsPad::CalibV1/XppGon.0:Cspad.0/pixel_mask/ (substitute your own hutch/experiment/detector information).  The filename should be something like 56-95.data, indicating that the mask is valid for runs 56 through 95.  The second number can be replaced with "end", indicating that the constants are valid for all runs later than 56.  psana has complex policies (but natural where possible) for handling cases when run number ranges overlap.

  • No labels