Issue
Implementation
igm - is a gain mode index 0,1,2 for Normal-00, Med-01, Low-11 gbits = raw>>14 # 00/01/11 - gain bits for mode 0,1,2 fg0, fg1, fg2 = gbits==0, gbits==1, gbits==3 bad = (np.logical_not(fg0),\ np.logical_not(fg1),\ np.logical_not(fg2))[igm]
Images of mask versions
User's mask
Mask from ~valmar/psana-extra-extreme-sabine2.h5 - very agressive masking - radial=9 pix around bad!
Bad pixel status as mask
Images of generated from status_as_mask arrays (3, 8, 512, 1024) merged for 3 gain ranges to the shape=(8, 512, 1024)
- mask = det.status_as_mask(par, mode=3, mstcode=63) - mask all status codes but bad gain switch
- mstcode=64 - mask of the new bad gain switch status
- mstcode=127 - mask all bad status codes
cxic00120 run 42
cxic00120 run 24
cxic00120 run 42 NEIGHBOURS MASKED AS +/-1pixel around each bad
- mstcode=64 strongly overlaps with 63
- mstcode=63 and 127 shows about the same mask, difference is minor as shown in pixel status statistics.
pixel status statistics
Merged for 3 gain modes status
cxic00120 run:24 status.shape:(8, 512, 1024) size: 4194304
bad pixels w/o sw: number of pixels containing bits 63(dec) 077(oct): 3739 of total bad 3768 of total 4194304
bad pixels switch: number of pixels containing bits 64(dec) 0100(oct): 1117 of total bad 3768 of total 4194304
bad pixels total : number of pixels containing bits 127(dec) 0177(oct): 3768 of total bad 3768 of total 4194304
Bad status code 64 adds 3768-3739=29 bad pixel.
Non-merged for 3 gain modes status
cxic00120 run:24 status.shape:(3, 8, 512, 1024) size: 12582912
bad pixels w/o sw: number of pixels containing bits 63(dec) 077(oct): 6217 of total bad 6280 of total 12582912
bad pixels switch: number of pixels containing bits 64(dec) 0100(oct): 1150 of total bad 6280 of total 12582912
bad pixels total : number of pixels containing bits 127(dec) 0177(oct): 6280 of total bad 6280 of total 12582912
Bad status code 64 adds 6280-6217=63 bad pixel.
Non-merged for 3 gain modes status
cxic00120 run:42 status.shape:(3, 8, 512, 1024) size: 12582912
bad pixels w/o sw: number of pixels containing bits 63(dec) 077(oct): 7673 of total bad 7734 of total 12582912
bad pixels switch: number of pixels containing bits 64(dec) 0100(oct): 1850 of total bad 7734 of total 12582912
bad pixels total : number of pixels containing bits 127(dec) 0177(oct): 7734 of total bad 7734 of total 12582912
Bad status code 64 adds 7734-7673=61 bad pixel.
Combined mask
det.mask(evt, calib=False, status=True, edges=True, central=True, unbond=False, unbondnbrs=False, mode=0o377, width=5, wcentral=5, mstcode=0xffff)
Custom mask
import PSCalib.GlobalUtils as gu
mask = det.status_as_mask(evt, mstcode=0o377) # mode=0 - by default do not mask neighbors
mask = gu.mask_neighbors_in_radius(mask, rad=6, ptrn='r')
mask = gu.merge_masks(mask, det.mask_geo(evt, width=10, wcentral=5)) # mbits=0o377, where 1-edges, 2-central, 4-non-bonded for cspad2x1, ... non-bonded neighbors
#mask = gu.merge_masks(mask, gu.mask_edges(mask, mrows=2, mcols=4)) # masks each segment edges only
mask = gu.merge_masks(mask, det.mask_calib(evt))
Summary
- New bad pixel status code is added for bad gain mode switch:
[I] L0703 bad pixel status: status 1: 1240 pixel rms > 19.414 status 2: 1875 pixel rms < 0.611 status 4: 1755 pixel intensity > 16000 in more than 0.1 fraction of events status 8: 111 pixel intensity < 1 in more than 0.1 fraction of events status 16: 340 pixel average > 3761.95 status 32: 1940 pixel average < 1226.6 status 64: 1790 pixel with bad gain mode switch
- However this new status bit 64 strongly overlaps with other bad pixel status.
- User's mask contains more bad pixels in peripheral rings ...