gbrammer / grizli

Grizli: The "Grism redshift and line" analysis software
MIT License
69 stars 51 forks source link

Mask outliers in BKG extensions in `drizzle_from_visit` #220

Closed gbrammer closed 7 months ago

gbrammer commented 7 months ago

Add a global variable BKG_CLIP used in grizli.utils.drizzle_from_visit to mask outlier pixels in the BKG extension of grizli-processed JWST exposures. There are a few examples where there are excessively negative pixels in the BKG maps that then show up as stripes of bad pixels in the combined mosaic.

The three elements of the BKG_CLIP array are interpreted as

BKG_CLIP = [scale, percentile_lo, percentile_hi]

# Clip percentiles
bkg_lo, bkg_hi = np.nanpercentile(flt['BKG'].data[valid], BKG_CLIP[1:3])

# make sure lower (upper) limit is negative (positive)
clip_lo = -np.abs(bkg_lo)
clip_hi = np.abs(bkg_hi)

_badpix = flt['BKG'].data < BKG_CLIP[0]*bkg_lo
_badpix |= flt['BKG'].data > BKG_CLIP[0]*bkg_hi

where the _badpix mask is added to the DQ mask for that exposure.

To turn off the masking, set grizli.utils.BKG_CLIP = None (it's not currently implemented as a keyword argument on grizli.utils.drizzle_from_visit ).