Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support FITS files with distortion maps when given as file name #477

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
7 changes: 7 additions & 0 deletions reproject/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
6 changes: 3 additions & 3 deletions reproject/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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])
Expand Down
Loading