diff --git a/reproject/tests/data/image_with_distortion_map.fits b/reproject/tests/data/image_with_distortion_map.fits new file mode 100644 index 000000000..9bd894515 Binary files /dev/null and b/reproject/tests/data/image_with_distortion_map.fits differ diff --git a/reproject/tests/test_utils.py b/reproject/tests/test_utils.py index 21f1ee408..967118b27 100644 --- a/reproject/tests/test_utils.py +++ b/reproject/tests/test_utils.py @@ -2,6 +2,7 @@ import numpy as np import pytest from astropy.io import fits +from astropy.utils.data import get_pkg_data_filename from astropy.wcs import WCS from reproject.conftest import set_wcs_array_shape @@ -41,6 +42,12 @@ def test_parse_input_data_missing_hdu_in(): parse_input_data(hdulist) +def test_parse_input_data_distortion_map(): + # Verify that the file can be successfully loaded and parsed + fname = get_pkg_data_filename("data/image_with_distortion_map.fits", package="reproject.tests") + parse_input_data(fname, hdu_in=0) + + @pytest.mark.filterwarnings("ignore:unclosed file:ResourceWarning") def test_parse_input_shape(tmpdir, valid_celestial_input_shapes): """ diff --git a/reproject/utils.py b/reproject/utils.py index b5428857d..5d17e5652 100644 --- a/reproject/utils.py +++ b/reproject/utils.py @@ -92,7 +92,7 @@ def hdu_to_numpy_memmap(hdu): ) -def parse_input_data(input_data, hdu_in=None): +def parse_input_data(input_data, hdu_in=None, source_hdul=None): """ Parse input data to return a Numpy array and WCS object. """ @@ -109,9 +109,9 @@ def parse_input_data(input_data, hdu_in=None): ) else: hdu_in = 0 - return parse_input_data(input_data[hdu_in]) + return parse_input_data(input_data[hdu_in], source_hdul=input_data) elif isinstance(input_data, PrimaryHDU | ImageHDU | CompImageHDU): - return hdu_to_numpy_memmap(input_data), WCS(input_data.header) + return (hdu_to_numpy_memmap(input_data), WCS(input_data.header, fobj=source_hdul)) elif isinstance(input_data, tuple) and isinstance(input_data[0], np.ndarray | da.core.Array): if isinstance(input_data[1], Header): return input_data[0], WCS(input_data[1])