From 98c5ec5c7a846e36d520eb359392eb56ea54c5ad Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Thu, 14 Nov 2024 11:07:13 -0500 Subject: [PATCH] Add test to demonstrate the filter for asdf file reads --- gwcs/examples.py | 11 +++++++++++ gwcs/tests/test_wcs.py | 27 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/gwcs/examples.py b/gwcs/examples.py index 8e3b3e36..61fc9387 100644 --- a/gwcs/examples.py +++ b/gwcs/examples.py @@ -73,6 +73,17 @@ def gwcs_2d_shift_scale(): pipe = [(DETECTOR_2D_FRAME, m3), (ICRC_SKY_FRAME, None)] return wcs.WCS(pipe) +def gwcs_2d_bad_bounding_box_order(): + m1 = models.Shift(1) & models.Shift(2) + m2 = models.Scale(5) & models.Scale(10) + m3 = m1 | m2 + + # Purposefully set the bounding box in the wrong order + m3.bounding_box = ((1, 2), (3, 4)) + + pipe = [(DETECTOR_2D_FRAME, m3), (ICRC_SKY_FRAME, None)] + return wcs.WCS(pipe) + def gwcs_1d_freq_quantity(): diff --git a/gwcs/tests/test_wcs.py b/gwcs/tests/test_wcs.py index 9387922d..39755aa8 100644 --- a/gwcs/tests/test_wcs.py +++ b/gwcs/tests/test_wcs.py @@ -25,6 +25,7 @@ from ..utils import CoordinateFrameError from .utils import _gwcs_from_hst_fits_wcs from . import data +from ..examples import gwcs_2d_bad_bounding_box_order data_path = os.path.split(os.path.abspath(data.__file__))[0] @@ -1443,3 +1444,29 @@ def test_bounding_box_is_returned_F(): # Show the the bounding box is different between the two WCS objects assert gwcs_object_after.bounding_box != gwcs_object_before.bounding_box + + +def test_no_bounding_box_if_read_from_file(tmp_path): + bad_wcs = gwcs_2d_bad_bounding_box_order() + + # Check the waring is issued for the bounding box of this WCS object + with pytest.warns(wcs.GwcsBoundingBoxWarning): + bad_wcs.bounding_box + + # Check that the warning is not issued again the second time + with warnings.catch_warnings(): + warnings.simplefilter("error") + bad_wcs.bounding_box + + # Write a bad wcs bounding box to an asdf file + asdf_file = tmp_path / "bad_wcs.asdf" + af = asdf.AsdfFile({"wcs": gwcs_2d_bad_bounding_box_order()}) # re-create the bad wcs object + af.write_to(asdf_file) + + with asdf.open(asdf_file) as af: + wcs_from_file = af["wcs"] + + # Check that no warning is issued for the bounding box of this WCS object + with warnings.catch_warnings(): + warnings.simplefilter("error") + wcs_from_file.bounding_box \ No newline at end of file