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

Ensure use of float64 when calling radec2pix #447

Merged
merged 1 commit into from
Dec 30, 2024
Merged
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
4 changes: 2 additions & 2 deletions src/hats/pixel_math/healpix_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def radec2pix(order: int, ra: float, dec: float) -> np.ndarray[np.int64]:
if not is_order_valid(order):
raise ValueError("Invalid value for order")

ra = Longitude(ra, unit="deg")
dec = Latitude(dec, unit="deg")
ra = Longitude(np.asarray(ra, dtype=np.float64), unit="deg")
dec = Latitude(np.asarray(dec, dtype=np.float64), unit="deg")

return cdshealpix.lonlat_to_healpix(ra, dec, order).astype(np.int64)

Expand Down
16 changes: 16 additions & 0 deletions tests/hats/pixel_math/test_healpix_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@ def test_radec2pix_lonlat():
assert np.all(pixels == expected_pixels)


def test_radec2pix_lonlat_float32():
orders = [0, 1, 5, 10, 20, 29]
ras = np.arange(-180.0, 180.0, 10.0)
ras_f = ras.astype(np.float32)
decs = np.arange(-90.0, 90.0, 180 // len(ras))
decs_f = decs.astype(np.float32)
for order in orders:
expected_pixels = cdshealpix.lonlat_to_healpix(
Longitude(ras, unit="deg"), Latitude(decs, unit="deg"), order
)
# Verify that healpixshim can work with float32 versions
# Fixes https://github.com/astronomy-commons/hats-import/issues/458
pixels = hps.radec2pix(order, ras_f, decs_f)
assert np.all(pixels == expected_pixels)


def test_radec2pix_invalid():
orders = [0, 1, 5, 10, 20, 29]
invalid_orders = [-1000, -1, 30, 40]
Expand Down
Loading