Skip to content

Commit

Permalink
JP-3808: Store scaling factor for WFSS data in background step (#9204)
Browse files Browse the repository at this point in the history
  • Loading branch information
emolter authored Feb 24, 2025
1 parent d5953bc commit 298965a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions changes/9204.background.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Store background scaling factor for WFSS data
1 change: 1 addition & 0 deletions jwst/background/background_sub_wfss.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def subtract_wfss_bkg(
result = input_model.copy()
result.data = input_model.data - subtract_this
result.dq = np.bitwise_or(input_model.dq, bkg_ref.dq)
result.meta.background.scaling_factor = factor

log.info(f"Average of scaled background image = {np.nanmean(subtract_this):.3e}")
log.info(f"Scaling factor = {factor:.5e}")
Expand Down
23 changes: 17 additions & 6 deletions jwst/background/tests/test_background_wfss.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,13 @@ def bkg_file(tmp_cwd, make_wfss_datamodel, known_bkg):


def shared_tests(sci, mask, original_data_mean):
"""Tests that are common to all WFSS modes
"""
Tests that are common to all WFSS modes.
Note that NaN fraction test in test_nrc_wfss_background and test_nis_wfss_background
cannot be applied to the full run tests because the background reference files contain
NaNs in some cases (specifically for NIRISS)"""
NaNs in some cases (specifically for NIRISS)
"""

# re-mask data so "real" sources are ignored here
sci[~mask] = np.nan
Expand Down Expand Up @@ -230,11 +233,14 @@ def test_nis_wfss_background(make_nis_wfss_datamodel, bkg_file):
# test both filters because they have opposite dispersion directions
@pytest.mark.parametrize("pupil", ["GRISMC", "GRISMR"])
def test_nrc_wfss_full_run(pupil, make_nrc_wfss_datamodel):
"""Test full run of NIRCAM WFSS background subtraction.
"""
Test full run of NIRCAM WFSS background subtraction.
The residual structure in the background will not look as nice as in
test_nis_wfss_background because here it's taken from a reference file,
so the bkg has real detector imperfections
while the data is synthetic and just has a mock gradient"""
while the data is synthetic and just has a mock gradient
"""
data = make_nrc_wfss_datamodel.copy()
data.meta.instrument.pupil = pupil

Expand All @@ -249,15 +255,19 @@ def test_nrc_wfss_full_run(pupil, make_nrc_wfss_datamodel):
wavelenrange = Step().get_reference_file(data, "wavelengthrange")
mask = _mask_from_source_cat(result, wavelenrange)
shared_tests(sci, mask, data.original_data_mean)
assert isinstance(result.meta.background.scaling_factor, float)


@pytest.mark.parametrize("filt", ["GR150C", "GR150R"])
def test_nis_wfss_full_run(filt, make_nis_wfss_datamodel):
"""Test full run of NIRISS WFSS background subtraction.
"""
Test full run of NIRISS WFSS background subtraction.
The residual structure in the background will not look as nice as in
test_nis_wfss_background because here it's taken from a reference file,
so the bkg has real detector imperfections
while the data is synthetic and just has a mock gradient"""
while the data is synthetic and just has a mock gradient
"""
data = make_nis_wfss_datamodel.copy()
data.meta.instrument.filter = filt

Expand All @@ -272,6 +282,7 @@ def test_nis_wfss_full_run(filt, make_nis_wfss_datamodel):
wavelenrange = Step().get_reference_file(data, "wavelengthrange")
mask = _mask_from_source_cat(result, wavelenrange)
shared_tests(sci, mask, data.original_data_mean)
assert isinstance(result.meta.background.scaling_factor, float)


def test_sufficient_background_pixels():
Expand Down

0 comments on commit 298965a

Please sign in to comment.