Skip to content

Commit dd78bdc

Browse files
committed
Separate nsclean tests from standard runs
1 parent 59be54c commit dd78bdc

File tree

3 files changed

+126
-16
lines changed

3 files changed

+126
-16
lines changed

jwst/regtest/test_nirspec_fs_spec2.py

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ def run_pipeline(rtdata_module, request, resource_tracker):
5252
# Run the calwebb_spec2 pipeline; save results from intermediate steps
5353
args = ["calwebb_spec2", rtdata.input,
5454
"--steps.assign_wcs.save_results=true",
55-
"--steps.nsclean.skip=False",
56-
"--steps.nsclean.save_results=true",
5755
"--steps.extract_2d.save_results=true",
5856
"--steps.wavecorr.save_results=true",
5957
"--steps.srctype.save_results=true",
@@ -67,6 +65,28 @@ def run_pipeline(rtdata_module, request, resource_tracker):
6765
return rtdata
6866

6967

68+
@pytest.fixture(scope="module")
69+
def run_pipeline_nsclean(rtdata_module):
70+
"""Run the calwebb_spec2 pipeline on NIRSpec Fixed-Slit exposures with nsclean."""
71+
72+
rtdata = rtdata_module
73+
74+
filename = "jw01245-o002_20230107t223023_spec2_00001_asn.json"
75+
rtdata.get_asn('nirspec/fs/' + filename)
76+
77+
# Run the calwebb_spec2 pipeline with nsclean
78+
args = ["calwebb_spec2", rtdata.input,
79+
"--output_file=jw01245002001_04102_00002_nrs1_nsc",
80+
"--steps.nsclean.skip=False",
81+
"--steps.nsclean.save_results=true"]
82+
83+
# FIXME: Handle warnings properly.
84+
# Example: RuntimeWarning: overflow encountered in square
85+
Step.from_cmdline(args)
86+
87+
return rtdata
88+
89+
7090
@pytest.fixture(scope="module")
7191
def run_pipeline_pixel_replace(rtdata_module):
7292
"""Run the calwebb_spec2 pipeline on NIRSpec Fixed-Slit exposures including pixel replacement.
@@ -93,7 +113,7 @@ def test_log_tracked_resources_spec2(log_tracked_resources, run_pipeline):
93113

94114

95115
@pytest.mark.parametrize("suffix", [
96-
"assign_wcs", "nsclean", "extract_2d", "wavecorr", "flat_field", "pathloss", "srctype",
116+
"assign_wcs", "extract_2d", "wavecorr", "flat_field", "pathloss", "srctype",
97117
"cal", "s2d", "x1d"])
98118
def test_nirspec_fs_spec2(run_pipeline, fitsdiff_default_kwargs, suffix):
99119
"""Regression test of the calwebb_spec2 pipeline on a
@@ -113,6 +133,24 @@ def test_nirspec_fs_spec2(run_pipeline, fitsdiff_default_kwargs, suffix):
113133
assert diff.identical, diff.report()
114134

115135

136+
@pytest.mark.parametrize("suffix", ["nsclean", "cal", "s2d", "x1d"])
137+
def test_nirspec_fs_nsclean(run_pipeline_nsclean, fitsdiff_default_kwargs, suffix):
138+
"""Regression test of the calwebb_spec2 pipeline with nsclean."""
139+
140+
# Run the pipeline and retrieve outputs
141+
rtdata = run_pipeline_nsclean
142+
basename = "jw01245002001_04102_00002_nrs1_nsc"
143+
output = f"{basename}_{suffix}.fits"
144+
rtdata.output = output
145+
146+
# Get the truth files
147+
rtdata.get_truth(os.path.join("truth/test_nirspec_fs_spec2", output))
148+
149+
# Compare the results
150+
diff = FITSDiff(rtdata.output, rtdata.truth, **fitsdiff_default_kwargs)
151+
assert diff.identical, diff.report()
152+
153+
116154
@pytest.mark.parametrize(
117155
'output',
118156
['jw013090_prtest_04102_00004_nrs2_pixel_replace.fits',

jwst/regtest/test_nirspec_ifu_spec2.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,41 @@ def run_spec2(rtdata_module, resource_tracker):
2727
'args': [
2828
'--steps.assign_wcs.save_results=true',
2929
'--steps.msa_flagging.save_results=true',
30-
'--steps.nsclean.skip=False',
31-
'--steps.nsclean.save_results=true',
3230
'--steps.srctype.save_results=true',
3331
'--steps.flat_field.save_results=true',
3432
'--steps.pathloss.save_results=true',
3533
]
3634
}
37-
# FIXME: Handle warnings properly.
38-
# Example: RuntimeWarning: Invalid interval: upper bound XXX is strictly less than lower bound XXX
35+
3936
with resource_tracker.track():
4037
rtdata = rt.run_step_from_dict(rtdata, **step_params)
4138
return rtdata
4239

4340

41+
@pytest.fixture(scope='module')
42+
def run_spec2_nsclean(rtdata_module, resource_tracker):
43+
"""Run the Spec2Pipeline on a spec2 ASN containing a single exposure"""
44+
rtdata = rtdata_module
45+
46+
# Set up the inputs
47+
asn_name = 'jw01251-o004_20221105t023552_spec2_031_asn.json'
48+
asn_path = INPUT_PATH + '/' + asn_name
49+
50+
# Run the pipeline
51+
step_params = {
52+
'input_path': asn_path,
53+
'step': 'calwebb_spec2',
54+
'args': [
55+
'--output_file=jw01251004001_03107_00002_nrs1_nsc',
56+
'--steps.nsclean.skip=False',
57+
'--steps.nsclean.save_results=true',
58+
]
59+
}
60+
61+
rtdata = rt.run_step_from_dict(rtdata, **step_params)
62+
return rtdata
63+
64+
4465
@pytest.mark.slow
4566
def test_log_tracked_resources_spec2(log_tracked_resources, run_spec2):
4667
log_tracked_resources()
@@ -50,14 +71,24 @@ def test_log_tracked_resources_spec2(log_tracked_resources, run_spec2):
5071
@pytest.mark.parametrize(
5172
'suffix',
5273
['assign_wcs', 'cal', 'flat_field', 'msa_flagging',
53-
'nsclean', 'pathloss', 's3d', 'srctype', 'x1d']
74+
'pathloss', 's3d', 'srctype', 'x1d']
5475
)
5576
def test_spec2(run_spec2, fitsdiff_default_kwargs, suffix):
5677
"""Regression test matching output files"""
5778
rt.is_like_truth(run_spec2, fitsdiff_default_kwargs, suffix,
5879
truth_path=TRUTH_PATH)
5980

6081

82+
@pytest.mark.slow
83+
@pytest.mark.parametrize(
84+
'suffix',
85+
['nsc_nsclean', 'nsc_cal', 'nsc_s3d', 'nsc_x1d']
86+
)
87+
def test_spec2_nsclean(run_spec2_nsclean, fitsdiff_default_kwargs, suffix):
88+
"""Regression test matching output files"""
89+
rt.is_like_truth(run_spec2_nsclean, fitsdiff_default_kwargs, suffix,
90+
truth_path=TRUTH_PATH)
91+
6192
@pytest.fixture
6293
def run_photom(rtdata):
6394
"""Run the photom step on an NRS IFU exposure with SRCTYPE=POINT"""

jwst/regtest/test_nirspec_mos_spec2.py

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,40 @@ def run_pipeline(rtdata_module, resource_tracker):
2424
args = ["calwebb_spec2", rtdata.input,
2525
"--steps.assign_wcs.save_results=true",
2626
"--steps.msa_flagging.save_results=true",
27-
"--steps.nsclean.skip=False",
28-
"--steps.nsclean.save_results=true",
2927
"--steps.bkg_subtract.save_results=true",
3028
"--steps.extract_2d.save_results=true",
3129
"--steps.srctype.save_results=true",
3230
"--steps.wavecorr.save_results=true",
3331
"--steps.flat_field.save_results=true",
3432
"--steps.pathloss.save_results=true",
3533
"--steps.barshadow.save_results=true"]
36-
# FIXME: Handle warnings properly.
37-
# Example: RuntimeWarning: Invalid interval: upper bound XXX is strictly less than lower bound XXX
38-
with pytest.warns(AstropyUserWarning, match="Input data contains invalid values"):
39-
with resource_tracker.track():
40-
Step.from_cmdline(args)
34+
35+
with resource_tracker.track():
36+
Step.from_cmdline(args)
37+
38+
return rtdata
39+
40+
41+
@pytest.fixture(scope="module")
42+
def run_pipeline_nsclean(rtdata_module, resource_tracker):
43+
"""Run the calwebb_spec2 pipeline on NIRSpec MOS with nsclean."""
44+
45+
rtdata = rtdata_module
46+
47+
# Get the MSA metadata file referenced in the input exposure
48+
rtdata.get_data("nirspec/mos/jw01345066001_01_msa.fits")
49+
50+
# Get the input ASN file and exposures
51+
rtdata.get_asn("nirspec/mos/jw01345-o066_20230831t181155_spec2_00010_asn.json")
52+
53+
# Run the calwebb_spec2 pipeline; save results from intermediate steps
54+
args = ["calwebb_spec2", rtdata.input,
55+
"--output_file=jw01345066001_05101_00003_nrs1_nsc",
56+
"--steps.nsclean.skip=False",
57+
"--steps.nsclean.save_results=True"]
58+
59+
with resource_tracker.track():
60+
Step.from_cmdline(args)
4161

4262
return rtdata
4363

@@ -47,7 +67,7 @@ def test_log_tracked_resources(log_tracked_resources, run_pipeline):
4767

4868

4969
@pytest.mark.parametrize("suffix", [
50-
"assign_wcs", "msa_flagging", "nsclean", "bsub", "extract_2d", "wavecorr", "flat_field",
70+
"assign_wcs", "msa_flagging", "bsub", "extract_2d", "wavecorr", "flat_field",
5171
"srctype", "pathloss", "barshadow", "cal", "s2d", "x1d"])
5272
def test_nirspec_mos_spec2(run_pipeline, fitsdiff_default_kwargs, suffix):
5373
"""Regression test of the calwebb_spec2 pipeline on a
@@ -66,3 +86,24 @@ def test_nirspec_mos_spec2(run_pipeline, fitsdiff_default_kwargs, suffix):
6686
# Compare the results
6787
diff = FITSDiff(rtdata.output, rtdata.truth, **fitsdiff_default_kwargs)
6888
assert diff.identical, diff.report()
89+
90+
91+
@pytest.mark.parametrize("suffix", [
92+
"nsclean", "cal", "s2d", "x1d"])
93+
def test_nirspec_mos_spec2_nsclean(run_pipeline, fitsdiff_default_kwargs, suffix):
94+
"""Regression test of the calwebb_spec2 pipeline on a
95+
NIRSpec MOS exposure. Using an exposure that's part of a
96+
3-shutter nod sequence, so there are nodded exposures available
97+
with which to do background subtraction."""
98+
99+
# Run the pipeline and retrieve outputs
100+
rtdata = run_pipeline
101+
output = f"jw01345066001_05101_00003_nrs1_nsc_{suffix}.fits"
102+
rtdata.output = output
103+
104+
# Get the truth files
105+
rtdata.get_truth("truth/test_nirspec_mos_spec2/" + output)
106+
107+
# Compare the results
108+
diff = FITSDiff(rtdata.output, rtdata.truth, **fitsdiff_default_kwargs)
109+
assert diff.identical, diff.report()

0 commit comments

Comments
 (0)