From a46406d351bea2fb22833eeece6623ab7c0d1216 Mon Sep 17 00:00:00 2001 From: Melanie Clarke Date: Thu, 19 Sep 2024 16:15:47 -0400 Subject: [PATCH 1/2] Add safeguards for nsclean on background/imprint members --- jwst/pipeline/calwebb_spec2.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/jwst/pipeline/calwebb_spec2.py b/jwst/pipeline/calwebb_spec2.py index 7a5f0b3ca3..36e2993113 100644 --- a/jwst/pipeline/calwebb_spec2.py +++ b/jwst/pipeline/calwebb_spec2.py @@ -270,15 +270,26 @@ def process_exposure_product( calibrated = self.nsclean(calibrated) # Apply nsclean to NIRSpec imprint and background members - for i, imprint_file in enumerate(members_by_type['imprint']): - self.nsclean.output_file = os.path.basename(imprint_file) - imprint_nsclean = self.nsclean(imprint_file) - members_by_type['imprint'][i] = imprint_nsclean - - for i, bkg_file in enumerate(members_by_type['background']): - self.nsclean.output_file = os.path.basename(bkg_file) - bkg_nsclean = self.nsclean(bkg_file) - members_by_type['background'][i] = bkg_nsclean + if not self.nsclean.skip: + save_results = self.nsclean.save_results + + for i, imprint_file in enumerate(members_by_type['imprint']): + if save_results: + if isinstance(imprint_file, datamodels.JwstDataModel): + self.nsclean.output_file = imprint_file.meta.filename + else: + self.nsclean.output_file = os.path.basename(imprint_file) + imprint_nsclean = self.nsclean(imprint_file) + members_by_type['imprint'][i] = imprint_nsclean + + for i, bkg_file in enumerate(members_by_type['background']): + if save_results: + if isinstance(bkg_file, datamodels.JwstDataModel): + self.nsclean.output_file = bkg_file.meta.filename + else: + self.nsclean.output_file = os.path.basename(bkg_file) + bkg_nsclean = self.nsclean(bkg_file) + members_by_type['background'][i] = bkg_nsclean # Leakcal subtraction (imprint) occurs before background subtraction on a per-exposure basis. # If there is only one `imprint` member, this imprint exposure is subtracted from all the From 9c68fc3568528385a6f92635989007c76b33ce98 Mon Sep 17 00:00:00 2001 From: Melanie Clarke Date: Thu, 19 Sep 2024 17:02:30 -0400 Subject: [PATCH 2/2] Update change log --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 3069853c64..8b97ac527a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -188,7 +188,7 @@ pipeline in memory or on disk. [#8683] - Updated ``calwebb_spec2`` to run ``nsclean`` on NIRSpec imprint and background - association members. [#8786] + association members. [#8786, #8809] - Updated `calwebb_spec3` to not save the `pixel_replacement` output by default.[#8765]