Skip to content

Commit

Permalink
JP-3426: Check WFSS background mask against input dq array (#8070)
Browse files Browse the repository at this point in the history
Co-authored-by: Howard Bushouse <[email protected]>
  • Loading branch information
tapastro and hbushouse authored Nov 15, 2023
1 parent 9dfaa37 commit e800077
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
1.12.6 (unreleased)
===================

background
----------

- Ensure that WFSS background mask does not leave only
pixels with DO_NOT_USE flagged. [#8070]

extract_1d
----------

Expand Down
8 changes: 7 additions & 1 deletion jwst/background/background_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np

from stdatamodels.jwst import datamodels
from stdatamodels.jwst.datamodels.dqflags import pixel

from . import subtract_images
from ..assign_wcs.util import create_grism_bbox
Expand Down Expand Up @@ -295,7 +296,12 @@ def subtract_wfss_bkg(input_model, bkg_filename, wl_range_name, mmag_extract=Non
# i.e. in regions we can use as background.
if got_catalog:
bkg_mask = mask_from_source_cat(input_model, wl_range_name, mmag_extract)
if bkg_mask.sum() < 100:
# Ensure mask has 100 pixels and that those pixels correspond to valid
# pixels using model DQ array
if np.count_nonzero(input_model.dq[bkg_mask]
^ pixel['DO_NOT_USE']
& pixel['DO_NOT_USE']
) < 100:
log.warning("Not enough background pixels to work with.")
log.warning("Step will be SKIPPED.")
return None
Expand Down

0 comments on commit e800077

Please sign in to comment.