From 1e3a6ddd6ba88073ec2f820258f3296be4b75175 Mon Sep 17 00:00:00 2001 From: Maria Pena-Guerrero Date: Thu, 18 Apr 2024 11:08:56 -0400 Subject: [PATCH] added reg tests --- jwst/regtest/test_miri_lrs_slit_spec3.py | 22 ++++++++++++++++++++++ jwst/regtest/test_nirspec_fs_spec3.py | 19 +++++++++++++++++++ jwst/regtest/test_nirspec_mos_spec3.py | 12 ++++++++++++ 3 files changed, 53 insertions(+) diff --git a/jwst/regtest/test_miri_lrs_slit_spec3.py b/jwst/regtest/test_miri_lrs_slit_spec3.py index 9ea82fb64a..d485c9b073 100644 --- a/jwst/regtest/test_miri_lrs_slit_spec3.py +++ b/jwst/regtest/test_miri_lrs_slit_spec3.py @@ -1,6 +1,8 @@ """ Test of the spec3 pipeline using MIRI LRS fixed-slit exposures. This takes an association and generates the level 3 products.""" import pytest +import numpy as np +from gwcs import wcstools import asdf from astropy.io.fits.diff import FITSDiff @@ -76,3 +78,23 @@ def test_miri_lrs_slit_spec3(run_pipeline, rtdata_module, fitsdiff_default_kwarg # Compare the results diff = FITSDiff(rtdata.output, rtdata.truth, **fitsdiff_default_kwargs) assert diff.identical, diff.report() + + if "s2d" in output: + # Compare the calculated wavelengths + tolerance = 1e-03 + dmt = datamodels.open(rtdata.truth) + dmr = datamodels.open(rtdata.output) + if isinstance(dmt, datamodels.MultiSlitModel): + for slit_idx, slit in enumerate(dmt.slits): + w = slit.meta.wcs + x, y = wcstools.grid_from_bounding_box(w.bounding_box, step=(1, 1), center=True) + _, _, wave = w(x, y) + wlr = dmr.slits[slit_idx].wavelength + assert np.all(np.isclose(wave, wlr, atol=tolerance)) + else: + w = dmt.meta.wcs + x, y = wcstools.grid_from_bounding_box(w.bounding_box, step=(1, 1), center=True) + _, _, wave = w(x, y) + wlr = dmr.wavelength + assert np.all(np.isclose(wave, wlr, atol=tolerance)) + diff --git a/jwst/regtest/test_nirspec_fs_spec3.py b/jwst/regtest/test_nirspec_fs_spec3.py index 10e205e870..54c101ad06 100644 --- a/jwst/regtest/test_nirspec_fs_spec3.py +++ b/jwst/regtest/test_nirspec_fs_spec3.py @@ -2,6 +2,7 @@ import pytest from jwst.stpipe import Step +from stdatamodels.jwst import datamodels @pytest.fixture(scope="module") @@ -42,3 +43,21 @@ def test_nirspec_fs_spec3(run_pipeline, rtdata_module, fitsdiff_default_kwargs, # Compare the results diff = FITSDiff(rtdata.output, rtdata.truth, **fitsdiff_default_kwargs) assert diff.identical, diff.report() + + if "s2d" in output: + # Compare the calculated wavelengths + tolerance = 1e-03 + dmt = datamodels.open(rtdata.truth) + dmr = datamodels.open(rtdata.output) + if isinstance(dmt, datamodels.MultiSlitModel): + w = slit.meta.wcs + x, y = wcstools.grid_from_bounding_box(w.bounding_box, step=(1, 1), center=True) + _, _, wave = w(x, y) + wlr = dmr.slits[slit_idx].wavelength + assert np.all(np.isclose(wave, wlr, atol=tolerance)) + else: + w = dmt.meta.wcs + x, y = wcstools.grid_from_bounding_box(w.bounding_box, step=(1, 1), center=True) + _, _, wave = w(x, y) + wlr = dmr.wavelength + assert np.all(np.isclose(wave, wlr, atol=tolerance)) diff --git a/jwst/regtest/test_nirspec_mos_spec3.py b/jwst/regtest/test_nirspec_mos_spec3.py index 59d9049837..0ac2e37897 100644 --- a/jwst/regtest/test_nirspec_mos_spec3.py +++ b/jwst/regtest/test_nirspec_mos_spec3.py @@ -2,6 +2,7 @@ from astropy.io.fits.diff import FITSDiff from jwst.stpipe import Step +from stdatamodels.jwst import datamodels @pytest.fixture(scope="module") @@ -36,3 +37,14 @@ def test_nirspec_mos_spec3(run_pipeline, suffix, source_id, fitsdiff_default_kwa diff = FITSDiff(rtdata.output, rtdata.truth, **fitsdiff_default_kwargs) assert diff.identical, diff.report() + + if "s2d" in output: + # Compare the calculated wavelengths + dmt = datamodels.open(rtdata.truth) + dmr = datamodels.open(rtdata.output) + for slit_idx, slit in enumerate(dmt.slits): + w = slit.meta.wcs + x, y = wcstools.grid_from_bounding_box(w.bounding_box, step=(1, 1), center=True) + _, _, wave = w(x, y) + wlr = dmr.slits[slit_idx].wavelength + assert np.all(np.isclose(wave, wlr, atol=1e-03))