Skip to content

Commit

Permalink
Add test to demonstrate the filter for asdf file reads
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson committed Nov 14, 2024
1 parent 0643813 commit ca3ff77
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions gwcs/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():

Expand Down
27 changes: 27 additions & 0 deletions gwcs/tests/test_wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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

0 comments on commit ca3ff77

Please sign in to comment.