From 92863b446a4b66195c436bbb0cf1082c492f6dc5 Mon Sep 17 00:00:00 2001 From: jemorrison Date: Tue, 19 Nov 2024 08:03:37 -0700 Subject: [PATCH 01/19] testing cube build names --- jwst/cube_build/ifu_cube.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jwst/cube_build/ifu_cube.py b/jwst/cube_build/ifu_cube.py index 84d56a8540..9c9b73e0fd 100644 --- a/jwst/cube_build/ifu_cube.py +++ b/jwst/cube_build/ifu_cube.py @@ -53,6 +53,8 @@ def __init__(self, self.input_models = input_models # needed when building single mode IFU cubes self.output_name_base = output_name_base + print('At the start output name base', self.output_name_base) + self.num_files = None self.instrument = instrument @@ -168,7 +170,9 @@ def define_cubename(self): """ Define the base output name """ if self.pipeline == 2: + print('in define_cubename', self.output_name_base) newname = self.output_name_base + self.suffix + '.fits' + print('***********NAME OF CUBE FILE', newname) else: if self.instrument == 'MIRI': @@ -203,6 +207,7 @@ def define_cubename(self): b_name = b_name + subchannels[i] b_name = b_name.lower() newname = self.output_name_base + ch_name + '-' + b_name + print('*******************NAME of cube when not pipeline2', newname) if self.coord_system == 'internal_cal': newname = self.output_name_base + ch_name + '-' + b_name + '_internal' if self.output_type == 'single': From c0e9d9c40e8065fb76706c3042f77e43db479e16 Mon Sep 17 00:00:00 2001 From: jemorrison Date: Thu, 21 Nov 2024 05:52:08 -0700 Subject: [PATCH 02/19] fixed cube build --- jwst/cube_build/ifu_cube.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/jwst/cube_build/ifu_cube.py b/jwst/cube_build/ifu_cube.py index 9c9b73e0fd..26a4713bcc 100644 --- a/jwst/cube_build/ifu_cube.py +++ b/jwst/cube_build/ifu_cube.py @@ -53,7 +53,6 @@ def __init__(self, self.input_models = input_models # needed when building single mode IFU cubes self.output_name_base = output_name_base - print('At the start output name base', self.output_name_base) self.num_files = None @@ -170,9 +169,7 @@ def define_cubename(self): """ Define the base output name """ if self.pipeline == 2: - print('in define_cubename', self.output_name_base) - newname = self.output_name_base + self.suffix + '.fits' - print('***********NAME OF CUBE FILE', newname) + newname = self.output_name_base + '_' + self.suffix + '.fits' else: if self.instrument == 'MIRI': @@ -207,7 +204,6 @@ def define_cubename(self): b_name = b_name + subchannels[i] b_name = b_name.lower() newname = self.output_name_base + ch_name + '-' + b_name - print('*******************NAME of cube when not pipeline2', newname) if self.coord_system == 'internal_cal': newname = self.output_name_base + ch_name + '-' + b_name + '_internal' if self.output_type == 'single': From 4f547b3690f9c1c97e7837914caa3761b609f522 Mon Sep 17 00:00:00 2001 From: jemorrison Date: Mon, 25 Nov 2024 13:20:24 -0700 Subject: [PATCH 03/19] fix names --- jwst/pixel_replace/pixel_replace.py | 2 +- jwst/pixel_replace/pixel_replace_step.py | 36 +++++++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/jwst/pixel_replace/pixel_replace.py b/jwst/pixel_replace/pixel_replace.py index 99a540d932..b767c48325 100644 --- a/jwst/pixel_replace/pixel_replace.py +++ b/jwst/pixel_replace/pixel_replace.py @@ -29,7 +29,7 @@ class PixelReplacement: VERTICAL = 2 LOG_SLICE = ['column', 'row'] - default_suffix = 'pixrep' + #default_suffix = 'pixrep' def __init__(self, input_model, **pars): """ diff --git a/jwst/pixel_replace/pixel_replace_step.py b/jwst/pixel_replace/pixel_replace_step.py index 5191ac3930..d0607a251b 100644 --- a/jwst/pixel_replace/pixel_replace_step.py +++ b/jwst/pixel_replace/pixel_replace_step.py @@ -4,7 +4,8 @@ from ..stpipe import Step from jwst.stpipe import record_step_status from jwst import datamodels -from .pixel_replace import PixelReplacement +from .pixel_replace import PixelReplacement#from functools import wraps +#from jwst.pipeline.calwebb_spec3 import invariant_filename __all__ = ["PixelReplaceStep"] @@ -72,9 +73,9 @@ def process(self, input): 'n_adjacent_cols': self.n_adjacent_cols, } - # ___________________ - # calewbb_spec3 case - # ___________________ + # ___________________________________ + # calewbb_spec3 case / ModelContainer + # __________________________________ if isinstance(input_model, datamodels.ModelContainer): output_model = input_model # Setup output path naming if associations are involved. @@ -85,6 +86,12 @@ def process(self, input): pass if asn_id is None: asn_id = self.search_attr('asn_id') + if asn_id is None: # it is still None. It does not exist. A ModelContainer was passed in with + # no asn information + # to create the correct output name set the following. + self.output_use_model = True + self.save_model = invariant_filename(self.save_model) + if asn_id is not None: _make_output_path = self.search_attr( '_make_output_path', parent_first=True @@ -93,6 +100,7 @@ def process(self, input): _make_output_path, asn_id=asn_id ) + # Check models to confirm they are the correct type for i, model in enumerate(output_model): run_pixel_replace = True @@ -124,3 +132,23 @@ def process(self, input): record_step_status(replacement.output, 'pixel_replace', success=True) result = replacement.output return result + + +def invariant_filename(save_model_func): + """Restore meta.filename after save_model""" + + @wraps(save_model_func) + def save_model(model, **kwargs): + try: + filename = model.meta.filename + except AttributeError: + filename = None + + result = save_model_func(model, **kwargs) + + if filename: + model.meta.filename = filename + + return result + + return save_model From a4e9f92182cdcb474efb9989c057a15a86d84f69 Mon Sep 17 00:00:00 2001 From: jemorrison Date: Mon, 25 Nov 2024 13:28:01 -0700 Subject: [PATCH 04/19] added import --- jwst/pixel_replace/pixel_replace_step.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jwst/pixel_replace/pixel_replace_step.py b/jwst/pixel_replace/pixel_replace_step.py index d0607a251b..bde1aaa716 100644 --- a/jwst/pixel_replace/pixel_replace_step.py +++ b/jwst/pixel_replace/pixel_replace_step.py @@ -4,7 +4,8 @@ from ..stpipe import Step from jwst.stpipe import record_step_status from jwst import datamodels -from .pixel_replace import PixelReplacement#from functools import wraps +from .pixel_replace import PixelReplacement +from functools import wraps #from jwst.pipeline.calwebb_spec3 import invariant_filename __all__ = ["PixelReplaceStep"] From 41e34bf7be02e77e7ef6403655d09d5fd12ea8b3 Mon Sep 17 00:00:00 2001 From: jemorrison Date: Wed, 27 Nov 2024 07:50:53 -0700 Subject: [PATCH 05/19] updates --- jwst/pixel_replace/pixel_replace_step.py | 8 ++-- .../pixel_replace/tests/test_pixel_replace.py | 42 ++++++++++++++++++- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/jwst/pixel_replace/pixel_replace_step.py b/jwst/pixel_replace/pixel_replace_step.py index bde1aaa716..88dd283db6 100644 --- a/jwst/pixel_replace/pixel_replace_step.py +++ b/jwst/pixel_replace/pixel_replace_step.py @@ -78,7 +78,7 @@ def process(self, input): # calewbb_spec3 case / ModelContainer # __________________________________ if isinstance(input_model, datamodels.ModelContainer): - output_model = input_model + output_model = input_model.copy() # Setup output path naming if associations are involved. asn_id = None try: @@ -103,7 +103,7 @@ def process(self, input): ) # Check models to confirm they are the correct type - for i, model in enumerate(output_model): + for model in output_model: run_pixel_replace = True if model.meta.model_type in ['MultiSlitModel', 'SlitModel', 'ImageModel', 'IFUImageModel', 'CubeModel']: @@ -119,8 +119,8 @@ def process(self, input): if run_pixel_replace: replacement = PixelReplacement(model, **pars) replacement.replace() - output_model[i] = replacement.output - record_step_status(output_model[i], 'pixel_replace', success=True) + model = replacement.output + record_step_status(model, 'pixel_replace', success=True) return output_model # ________________________________________ # calewbb_spec2 case - single input model diff --git a/jwst/pixel_replace/tests/test_pixel_replace.py b/jwst/pixel_replace/tests/test_pixel_replace.py index 3ab91c7eec..0b3c31f5a8 100644 --- a/jwst/pixel_replace/tests/test_pixel_replace.py +++ b/jwst/pixel_replace/tests/test_pixel_replace.py @@ -2,6 +2,7 @@ import pytest from stdatamodels.jwst import datamodels +from jwst.datamodels import ModelContainer from stdatamodels.jwst.datamodels.dqflags import pixel as flags from jwst.assign_wcs import AssignWcsStep @@ -99,6 +100,7 @@ def nirspec_ifu(): model.var_poisson = test_data.var_poisson model.var_rnoise = test_data.var_rnoise model.var_flat = test_data.var_flat + test_data.close() return model, bad_idx @@ -212,11 +214,14 @@ def test_pixel_replace_nirspec_ifu(input_model_function, algorithm): The test is otherwise the same as for other modes. """ input_model, bad_idx = input_model_function() + input_model.meta.filename = 'jwst_nirspec_cal.fits' # for this simple case, the results from either algorithm should # be the same - result = PixelReplaceStep.call(input_model, skip=False, algorithm=algorithm) + result = PixelReplaceStep.call(input_model, skip=False, algorithm=algorithm,save_results=True) + assert result.meta.filename == 'jwst_nirspec_pixelreplacestep.fits' + for ext in ['data', 'err', 'var_poisson', 'var_rnoise', 'var_flat']: # non-science edges are uncorrected assert np.all(np.isnan(getattr(result, ext)[..., :, 1])) @@ -238,3 +243,38 @@ def test_pixel_replace_nirspec_ifu(input_model_function, algorithm): result.close() input_model.close() + + + + +@pytest.mark.slow +@pytest.mark.parametrize('input_model_function', + [nirspec_ifu]) +@pytest.mark.parametrize('algorithm', ['fit_profile', 'mingrad']) +def test_pixel_replace_nirspec_ifu_container_names(input_model_function, algorithm): + """ + Test pixel replacement for NIRSpec IFU using a container + + Larger data and more WCS operations required for testing make + this test take more than a minute, so marking this test 'slow'. + + The test is otherwise the same as for other modes. + """ + input_model, bad_idx = input_model_function() + input_model.meta.filename = 'jwst_nirspec_1_cal.fits' + input_model2, bad_idx2 = input_model_function() + input_model2.meta.filename = 'jwst_nirspec_2_cal.fits' + cfiles = [input_model, input_model2] + container = ModelContainer(cfiles) + + # for this simple case, the results from either algorithm should + # be the same + result = PixelReplaceStep.call(container, skip=False, algorithm=algorithm,save_results=True) + + print(result[0].meta.filename, result[1].meta.filename) + + assert result[0].meta.filename == 'jwst_nirspec_1_pixelreplacestep.fits' + assert result[1].meta.filename == 'jwst_nirspec_2_pixelreplacestep.fits' + + result.close() + input_model.close() From cc56feb189ea4f5764f64103808efe5d86b14e9b Mon Sep 17 00:00:00 2001 From: jemorrison Date: Fri, 6 Dec 2024 10:01:58 -0700 Subject: [PATCH 06/19] updates to fix names --- jwst/cube_build/data_types.py | 1 - jwst/cube_build/ifu_cube.py | 4 ++- jwst/pixel_replace/pixel_replace_step.py | 8 +++--- .../pixel_replace/tests/test_pixel_replace.py | 25 ++++++++++++++----- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/jwst/cube_build/data_types.py b/jwst/cube_build/data_types.py index 711f729bd1..50e28fba03 100644 --- a/jwst/cube_build/data_types.py +++ b/jwst/cube_build/data_types.py @@ -98,7 +98,6 @@ def __init__(self, input, single, output_file, output_dir): # Suffixes will be added to this name later, to designate the # channel+subchannel (MIRI MRS) or grating+filter (NRS IFU) the output cube covers. - if output_file is not None: basename, ext = os.path.splitext(os.path.basename(output_file)) self.output_name = basename diff --git a/jwst/cube_build/ifu_cube.py b/jwst/cube_build/ifu_cube.py index 26a4713bcc..db05d49b33 100644 --- a/jwst/cube_build/ifu_cube.py +++ b/jwst/cube_build/ifu_cube.py @@ -179,9 +179,10 @@ def define_cubename(self): # that the remaining suffixes created below form the entire # list of optical elements in the final output name. suffix = self.output_name_base[self.output_name_base.rfind('_') + 1:] + if suffix in ['clear']: self.output_name_base = self.output_name_base[:self.output_name_base.rfind('_')] - + # Now compose the appropriate list of optical element suffix names # based on MRS channel and sub-channel channels = [] @@ -562,6 +563,7 @@ def build_ifucube(self): """ self.output_name = self.define_cubename() + print('ifu cube returend output_name', self.output_name) total_num = self.naxis1 * self.naxis2 * self.naxis3 self.spaxel_flux = np.zeros(total_num, dtype=np.float64) diff --git a/jwst/pixel_replace/pixel_replace_step.py b/jwst/pixel_replace/pixel_replace_step.py index 88dd283db6..32f5944e56 100644 --- a/jwst/pixel_replace/pixel_replace_step.py +++ b/jwst/pixel_replace/pixel_replace_step.py @@ -78,8 +78,10 @@ def process(self, input): # calewbb_spec3 case / ModelContainer # __________________________________ if isinstance(input_model, datamodels.ModelContainer): - output_model = input_model.copy() # Setup output path naming if associations are involved. + # if input is ModelContainer do not copy the input_model + # because assocation information is not copied. + # Instead update input_modelin place. asn_id = None try: asn_id = input_model.asn_table["asn_id"] @@ -103,7 +105,7 @@ def process(self, input): ) # Check models to confirm they are the correct type - for model in output_model: + for i, model in enumerate(input_model): run_pixel_replace = True if model.meta.model_type in ['MultiSlitModel', 'SlitModel', 'ImageModel', 'IFUImageModel', 'CubeModel']: @@ -121,7 +123,7 @@ def process(self, input): replacement.replace() model = replacement.output record_step_status(model, 'pixel_replace', success=True) - return output_model + return input_model # ________________________________________ # calewbb_spec2 case - single input model # ________________________________________ diff --git a/jwst/pixel_replace/tests/test_pixel_replace.py b/jwst/pixel_replace/tests/test_pixel_replace.py index 0b3c31f5a8..47a6daa8d7 100644 --- a/jwst/pixel_replace/tests/test_pixel_replace.py +++ b/jwst/pixel_replace/tests/test_pixel_replace.py @@ -1,3 +1,4 @@ +import os import numpy as np import pytest @@ -8,7 +9,7 @@ from jwst.assign_wcs import AssignWcsStep from jwst.assign_wcs.tests.test_nirspec import create_nirspec_ifu_file from jwst.pixel_replace.pixel_replace_step import PixelReplaceStep - +from glob import glob def cal_data(shape, bad_idx, dispaxis=1, model='slit'): if model == 'image': @@ -251,7 +252,7 @@ def test_pixel_replace_nirspec_ifu(input_model_function, algorithm): @pytest.mark.parametrize('input_model_function', [nirspec_ifu]) @pytest.mark.parametrize('algorithm', ['fit_profile', 'mingrad']) -def test_pixel_replace_nirspec_ifu_container_names(input_model_function, algorithm): +def test_pixel_replace_nirspec_ifu_container_names(tmp_cwd, tmp_path, input_model_function, algorithm): """ Test pixel replacement for NIRSpec IFU using a container @@ -260,6 +261,10 @@ def test_pixel_replace_nirspec_ifu_container_names(input_model_function, algorit The test is otherwise the same as for other modes. """ + output_dir = tmp_path / 'output' + output_dir.mkdir(exist_ok=True) + output_dir = str(output_dir) + input_model, bad_idx = input_model_function() input_model.meta.filename = 'jwst_nirspec_1_cal.fits' input_model2, bad_idx2 = input_model_function() @@ -267,14 +272,22 @@ def test_pixel_replace_nirspec_ifu_container_names(input_model_function, algorit cfiles = [input_model, input_model2] container = ModelContainer(cfiles) + expected_name = [] + expected_name.append('jwst_nirspec_1_pixelreplacestep.fits') + expected_name.append('jwst_nirspec_2_pixelreplacestep.fits') + + return_files = [] # for this simple case, the results from either algorithm should # be the same result = PixelReplaceStep.call(container, skip=False, algorithm=algorithm,save_results=True) - - print(result[0].meta.filename, result[1].meta.filename) + for dirname in [output_dir, tmp_cwd]: + result_files = glob(os.path.join(dirname, '*pixelreplacestep.fits')) + for file in result_files: + basename = os.path.basename(file) + return_files.append(basename) - assert result[0].meta.filename == 'jwst_nirspec_1_pixelreplacestep.fits' - assert result[1].meta.filename == 'jwst_nirspec_2_pixelreplacestep.fits' + assert expected_name[0] == basename[0][0] + assert expected_name[1] == basename[1][0] result.close() input_model.close() From 21024531d83ab2967cdd58a9a409366c76b29670 Mon Sep 17 00:00:00 2001 From: jemorrison Date: Fri, 6 Dec 2024 10:35:13 -0700 Subject: [PATCH 07/19] update test to check filenames --- jwst/pixel_replace/tests/test_pixel_replace.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jwst/pixel_replace/tests/test_pixel_replace.py b/jwst/pixel_replace/tests/test_pixel_replace.py index 47a6daa8d7..171948f3b7 100644 --- a/jwst/pixel_replace/tests/test_pixel_replace.py +++ b/jwst/pixel_replace/tests/test_pixel_replace.py @@ -286,8 +286,8 @@ def test_pixel_replace_nirspec_ifu_container_names(tmp_cwd, tmp_path, input_mode basename = os.path.basename(file) return_files.append(basename) - assert expected_name[0] == basename[0][0] - assert expected_name[1] == basename[1][0] + assert expected_name[0] == return_files[0] + assert expected_name[1] == return_files[1] result.close() input_model.close() From 2488062961b80d202dfc27110ca7e682b9fb14f1 Mon Sep 17 00:00:00 2001 From: jemorrison Date: Fri, 6 Dec 2024 13:54:36 -0700 Subject: [PATCH 08/19] add another test --- jwst/cube_build/ifu_cube.py | 1 - jwst/pipeline/calwebb_spec3.py | 24 +------------ jwst/pixel_replace/pixel_replace_step.py | 22 +----------- .../pixel_replace/tests/test_pixel_replace.py | 34 +++++++++++++++++++ jwst/stpipe/utilities.py | 21 ++++++++++++ 5 files changed, 57 insertions(+), 45 deletions(-) diff --git a/jwst/cube_build/ifu_cube.py b/jwst/cube_build/ifu_cube.py index db05d49b33..3a75f33381 100644 --- a/jwst/cube_build/ifu_cube.py +++ b/jwst/cube_build/ifu_cube.py @@ -563,7 +563,6 @@ def build_ifucube(self): """ self.output_name = self.define_cubename() - print('ifu cube returend output_name', self.output_name) total_num = self.naxis1 * self.naxis2 * self.naxis3 self.spaxel_flux = np.zeros(total_num, dtype=np.float64) diff --git a/jwst/pipeline/calwebb_spec3.py b/jwst/pipeline/calwebb_spec3.py index 707a67f5c0..6f5665aa0e 100644 --- a/jwst/pipeline/calwebb_spec3.py +++ b/jwst/pipeline/calwebb_spec3.py @@ -7,7 +7,7 @@ from jwst.datamodels import SourceModelContainer from jwst.stpipe import query_step_status - +from jwst.stpipe.utilities import invariant_filename from ..associations.lib.rules_level3_base import format_product from ..exp_to_source import multislit_to_container from ..master_background.master_background_step import split_container @@ -350,25 +350,3 @@ def _create_nrsmos_source_id(self, source_models): srcid = f's{str(source_id):>09s}' return srcid - -# ######### -# Utilities -# ######### -def invariant_filename(save_model_func): - """Restore meta.filename after save_model""" - - @wraps(save_model_func) - def save_model(model, **kwargs): - try: - filename = model.meta.filename - except AttributeError: - filename = None - - result = save_model_func(model, **kwargs) - - if filename: - model.meta.filename = filename - - return result - - return save_model diff --git a/jwst/pixel_replace/pixel_replace_step.py b/jwst/pixel_replace/pixel_replace_step.py index 32f5944e56..e55388736d 100644 --- a/jwst/pixel_replace/pixel_replace_step.py +++ b/jwst/pixel_replace/pixel_replace_step.py @@ -6,7 +6,7 @@ from jwst import datamodels from .pixel_replace import PixelReplacement from functools import wraps -#from jwst.pipeline.calwebb_spec3 import invariant_filename +from jwst.stpipe.utilities import invariant_filename __all__ = ["PixelReplaceStep"] @@ -135,23 +135,3 @@ def process(self, input): record_step_status(replacement.output, 'pixel_replace', success=True) result = replacement.output return result - - -def invariant_filename(save_model_func): - """Restore meta.filename after save_model""" - - @wraps(save_model_func) - def save_model(model, **kwargs): - try: - filename = model.meta.filename - except AttributeError: - filename = None - - result = save_model_func(model, **kwargs) - - if filename: - model.meta.filename = filename - - return result - - return save_model diff --git a/jwst/pixel_replace/tests/test_pixel_replace.py b/jwst/pixel_replace/tests/test_pixel_replace.py index 171948f3b7..e18e420e40 100644 --- a/jwst/pixel_replace/tests/test_pixel_replace.py +++ b/jwst/pixel_replace/tests/test_pixel_replace.py @@ -291,3 +291,37 @@ def test_pixel_replace_nirspec_ifu_container_names(tmp_cwd, tmp_path, input_mode result.close() input_model.close() + + + +@pytest.mark.slow +@pytest.mark.parametrize('input_model_function', + [nirspec_ifu]) +@pytest.mark.parametrize('algorithm', ['fit_profile', 'mingrad']) +def test_pixel_replace_nirspec_ifu_name(tmp_cwd, tmp_path, input_model_function, algorithm): + """ + Test pixel replacement for NIRSpec IFU using a single file + + Larger data and more WCS operations required for testing make + this test take more than a minute, so marking this test 'slow'. + + The test is otherwise the same as for other modes. + """ + output_dir = tmp_path / 'output' + output_dir.mkdir(exist_ok=True) + output_dir = str(output_dir) + + input_model, bad_idx = input_model_function() + input_model.meta.filename = 'jwst_nirspec_cal.fits' + expected_name = 'jwst_nirspec_pixelreplacestep.fits' + + # for this simple case, the results from either algorithm should + # be the same + result = PixelReplaceStep.call(input_model, skip=False, algorithm=algorithm,save_results=True) + + assert expected_name == result.meta.filename + + + result.close() + input_model.close() + diff --git a/jwst/stpipe/utilities.py b/jwst/stpipe/utilities.py index ad62ba1468..fcca990de7 100644 --- a/jwst/stpipe/utilities.py +++ b/jwst/stpipe/utilities.py @@ -30,6 +30,7 @@ Utilities """ import importlib.util +from functools import wraps from importlib import import_module import inspect import logging @@ -211,3 +212,23 @@ def query_step_status(datamodel, cal_step): return getattr(datamodel[0].meta.cal_step, cal_step, NOT_SET) else: return getattr(datamodel.meta.cal_step, cal_step, NOT_SET) + + +def invariant_filename(save_model_func): + """Restore meta.filename after save_model""" + + @wraps(save_model_func) + def save_model(model, **kwargs): + try: + filename = model.meta.filename + except AttributeError: + filename = None + + result = save_model_func(model, **kwargs) + + if filename: + model.meta.filename = filename + + return result + + return save_model From c1c0f19cffdb3dc3ca7e033fc27e984c5dd67d46 Mon Sep 17 00:00:00 2001 From: jemorrison Date: Mon, 9 Dec 2024 09:01:41 -0700 Subject: [PATCH 09/19] update changes --- changes/8979.pixel_replace.rst | 1 + jwst/pixel_replace/pixel_replace.py | 2 -- jwst/pixel_replace/pixel_replace_step.py | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) create mode 100644 changes/8979.pixel_replace.rst diff --git a/changes/8979.pixel_replace.rst b/changes/8979.pixel_replace.rst new file mode 100644 index 0000000000..3c2df1c8c2 --- /dev/null +++ b/changes/8979.pixel_replace.rst @@ -0,0 +1 @@ +fix a bug in pixel_replace and cube_build output filenames diff --git a/jwst/pixel_replace/pixel_replace.py b/jwst/pixel_replace/pixel_replace.py index b767c48325..a28d209451 100644 --- a/jwst/pixel_replace/pixel_replace.py +++ b/jwst/pixel_replace/pixel_replace.py @@ -29,8 +29,6 @@ class PixelReplacement: VERTICAL = 2 LOG_SLICE = ['column', 'row'] - #default_suffix = 'pixrep' - def __init__(self, input_model, **pars): """ Initialize the class with input data model. diff --git a/jwst/pixel_replace/pixel_replace_step.py b/jwst/pixel_replace/pixel_replace_step.py index e55388736d..1124a1d1e7 100644 --- a/jwst/pixel_replace/pixel_replace_step.py +++ b/jwst/pixel_replace/pixel_replace_step.py @@ -5,7 +5,6 @@ from jwst.stpipe import record_step_status from jwst import datamodels from .pixel_replace import PixelReplacement -from functools import wraps from jwst.stpipe.utilities import invariant_filename __all__ = ["PixelReplaceStep"] From 55177843494728115a39ccad9f3dc388c7a51da5 Mon Sep 17 00:00:00 2001 From: jemorrison Date: Mon, 9 Dec 2024 09:12:01 -0700 Subject: [PATCH 10/19] calwebb_spec3.py --- jwst/pipeline/calwebb_spec3.py | 1 - 1 file changed, 1 deletion(-) diff --git a/jwst/pipeline/calwebb_spec3.py b/jwst/pipeline/calwebb_spec3.py index 6f5665aa0e..39b3b75f95 100644 --- a/jwst/pipeline/calwebb_spec3.py +++ b/jwst/pipeline/calwebb_spec3.py @@ -1,6 +1,5 @@ #!/usr/bin/env python from collections import defaultdict -from functools import wraps import os.path as op from stdatamodels.jwst import datamodels From 2c0c42ba21029ac0d68542abb0e254f0d89bd258 Mon Sep 17 00:00:00 2001 From: jemorrison Date: Wed, 11 Dec 2024 11:37:47 -0700 Subject: [PATCH 11/19] fix test --- jwst/pixel_replace/tests/test_pixel_replace.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/jwst/pixel_replace/tests/test_pixel_replace.py b/jwst/pixel_replace/tests/test_pixel_replace.py index e18e420e40..836082538a 100644 --- a/jwst/pixel_replace/tests/test_pixel_replace.py +++ b/jwst/pixel_replace/tests/test_pixel_replace.py @@ -219,7 +219,8 @@ def test_pixel_replace_nirspec_ifu(input_model_function, algorithm): # for this simple case, the results from either algorithm should # be the same - result = PixelReplaceStep.call(input_model, skip=False, algorithm=algorithm,save_results=True) + result = PixelReplaceStep.call(input_model, skip=False, + algorithm=algorithm, save_results=True) assert result.meta.filename == 'jwst_nirspec_pixelreplacestep.fits' @@ -279,12 +280,12 @@ def test_pixel_replace_nirspec_ifu_container_names(tmp_cwd, tmp_path, input_mode return_files = [] # for this simple case, the results from either algorithm should # be the same - result = PixelReplaceStep.call(container, skip=False, algorithm=algorithm,save_results=True) - for dirname in [output_dir, tmp_cwd]: - result_files = glob(os.path.join(dirname, '*pixelreplacestep.fits')) - for file in result_files: - basename = os.path.basename(file) - return_files.append(basename) + result = PixelReplaceStep.call(container, skip=False, algorithm=algorithm, + save_results=True) + result_files = glob(os.path.join(tmp_cwd, '*pixelreplacestep.fits')) + for file in result_files: + basename = os.path.basename(file) + return_files.append(basename) assert expected_name[0] == return_files[0] assert expected_name[1] == return_files[1] @@ -321,7 +322,6 @@ def test_pixel_replace_nirspec_ifu_name(tmp_cwd, tmp_path, input_model_function, assert expected_name == result.meta.filename - result.close() input_model.close() From c384c2607c1767e70f00f3f21da2f825bd934946 Mon Sep 17 00:00:00 2001 From: jemorrison Date: Mon, 16 Dec 2024 11:48:59 -0700 Subject: [PATCH 12/19] added a test for invariant filename --- jwst/stpipe/tests/test_utilities.py | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/jwst/stpipe/tests/test_utilities.py b/jwst/stpipe/tests/test_utilities.py index 0a1d543d48..8c86beae0b 100644 --- a/jwst/stpipe/tests/test_utilities.py +++ b/jwst/stpipe/tests/test_utilities.py @@ -5,6 +5,10 @@ from jwst.stpipe.utilities import all_steps, NOT_SET import jwst.pipeline import jwst.step +import pytest +from stdatamodels.jwst import datamodels +from jwst.stpipe.utilities import invariant_filename + from jwst import datamodels as dm @@ -54,3 +58,32 @@ def test_record_query_step_status(): # test query not set model3 = dm.MultiSpecModel() assert query_step_status(model3, 'test_step') == NOT_SET + +# make up a datamodel for testing filename +@pytest.fixture(scope='function') +def miri_ifushort(): + """ Generate input model IFU image """ + + + mirifushort_short = { + 'detector': 'MIRIFUSHORT', + 'channel': '12', + 'band': 'SHORT', + 'name': 'MIRI' + + } + input_model = datamodels.IFUImageModel() + input_model.meta.exposure.type = 'MIR_MRS' + input_model.meta.instrument._instance.update(mirifushort_short) + input_model.meta.filename = 'test1.fits' + return input_model + + +def change_name_func(model): + model.meta.filename = "changed" + return model + +def test_invariant_filename(miri_ifushort): + invariant_save_func = invariant_filename(change_name_func) + output_model = invariant_save_func(miri_ifushort) + assert output_model.meta.filename == "test1.fits" From 36c4c252b91585d6dc8feb164acf92986f91e82d Mon Sep 17 00:00:00 2001 From: Melanie Clarke Date: Wed, 18 Dec 2024 16:25:46 -0500 Subject: [PATCH 13/19] Clarify invariant_filename test --- jwst/stpipe/tests/test_utilities.py | 25 ++++++++++++++++++++++--- jwst/stpipe/utilities.py | 5 +++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/jwst/stpipe/tests/test_utilities.py b/jwst/stpipe/tests/test_utilities.py index 8c86beae0b..3a5993b0fc 100644 --- a/jwst/stpipe/tests/test_utilities.py +++ b/jwst/stpipe/tests/test_utilities.py @@ -59,6 +59,7 @@ def test_record_query_step_status(): model3 = dm.MultiSpecModel() assert query_step_status(model3, 'test_step') == NOT_SET + # make up a datamodel for testing filename @pytest.fixture(scope='function') def miri_ifushort(): @@ -81,9 +82,27 @@ def miri_ifushort(): def change_name_func(model): model.meta.filename = "changed" + model.meta.cal_step.pixel_replace = "COMPLETE" return model -def test_invariant_filename(miri_ifushort): + +def test_invariant_filename(): + # Make sure the change_name_func changes the name and has side effects + # (here, setting a status variable, but normally, actually saving the file) + input_model = datamodels.IFUImageModel() + input_model.meta.filename = 'test1.fits' + change_name_func(input_model) + assert input_model.meta.filename == 'changed' + assert input_model.meta.cal_step.pixel_replace == 'COMPLETE' + + # When the function is wrapped with invariant_filename, + # the filename is not changed, but the side effect still happens + input_model = datamodels.IFUImageModel() + input_model.meta.filename = 'test2.fits' invariant_save_func = invariant_filename(change_name_func) - output_model = invariant_save_func(miri_ifushort) - assert output_model.meta.filename == "test1.fits" + output_model = invariant_save_func(input_model) + assert output_model.meta.filename == "test2.fits" + assert output_model.meta.cal_step.pixel_replace == 'COMPLETE' + + # The output model is not a copy - the name is reset in place + assert output_model is input_model diff --git a/jwst/stpipe/utilities.py b/jwst/stpipe/utilities.py index fcca990de7..629ac596e2 100644 --- a/jwst/stpipe/utilities.py +++ b/jwst/stpipe/utilities.py @@ -30,13 +30,14 @@ Utilities """ import importlib.util -from functools import wraps -from importlib import import_module import inspect import logging import os import re from collections.abc import Sequence +from functools import wraps +from importlib import import_module + from jwst import datamodels # Configure logging From 7bb1036d66596026e2f94de72ff0800f0aa24ec3 Mon Sep 17 00:00:00 2001 From: Melanie Clarke Date: Wed, 18 Dec 2024 16:26:19 -0500 Subject: [PATCH 14/19] Add tests for output filename for cube build --- jwst/cube_build/ifu_cube.py | 3 +- jwst/cube_build/tests/test_cube_build_step.py | 38 +++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/jwst/cube_build/ifu_cube.py b/jwst/cube_build/ifu_cube.py index 3a75f33381..26a4713bcc 100644 --- a/jwst/cube_build/ifu_cube.py +++ b/jwst/cube_build/ifu_cube.py @@ -179,10 +179,9 @@ def define_cubename(self): # that the remaining suffixes created below form the entire # list of optical elements in the final output name. suffix = self.output_name_base[self.output_name_base.rfind('_') + 1:] - if suffix in ['clear']: self.output_name_base = self.output_name_base[:self.output_name_base.rfind('_')] - + # Now compose the appropriate list of optical element suffix names # based on MRS channel and sub-channel channels = [] diff --git a/jwst/cube_build/tests/test_cube_build_step.py b/jwst/cube_build/tests/test_cube_build_step.py index d93c11e43d..f2b396c723 100644 --- a/jwst/cube_build/tests/test_cube_build_step.py +++ b/jwst/cube_build/tests/test_cube_build_step.py @@ -3,6 +3,7 @@ """ import numpy as np +import os import pytest from astropy.io import fits @@ -13,6 +14,7 @@ from jwst.cube_build import CubeBuildStep from jwst.cube_build.file_table import ErrorNoAssignWCS from jwst.cube_build.cube_build import ErrorNoChannels +from jwst.datamodels import ModelContainer @pytest.fixture(scope='module') @@ -158,7 +160,7 @@ def nirspec_data(): image.meta.instrument.name = 'NIRSPEC' image.meta.instrument.detector = 'NRS1' image.meta.exposure.type = 'NRS_IFU' - image.meta.filename = 'test_nirspec.fits' + image.meta.filename = 'test_nirspec_cal.fits' image.meta.observation.date = '2023-10-06' image.meta.observation.time = '00:00:00.000' # below values taken from regtest using file @@ -182,7 +184,7 @@ def nirspec_data(): @pytest.mark.parametrize("as_filename", [True, False]) def test_call_cube_build_nirspec(tmp_cwd, nirspec_data, tmp_path, as_filename): if as_filename: - fn = tmp_path / 'test_nirspec.fits' + fn = tmp_path / 'test_nirspec_cal.fits' nirspec_data.save(fn) step_input = fn else: @@ -190,4 +192,34 @@ def test_call_cube_build_nirspec(tmp_cwd, nirspec_data, tmp_path, as_filename): step = CubeBuildStep() step.channel = '1' step.coord_system = 'internal_cal' - step.run(step_input) + step.save_results = True + result = step.run(step_input) + + assert isinstance(result, ModelContainer) + assert len(result) == 1 + model = result[0] + assert model.meta.cal_step.cube_build == 'COMPLETE' + assert model.meta.filename == 'test_nirspec_g395h-f290lp_internal_s3d.fits' + assert os.path.isfile(model.meta.filename) + + +@pytest.mark.parametrize("as_filename", [True, False]) +def test_call_cube_build_nirspec_multi(tmp_cwd, nirspec_data, tmp_path, as_filename): + if as_filename: + fn = tmp_path / 'test_nirspec_cal.fits' + nirspec_data.save(fn) + step_input = fn + else: + step_input = nirspec_data + step = CubeBuildStep() + step.channel = '1' + step.coord_system = 'internal_cal' + step.save_results = True + step.output_type = 'multi' + result = step.run(step_input) + + assert isinstance(result, ModelContainer) + assert len(result) == 1 + model = result[0] + assert model.meta.cal_step.cube_build == 'COMPLETE' + assert model.meta.filename == 'test_nirspec_s3d.fits' From ff95e7b3788cf85839214aa6eaa4ff756eaa3852 Mon Sep 17 00:00:00 2001 From: Melanie Clarke Date: Wed, 18 Dec 2024 16:27:16 -0500 Subject: [PATCH 15/19] Restore pixel_replace output, set output_use_model default --- jwst/pixel_replace/pixel_replace_step.py | 33 +++---- .../pixel_replace/tests/test_pixel_replace.py | 94 +++++-------------- 2 files changed, 36 insertions(+), 91 deletions(-) diff --git a/jwst/pixel_replace/pixel_replace_step.py b/jwst/pixel_replace/pixel_replace_step.py index 1124a1d1e7..1df5938f6c 100644 --- a/jwst/pixel_replace/pixel_replace_step.py +++ b/jwst/pixel_replace/pixel_replace_step.py @@ -1,11 +1,8 @@ -#! /usr/bin/env python from functools import partial -from ..stpipe import Step -from jwst.stpipe import record_step_status from jwst import datamodels -from .pixel_replace import PixelReplacement -from jwst.stpipe.utilities import invariant_filename +from jwst.pixel_replace.pixel_replace import PixelReplacement +from jwst.stpipe import record_step_status, Step __all__ = ["PixelReplaceStep"] @@ -34,6 +31,7 @@ class PixelReplaceStep(Step): algorithm = option("fit_profile", "mingrad", "N/A", default="fit_profile") n_adjacent_cols = integer(default=3) # Number of adjacent columns to use in creation of profile skip = boolean(default=True) # Step must be turned on by parameter reference or user + output_use_model = boolean(default=True) # Use input filenames in the output models """ def process(self, input): @@ -55,7 +53,7 @@ def process(self, input): if isinstance(input_model, (datamodels.MultiSlitModel, datamodels.SlitModel, - datamodels.ImageModel, + datamodels.ImageModel, datamodels.IFUImageModel, datamodels.CubeModel)): self.log.debug(f'Input is a {input_model.meta.model_type}.') @@ -77,10 +75,10 @@ def process(self, input): # calewbb_spec3 case / ModelContainer # __________________________________ if isinstance(input_model, datamodels.ModelContainer): - # Setup output path naming if associations are involved. - # if input is ModelContainer do not copy the input_model - # because assocation information is not copied. - # Instead update input_modelin place. + output_model = input_model + + # Setup output path naming if associations are involved, to + # include the ASN ID in the output asn_id = None try: asn_id = input_model.asn_table["asn_id"] @@ -88,12 +86,6 @@ def process(self, input): pass if asn_id is None: asn_id = self.search_attr('asn_id') - if asn_id is None: # it is still None. It does not exist. A ModelContainer was passed in with - # no asn information - # to create the correct output name set the following. - self.output_use_model = True - self.save_model = invariant_filename(self.save_model) - if asn_id is not None: _make_output_path = self.search_attr( '_make_output_path', parent_first=True @@ -104,7 +96,7 @@ def process(self, input): ) # Check models to confirm they are the correct type - for i, model in enumerate(input_model): + for i, model in enumerate(output_model): run_pixel_replace = True if model.meta.model_type in ['MultiSlitModel', 'SlitModel', 'ImageModel', 'IFUImageModel', 'CubeModel']: @@ -120,9 +112,10 @@ def process(self, input): if run_pixel_replace: replacement = PixelReplacement(model, **pars) replacement.replace() - model = replacement.output - record_step_status(model, 'pixel_replace', success=True) - return input_model + output_model[i] = replacement.output + record_step_status(output_model[i], 'pixel_replace', success=True) + + return output_model # ________________________________________ # calewbb_spec2 case - single input model # ________________________________________ diff --git a/jwst/pixel_replace/tests/test_pixel_replace.py b/jwst/pixel_replace/tests/test_pixel_replace.py index 836082538a..92ec146967 100644 --- a/jwst/pixel_replace/tests/test_pixel_replace.py +++ b/jwst/pixel_replace/tests/test_pixel_replace.py @@ -11,6 +11,7 @@ from jwst.pixel_replace.pixel_replace_step import PixelReplaceStep from glob import glob + def cal_data(shape, bad_idx, dispaxis=1, model='slit'): if model == 'image': model = datamodels.ImageModel(shape) @@ -202,10 +203,9 @@ def test_pixel_replace_multislit(input_model_function, algorithm): @pytest.mark.slow -@pytest.mark.parametrize('input_model_function', - [nirspec_ifu]) +@pytest.mark.parametrize('input_model_function', [nirspec_ifu]) @pytest.mark.parametrize('algorithm', ['fit_profile', 'mingrad']) -def test_pixel_replace_nirspec_ifu(input_model_function, algorithm): +def test_pixel_replace_nirspec_ifu(tmp_cwd, input_model_function, algorithm): """ Test pixel replacement for NIRSpec IFU. @@ -223,7 +223,9 @@ def test_pixel_replace_nirspec_ifu(input_model_function, algorithm): algorithm=algorithm, save_results=True) assert result.meta.filename == 'jwst_nirspec_pixelreplacestep.fits' - + assert result.meta.cal_step.pixel_replace == 'COMPLETE' + assert os.path.isfile(result.meta.filename) + for ext in ['data', 'err', 'var_poisson', 'var_rnoise', 'var_flat']: # non-science edges are uncorrected assert np.all(np.isnan(getattr(result, ext)[..., :, 1])) @@ -247,81 +249,31 @@ def test_pixel_replace_nirspec_ifu(input_model_function, algorithm): input_model.close() - - -@pytest.mark.slow -@pytest.mark.parametrize('input_model_function', - [nirspec_ifu]) -@pytest.mark.parametrize('algorithm', ['fit_profile', 'mingrad']) -def test_pixel_replace_nirspec_ifu_container_names(tmp_cwd, tmp_path, input_model_function, algorithm): - """ - Test pixel replacement for NIRSpec IFU using a container - - Larger data and more WCS operations required for testing make - this test take more than a minute, so marking this test 'slow'. - - The test is otherwise the same as for other modes. - """ - output_dir = tmp_path / 'output' - output_dir.mkdir(exist_ok=True) - output_dir = str(output_dir) - - input_model, bad_idx = input_model_function() +@pytest.mark.parametrize('input_model_function', [nirspec_fs_slitmodel]) +def test_pixel_replace_container_names(tmp_cwd, input_model_function): + """Test pixel replace output names for input container.""" + input_model, _ = input_model_function() input_model.meta.filename = 'jwst_nirspec_1_cal.fits' - input_model2, bad_idx2 = input_model_function() + input_model2, _ = input_model_function() input_model2.meta.filename = 'jwst_nirspec_2_cal.fits' cfiles = [input_model, input_model2] container = ModelContainer(cfiles) - expected_name = [] - expected_name.append('jwst_nirspec_1_pixelreplacestep.fits') - expected_name.append('jwst_nirspec_2_pixelreplacestep.fits') + expected_name = ['jwst_nirspec_1_pixelreplacestep.fits', + 'jwst_nirspec_2_pixelreplacestep.fits'] + + result = PixelReplaceStep.call(container, skip=False, save_results=True) + for i, model in enumerate(result): + assert model.meta.filename == expected_name[i] + assert model.meta.cal_step.pixel_replace == 'COMPLETE' - return_files = [] - # for this simple case, the results from either algorithm should - # be the same - result = PixelReplaceStep.call(container, skip=False, algorithm=algorithm, - save_results=True) result_files = glob(os.path.join(tmp_cwd, '*pixelreplacestep.fits')) - for file in result_files: + for i, file in enumerate(result_files): basename = os.path.basename(file) - return_files.append(basename) - - assert expected_name[0] == return_files[0] - assert expected_name[1] == return_files[1] - - result.close() - input_model.close() - - - -@pytest.mark.slow -@pytest.mark.parametrize('input_model_function', - [nirspec_ifu]) -@pytest.mark.parametrize('algorithm', ['fit_profile', 'mingrad']) -def test_pixel_replace_nirspec_ifu_name(tmp_cwd, tmp_path, input_model_function, algorithm): - """ - Test pixel replacement for NIRSpec IFU using a single file - - Larger data and more WCS operations required for testing make - this test take more than a minute, so marking this test 'slow'. - - The test is otherwise the same as for other modes. - """ - output_dir = tmp_path / 'output' - output_dir.mkdir(exist_ok=True) - output_dir = str(output_dir) - - input_model, bad_idx = input_model_function() - input_model.meta.filename = 'jwst_nirspec_cal.fits' - expected_name = 'jwst_nirspec_pixelreplacestep.fits' - - # for this simple case, the results from either algorithm should - # be the same - result = PixelReplaceStep.call(input_model, skip=False, algorithm=algorithm,save_results=True) - - assert expected_name == result.meta.filename + assert expected_name[i] == basename + with datamodels.open(file) as model: + assert model.meta.cal_step.pixel_replace == 'COMPLETE' + assert model.meta.filename == expected_name[i] result.close() input_model.close() - From 112c6fbca4ede7095ddb4e4513cc6ab40d174475 Mon Sep 17 00:00:00 2001 From: Melanie Clarke Date: Wed, 18 Dec 2024 16:40:48 -0500 Subject: [PATCH 16/19] Update change note --- changes/8979.pixel_replace.rst | 1 - changes/9019.pixel_replace.rst | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 changes/8979.pixel_replace.rst create mode 100644 changes/9019.pixel_replace.rst diff --git a/changes/8979.pixel_replace.rst b/changes/8979.pixel_replace.rst deleted file mode 100644 index 3c2df1c8c2..0000000000 --- a/changes/8979.pixel_replace.rst +++ /dev/null @@ -1 +0,0 @@ -fix a bug in pixel_replace and cube_build output filenames diff --git a/changes/9019.pixel_replace.rst b/changes/9019.pixel_replace.rst new file mode 100644 index 0000000000..9c961ad048 --- /dev/null +++ b/changes/9019.pixel_replace.rst @@ -0,0 +1 @@ +Base output filenames on input filenames when the step is called outside the pipeline, in order to create sensible names when the input is a list of models. From 8f2b88d01dea04e873970131c0440cbd12f66dc6 Mon Sep 17 00:00:00 2001 From: Melanie Clarke Date: Thu, 19 Dec 2024 09:15:00 -0500 Subject: [PATCH 17/19] Fix filename order in test --- jwst/pixel_replace/tests/test_pixel_replace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jwst/pixel_replace/tests/test_pixel_replace.py b/jwst/pixel_replace/tests/test_pixel_replace.py index 92ec146967..dcf8c96fa5 100644 --- a/jwst/pixel_replace/tests/test_pixel_replace.py +++ b/jwst/pixel_replace/tests/test_pixel_replace.py @@ -268,7 +268,7 @@ def test_pixel_replace_container_names(tmp_cwd, input_model_function): assert model.meta.cal_step.pixel_replace == 'COMPLETE' result_files = glob(os.path.join(tmp_cwd, '*pixelreplacestep.fits')) - for i, file in enumerate(result_files): + for i, file in enumerate(sorted(result_files)): basename = os.path.basename(file) assert expected_name[i] == basename with datamodels.open(file) as model: From 1834ec09f287fef20e283e5c464bc5231f380e88 Mon Sep 17 00:00:00 2001 From: Melanie Clarke Date: Thu, 19 Dec 2024 09:35:23 -0500 Subject: [PATCH 18/19] Fix typos --- jwst/pixel_replace/pixel_replace_step.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/jwst/pixel_replace/pixel_replace_step.py b/jwst/pixel_replace/pixel_replace_step.py index 1df5938f6c..2bfe166c0e 100644 --- a/jwst/pixel_replace/pixel_replace_step.py +++ b/jwst/pixel_replace/pixel_replace_step.py @@ -71,14 +71,12 @@ def process(self, input): 'n_adjacent_cols': self.n_adjacent_cols, } - # ___________________________________ - # calewbb_spec3 case / ModelContainer - # __________________________________ + # calwebb_spec3 case / ModelContainer if isinstance(input_model, datamodels.ModelContainer): output_model = input_model - # Setup output path naming if associations are involved, to - # include the ASN ID in the output + # Set up output path name to include the ASN ID + # if associations are involved asn_id = None try: asn_id = input_model.asn_table["asn_id"] @@ -116,9 +114,8 @@ def process(self, input): record_step_status(output_model[i], 'pixel_replace', success=True) return output_model - # ________________________________________ - # calewbb_spec2 case - single input model - # ________________________________________ + + # calwebb_spec2 case / single input model else: # Make copy of input to prevent overwriting result = input_model.copy() From 095d364335268710228e5ad8bb39a2a8512190d8 Mon Sep 17 00:00:00 2001 From: Melanie Clarke Date: Thu, 19 Dec 2024 09:39:40 -0500 Subject: [PATCH 19/19] Remove unused test fixture --- jwst/stpipe/tests/test_utilities.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/jwst/stpipe/tests/test_utilities.py b/jwst/stpipe/tests/test_utilities.py index 3a5993b0fc..145440c6f9 100644 --- a/jwst/stpipe/tests/test_utilities.py +++ b/jwst/stpipe/tests/test_utilities.py @@ -5,7 +5,6 @@ from jwst.stpipe.utilities import all_steps, NOT_SET import jwst.pipeline import jwst.step -import pytest from stdatamodels.jwst import datamodels from jwst.stpipe.utilities import invariant_filename @@ -60,26 +59,6 @@ def test_record_query_step_status(): assert query_step_status(model3, 'test_step') == NOT_SET -# make up a datamodel for testing filename -@pytest.fixture(scope='function') -def miri_ifushort(): - """ Generate input model IFU image """ - - - mirifushort_short = { - 'detector': 'MIRIFUSHORT', - 'channel': '12', - 'band': 'SHORT', - 'name': 'MIRI' - - } - input_model = datamodels.IFUImageModel() - input_model.meta.exposure.type = 'MIR_MRS' - input_model.meta.instrument._instance.update(mirifushort_short) - input_model.meta.filename = 'test1.fits' - return input_model - - def change_name_func(model): model.meta.filename = "changed" model.meta.cal_step.pixel_replace = "COMPLETE"