From d57f6337ba1b5a6f14379f236b83f741afffa413 Mon Sep 17 00:00:00 2001 From: David Law Date: Fri, 19 Apr 2024 08:59:49 -0400 Subject: [PATCH] JP-3587: Clean up NIRSpec IFU flat field SCI/ERR/DQ flagging (#8385) Co-authored-by: Howard Bushouse --- CHANGES.rst | 6 ++++++ jwst/flatfield/flat_field.py | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index c3a2cd99db..73c37648b6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -36,6 +36,12 @@ extract_1d - Replaced deprecated ``np.trapz`` with ``np.trapezoid()``. [#8415] +flat_field +---------- + +- Update the flatfield code for NIRSpec IFU data to ensure that SCI=ERR=NaN and + DQ has the DO_NOT_USE flag set outside the footprint of the IFU slices [#8385] + general ------- diff --git a/jwst/flatfield/flat_field.py b/jwst/flatfield/flat_field.py index 3e89c52ab4..3795fd74a4 100644 --- a/jwst/flatfield/flat_field.py +++ b/jwst/flatfield/flat_field.py @@ -1627,9 +1627,9 @@ def flat_for_nirspec_ifu(output_model, f_flat_model, s_flat_model, d_flat_model, """ any_updated = False exposure_type = output_model.meta.exposure.type - flat = np.ones_like(output_model.data) + flat = np.ones_like(output_model.data) * np.nan flat_dq = np.zeros_like(output_model.dq) - flat_err = np.zeros_like(output_model.data) + flat_err = np.zeros_like(output_model.data) * np.nan try: list_of_wcs = nirspec.nrs_ifu_wcs(output_model) @@ -1726,6 +1726,13 @@ def flat_for_nirspec_ifu(output_model, f_flat_model, s_flat_model, d_flat_model, any_updated = True + # Ensure consistency between NaN-valued pixels and the DO_NOT_USE flag + indx = np.where((flat_dq & dqflags.pixel['DO_NOT_USE']) != 0) + flat[indx] = np.nan + flat_err[indx] = np.nan + indx = np.where(~ np.isfinite(flat)) + flat_dq[indx] = flat_dq[indx] | dqflags.pixel['DO_NOT_USE'] + # That's all folks return flat, flat_dq, flat_err, any_updated