Skip to content
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
18 changes: 9 additions & 9 deletions reproject/healpix/_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

import numpy as np
from astropy.coordinates import (
ICRS,
Expand Down Expand Up @@ -40,14 +42,12 @@ def parse_input_healpix_data(input_data, field=0, hdu_in=None, nested=None):
array_in = data[data.columns[field].name].ravel()
if "ORDERING" in header:
nested = header["ORDERING"].lower() == "nested"
elif isinstance(input_data, str):
# NOTE: hdu is not closed here.
hdu = fits.open(input_data)[hdu_in or 1]
return parse_input_healpix_data(hdu, field=field)
elif isinstance(input_data, tuple) and isinstance(input_data[0], np.ndarray):
return array_in, coordinate_system_in, nested
if isinstance(input_data, str | Path):
with fits.open(input_data) as hdulist:
return parse_input_healpix_data(hdulist[hdu_in or 1], field=field)
if isinstance(input_data, tuple) and isinstance(input_data[0], np.ndarray):
array_in = input_data[0]
coordinate_system_in = parse_coord_system(input_data[1])
else:
raise TypeError("input_data should either be an HDU object or a tuple of (array, frame)")

return array_in, coordinate_system_in, nested
return array_in, coordinate_system_in, nested
raise TypeError("input_data should either be an HDU object or a tuple of (array, frame)")
6 changes: 6 additions & 0 deletions reproject/healpix/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

import numpy as np
import pytest
from astropy.coordinates import FK5, Galactic
Expand Down Expand Up @@ -44,6 +46,10 @@ def test_parse_input_healpix_data(tmpdir):
array, coordinate_system, nested = parse_input_healpix_data(filename)
np.testing.assert_allclose(array, data)

# As Path
array, coordinate_system, nested = parse_input_healpix_data(Path(filename))
np.testing.assert_allclose(array, data)

# As array
array, coordinate_system, nested = parse_input_healpix_data((data, "galactic"))
np.testing.assert_allclose(array, data)
Expand Down
Loading