1+ import os
12import numpy as np
23import pytest
34
45from stdatamodels .jwst import datamodels
6+ from jwst .datamodels import ModelContainer
57from stdatamodels .jwst .datamodels .dqflags import pixel as flags
68
79from jwst .assign_wcs import AssignWcsStep
810from jwst .assign_wcs .tests .test_nirspec import create_nirspec_ifu_file
911from jwst .pixel_replace .pixel_replace_step import PixelReplaceStep
12+ from glob import glob
1013
1114
1215def cal_data (shape , bad_idx , dispaxis = 1 , model = 'slit' ):
@@ -99,6 +102,7 @@ def nirspec_ifu():
99102 model .var_poisson = test_data .var_poisson
100103 model .var_rnoise = test_data .var_rnoise
101104 model .var_flat = test_data .var_flat
105+
102106 test_data .close ()
103107
104108 return model , bad_idx
@@ -199,10 +203,9 @@ def test_pixel_replace_multislit(input_model_function, algorithm):
199203
200204
201205@pytest .mark .slow
202- @pytest .mark .parametrize ('input_model_function' ,
203- [nirspec_ifu ])
206+ @pytest .mark .parametrize ('input_model_function' , [nirspec_ifu ])
204207@pytest .mark .parametrize ('algorithm' , ['fit_profile' , 'mingrad' ])
205- def test_pixel_replace_nirspec_ifu (input_model_function , algorithm ):
208+ def test_pixel_replace_nirspec_ifu (tmp_cwd , input_model_function , algorithm ):
206209 """
207210 Test pixel replacement for NIRSpec IFU.
208211
@@ -212,10 +215,16 @@ def test_pixel_replace_nirspec_ifu(input_model_function, algorithm):
212215 The test is otherwise the same as for other modes.
213216 """
214217 input_model , bad_idx = input_model_function ()
218+ input_model .meta .filename = 'jwst_nirspec_cal.fits'
215219
216220 # for this simple case, the results from either algorithm should
217221 # be the same
218- result = PixelReplaceStep .call (input_model , skip = False , algorithm = algorithm )
222+ result = PixelReplaceStep .call (input_model , skip = False ,
223+ algorithm = algorithm , save_results = True )
224+
225+ assert result .meta .filename == 'jwst_nirspec_pixelreplacestep.fits'
226+ assert result .meta .cal_step .pixel_replace == 'COMPLETE'
227+ assert os .path .isfile (result .meta .filename )
219228
220229 for ext in ['data' , 'err' , 'var_poisson' , 'var_rnoise' , 'var_flat' ]:
221230 # non-science edges are uncorrected
@@ -238,3 +247,33 @@ def test_pixel_replace_nirspec_ifu(input_model_function, algorithm):
238247
239248 result .close ()
240249 input_model .close ()
250+
251+
252+ @pytest .mark .parametrize ('input_model_function' , [nirspec_fs_slitmodel ])
253+ def test_pixel_replace_container_names (tmp_cwd , input_model_function ):
254+ """Test pixel replace output names for input container."""
255+ input_model , _ = input_model_function ()
256+ input_model .meta .filename = 'jwst_nirspec_1_cal.fits'
257+ input_model2 , _ = input_model_function ()
258+ input_model2 .meta .filename = 'jwst_nirspec_2_cal.fits'
259+ cfiles = [input_model , input_model2 ]
260+ container = ModelContainer (cfiles )
261+
262+ expected_name = ['jwst_nirspec_1_pixelreplacestep.fits' ,
263+ 'jwst_nirspec_2_pixelreplacestep.fits' ]
264+
265+ result = PixelReplaceStep .call (container , skip = False , save_results = True )
266+ for i , model in enumerate (result ):
267+ assert model .meta .filename == expected_name [i ]
268+ assert model .meta .cal_step .pixel_replace == 'COMPLETE'
269+
270+ result_files = glob (os .path .join (tmp_cwd , '*pixelreplacestep.fits' ))
271+ for i , file in enumerate (sorted (result_files )):
272+ basename = os .path .basename (file )
273+ assert expected_name [i ] == basename
274+ with datamodels .open (file ) as model :
275+ assert model .meta .cal_step .pixel_replace == 'COMPLETE'
276+ assert model .meta .filename == expected_name [i ]
277+
278+ result .close ()
279+ input_model .close ()
0 commit comments