Skip to content

Commit

Permalink
Ensure float64 in radec2pix (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitosaurus authored Dec 30, 2024
1 parent 171b901 commit e07916b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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

0 comments on commit e07916b

Please sign in to comment.