Skip to content

Commit

Permalink
JP-2928: Update test data for NIRSpec master background (#8912)
Browse files Browse the repository at this point in the history
  • Loading branch information
melanieclarke authored Nov 7, 2024
2 parents e898f2a + 0659b9c commit bf7699e
Showing 1 changed file with 39 additions and 22 deletions.
61 changes: 39 additions & 22 deletions jwst/regtest/test_nirspec_masterbackground.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def run_spec2_mbkg(rtdata_module):
rtdata = rtdata_module

# Get data
rtdata.get_data('nirspec/mos/jw01180025001_01_msa.fits')
rtdata.get_data('nirspec/mos/jw01180025001_05101_00001_nrs2_rate.fits')
rtdata.get_data('nirspec/mos/jw01448011001_01_msa.fits')
rtdata.get_data('nirspec/mos/jw01448011001_02101_00001_nrs2_rate.fits')

# Run the pipeline
step_params = {
Expand All @@ -39,16 +39,18 @@ def run_spec2_mbkg_user(rtdata_module):
rtdata = rtdata_module

# Get data
rtdata.get_data('nirspec/mos/nrs_mos_3pointnod_1_msa.fits')
rtdata.get_data('nirspec/mos/jw00626030001_02103_00001_nrs1_masterbg1d.fits')
rtdata.get_data('nirspec/mos/jw00626030001_02103_00001_nrs1_rate.fits')
user_bg = 'jw01448011001_02101_00001_nrs2_user_bg.fits'
rtdata.get_data('nirspec/mos/jw01448011001_01_msa.fits')
rtdata.get_data(f'nirspec/mos/{user_bg}')
rtdata.get_data('nirspec/mos/jw01448011001_02101_00001_nrs2_rate.fits')

# Run the pipeline
step_params = {
'step': 'calwebb_spec2',
'args': [
'--steps.master_background_mos.skip=false',
'--steps.master_background_mos.user_background=jw00626030001_02103_00001_nrs1_masterbg1d.fits'
f'--steps.master_background_mos.user_background={user_bg}',
f'--output_file={user_bg}'
]
}
rtdata = rt.run_step_from_dict(rtdata, **step_params)
Expand All @@ -57,7 +59,7 @@ def run_spec2_mbkg_user(rtdata_module):

def test_masterbkg_rerun(rtdata):
"""Test to ensure sequential runs of the step are consistent"""
with dm.open(rtdata.get_data('nirspec/mos/nrs_mos_with_bkgslits_srctype.fits')) as data:
with dm.open(rtdata.get_data('nirspec/mos/jw01448011001_02101_00001_nrs2_srctype.fits')) as data:
mbs = MasterBackgroundMosStep()
corrected = mbs.run(data)
corrected_again = mbs.run(data)
Expand All @@ -72,7 +74,7 @@ def test_masterbkg_rerun(rtdata):

def test_masterbkg_corrpars(rtdata):
"""Test for correction parameters"""
with dm.open(rtdata.get_data('nirspec/mos/nrs_mos_with_bkgslits_srctype.fits')) as data:
with dm.open(rtdata.get_data('nirspec/mos/jw01448011001_02101_00001_nrs2_srctype.fits')) as data:
mbs = MasterBackgroundMosStep()
corrected = mbs.run(data)

Expand All @@ -94,6 +96,11 @@ def test_masterbkg_corrpars(rtdata):
def test_nirspec_mos_mbkg(suffix, run_spec2_mbkg, fitsdiff_default_kwargs):
"""Run spec2 with master background"""
rtdata = run_spec2_mbkg

# Adjust tolerance for machine precision with float32 drizzle code
if suffix == "s2d":
fitsdiff_default_kwargs["rtol"] = 1e-2
fitsdiff_default_kwargs["atol"] = 2e-4
rt.is_like_truth(rtdata, fitsdiff_default_kwargs, suffix, truth_path='truth/test_nirspec_mos_mbkg')


Expand All @@ -104,23 +111,33 @@ def test_nirspec_mos_mbkg(suffix, run_spec2_mbkg, fitsdiff_default_kwargs):
def test_nirspec_mos_mbkg_user(suffix, run_spec2_mbkg_user, fitsdiff_default_kwargs):
"""Run spec2 with master background and user-supplied mbkg"""
rtdata = run_spec2_mbkg_user
rt.is_like_truth(rtdata, fitsdiff_default_kwargs, suffix, truth_path='truth/test_nirspec_mos_mbkg_user')

output_filename = f"jw01448011001_02101_00001_nrs2_user_bg_{suffix}.fits"
rtdata.output = output_filename
rtdata.get_truth(f"truth/test_nirspec_mos_mbkg_user/{output_filename}")

# Adjust tolerance for machine precision with float32 drizzle code
if suffix == "s2d":
fitsdiff_default_kwargs["rtol"] = 1e-2
fitsdiff_default_kwargs["atol"] = 2e-4
diff = FITSDiff(rtdata.output, rtdata.truth, **fitsdiff_default_kwargs)
assert diff.identical, diff.report()


def test_nirspec_fs_mbkg_user(rtdata, fitsdiff_default_kwargs):
"""Run a test for NIRSpec FS data with a user-supplied background file."""

# Get user-supplied background
user_background = "v2_nrs_bkg_user_clean_x1d.fits"
user_background = "jw01309-o022_b000000021_nirspec_f290lp-g395h-s200a1-allslits_x1d.fits"
rtdata.get_data(f"nirspec/fs/{user_background}")

# Get input data
rtdata.get_data("nirspec/fs/nrs_sci+bkg_cal.fits")
rtdata.get_data("nirspec/fs/jw01309022001_04102_00001_nrs1_cal.fits")

MasterBackgroundStep.call(rtdata.input, save_results=True, suffix='master_background',
MasterBackgroundStep.call(rtdata.input, save_results=True, suffix='mbsub',
user_background=user_background)

output = "nrs_sci+bkg_master_background.fits"
output = "jw01309022001_04102_00001_nrs1_mbsub.fits"
rtdata.output = output

# Get the truth file
Expand All @@ -134,16 +151,16 @@ def test_nirspec_fs_mbkg_user(rtdata, fitsdiff_default_kwargs):
def test_nirspec_ifu_mbkg_user(rtdata, fitsdiff_default_kwargs):
"""Test NIRSpec IFU data with a user-supplied background file."""
# Get user-supplied background
user_background = "prism_bkg_x1d.fits"
user_background = "jw01252-o002_t005_nirspec_prism-clear_x1d.fits"
rtdata.get_data(f"nirspec/ifu/{user_background}")

# Get input data
rtdata.get_data("nirspec/ifu/prism_sci_bkg_cal.fits")
rtdata.get_data("nirspec/ifu/jw01252001001_03101_00001_nrs1_cal.fits")

MasterBackgroundStep.call(rtdata.input, user_background=user_background,
save_results=True, suffix='master_background')
save_results=True, suffix='mbsub')

output = "prism_sci_bkg_master_background.fits"
output = "jw01252001001_03101_00001_nrs1_mbsub.fits"
rtdata.output = output

# Get the truth file
Expand All @@ -156,18 +173,18 @@ def test_nirspec_ifu_mbkg_user(rtdata, fitsdiff_default_kwargs):

@pytest.mark.parametrize(
'output_file',
['ifu_prism_source_on_NRS1_master_background.fits',
'ifu_prism_source_off_NRS1_o001_masterbg1d.fits',
'ifu_prism_source_on_NRS1_o001_masterbg2d.fits'],
['jw01252001001_03101_00001_nrs1_mbsub.fits',
'jw01252-o002_t005_nirspec_prism-clear_o001_masterbg1d.fits',
'jw01252001001_03101_00001_nrs1_o001_masterbg2d.fits'],
ids=["on-source", "off-source", "on-source2d"]
)
def test_nirspec_ifu_mbkg_nod(rtdata, fitsdiff_default_kwargs, output_file):
"""Test NIRSpec IFU prism nodded data."""
# Get input data
rtdata.get_asn("nirspec/ifu/nirspec_spec3_asn.json")
rtdata.get_asn("nirspec/ifu/jw01252-o001_spec3_00003_asn_with_bg.json")

MasterBackgroundStep.call(rtdata.input, save_background=True, save_results=True,
suffix='master_background')
suffix='mbsub')

rtdata.output = output_file

Expand Down

0 comments on commit bf7699e

Please sign in to comment.