From 45512fc7473908a1a3f3ebe6c5b8159be1c9ab4c Mon Sep 17 00:00:00 2001 From: Sean McGuire Date: Wed, 20 Nov 2024 18:38:55 -0500 Subject: [PATCH 1/5] Replace healpy in healpix_shim pixel math operations --- src/hats/pixel_math/healpix_shim.py | 74 ++++++++--- tests/hats/pixel_math/test_healpix_shim.py | 142 +++++++++++++++++++++ 2 files changed, 201 insertions(+), 15 deletions(-) diff --git a/src/hats/pixel_math/healpix_shim.py b/src/hats/pixel_math/healpix_shim.py index 1afccda2..1c8a06f9 100644 --- a/src/hats/pixel_math/healpix_shim.py +++ b/src/hats/pixel_math/healpix_shim.py @@ -1,41 +1,85 @@ from __future__ import annotations +import math + import astropy.units as u +import cdshealpix import healpy as hp import numpy as np -from astropy.coordinates import SkyCoord +from astropy.coordinates import SkyCoord, Longitude, Latitude # pylint: disable=missing-function-docstring ## Arithmetic conversions -def npix2order(param): - return hp.nside2order(hp.npix2nside(param)) +MAX_HEALPIX_ORDER = 29 + + +def is_order_valid(order: int) -> bool: + return 0 <= order <= MAX_HEALPIX_ORDER + + +def npix2order(npix: int) -> int: + if npix <= 0: + raise ValueError("Invalid value for npix") + order = int(math.log2(npix / 12)) >> 1 + if not is_order_valid(order) or not 12 * (1 << (2 * order)) == npix: + raise ValueError("Invalid value for npix") + return order + + +def order2nside(order: int) -> int: + if not is_order_valid(order): + raise ValueError("Invalid value for order") + return 1 << order + + +def order2npix(order: int) -> int: + if not is_order_valid(order): + raise ValueError("Invalid value for order") + return 12 * (1 << (2 * order)) + +def nside2resol(nside: int, arcmin: bool = False) -> float: + resol_rad = np.sqrt(nside2pixarea(nside)) -def order2nside(param): - return hp.order2nside(param) + if arcmin: + return np.rad2deg(resol_rad) * 60 + return resol_rad -def order2npix(param): - return hp.order2npix(param) +def nside2pixarea(nside: int, degrees: bool = False) -> float: + npix = 12 * nside * nside + pix_area_rad = 4 * np.pi / npix + if degrees: + return pix_area_rad * (180 / np.pi) * (180 / np.pi) + return pix_area_rad -def nside2resol(*args, **kwargs): - return hp.nside2resol(*args, **kwargs) +def ang2pix(nside: int, theta: float, phi: float, nest: bool = False, lonlat: bool = False) -> int: + if not nest: + raise NotImplementedError("RING order ang2pix not supported") + order = nside2order(nside) + if lonlat: + ra = Longitude(theta, unit="deg") + dec = Latitude(phi, unit="deg") + else: + ra = Longitude(phi, unit="rad") + dec = Latitude(np.pi / 2 - theta, unit="rad") -def nside2pixarea(*args, **kwargs): - return hp.nside2pixarea(*args, **kwargs) + return cdshealpix.lonlat_to_healpix(ra, dec, order) -def ang2pix(*args, **kwargs): - return hp.ang2pix(*args, **kwargs) +def nside2order(nside: int) -> int: + npix = 12 * nside * nside + return npix2order(npix) -def ring2nest(*args, **kwargs): - return hp.ring2nest(*args, **kwargs) +def ring2nest(nside: int, ipix: int) -> int: + order = nside2order(nside) + return cdshealpix.from_ring(ipix, order) ## Query diff --git a/tests/hats/pixel_math/test_healpix_shim.py b/tests/hats/pixel_math/test_healpix_shim.py index 00ddc1bd..bc12ca9e 100644 --- a/tests/hats/pixel_math/test_healpix_shim.py +++ b/tests/hats/pixel_math/test_healpix_shim.py @@ -1,4 +1,7 @@ +import cdshealpix import numpy as np +import pytest +from astropy.coordinates import Longitude, Latitude from numpy.testing import assert_allclose, assert_array_equal from hats.pixel_math import healpix_shim as hps @@ -50,3 +53,142 @@ def test_ang2vec(): z = np.sin(dec_rad) actual = np.asarray([x, y, z]).T assert_array_equal(actual, hps.ang2vec(ra, dec)) + + +def test_npix2order(): + orders = [0, 1, 5, 10, 20, 29] + npix = [12 * (4**order) for order in orders] + test_orders = [hps.npix2order(x) for x in npix] + assert test_orders == orders + + +def test_npix2order_invalid(): + npixs = [-10, 0, 11, 13, 47, 49, 100000, 100000000000000000] + for npix in npixs: + with pytest.raises(ValueError, match="Invalid"): + hps.npix2order(npix) + + +def test_order2nside(): + orders = [0, 1, 5, 10, 20, 29] + expected_nsides = [2**x for x in orders] + test_nsides = [hps.order2nside(o) for o in orders] + assert test_nsides == expected_nsides + + +def test_order2nside_invalid(): + orders = [-1000, -1, 30, 4000] + for order in orders: + with pytest.raises(ValueError, match="Invalid"): + hps.order2nside(order) + + +def test_order2npix(): + orders = [0, 1, 5, 10, 20, 29] + npix = [12 * (4**order) for order in orders] + test_npix = [hps.order2npix(o) for o in orders] + assert test_npix == npix + + +def test_order2npix_invalid(): + orders = [-1000, -1, 30, 4000] + for order in orders: + with pytest.raises(ValueError, match="Invalid"): + hps.order2npix(order) + + +def test_nside2pixarea(): + orders = [0, 1, 5, 10, 20, 29] + nsides = [2**x for x in orders] + npix = [12 * (4**order) for order in orders] + pix_area_expected = [4 * np.pi / x for x in npix] + pix_area_test = [hps.nside2pixarea(nside) for nside in nsides] + assert pix_area_test == pix_area_expected + + +def test_nside2pixarea_degrees(): + orders = [0, 1, 5, 10, 20, 29] + nsides = [2**x for x in orders] + npix = [12 * (4**order) for order in orders] + pix_area_expected = [np.rad2deg(np.rad2deg(4 * np.pi / x)) for x in npix] + pix_area_test = [hps.nside2pixarea(nside, degrees=True) for nside in nsides] + assert pix_area_test == pix_area_expected + + +def test_nside2resol(): + orders = [0, 1, 5, 10, 20, 29] + nsides = [2**x for x in orders] + resol_expected = [np.sqrt(hps.nside2pixarea(nside)) for nside in nsides] + resol_test = [hps.nside2resol(nside) for nside in nsides] + assert resol_test == resol_expected + + +def test_nside2resol_arcmin(): + orders = [0, 1, 5, 10, 20, 29] + nsides = [2**x for x in orders] + resol_expected = [np.rad2deg(np.sqrt(hps.nside2pixarea(nside))) * 60 for nside in nsides] + resol_test = [hps.nside2resol(nside, arcmin=True) for nside in nsides] + assert resol_test == resol_expected + + +def test_ang2pix(): + orders = [0, 1, 5, 10, 20, 29] + ras = np.arange(-180.0, 180.0, 10.0) + decs = np.arange(-90.0, 90.0, 180 // len(ras)) + colats = 90 - decs + for order in orders: + expected_pixels = cdshealpix.lonlat_to_healpix( + Longitude(ras, unit="deg"), Latitude(decs, unit="deg"), order + ) + pixels = hps.ang2pix(hps.order2nside(order), np.deg2rad(colats), np.deg2rad(ras), nest=True) + assert np.all(pixels == expected_pixels) + + +def test_ang2pix_lonlat(): + orders = [0, 1, 5, 10, 20, 29] + ras = np.arange(-180.0, 180.0, 10.0) + decs = np.arange(-90.0, 90.0, 180 // len(ras)) + for order in orders: + expected_pixels = cdshealpix.lonlat_to_healpix( + Longitude(ras, unit="deg"), Latitude(decs, unit="deg"), order + ) + pixels = hps.ang2pix(hps.order2nside(order), ras, decs, nest=True, lonlat=True) + assert np.all(pixels == expected_pixels) + + +def test_ang2pix_ring(): + order = 4 + ras = np.arange(-180.0, 180.0, 10.0) + decs = np.arange(-90.0, 90.0, 180 // len(ras)) + colats = 90 - decs + with pytest.raises(NotImplementedError, match="RING"): + hps.ang2pix(hps.order2nside(order), ras, decs, lonlat=True) + with pytest.raises(NotImplementedError, match="RING"): + hps.ang2pix(hps.order2nside(order), colats, ras) + + +def test_ang2pix_invalid(): + orders = [0, 1, 5, 10, 20, 29] + invalid_orders = [-1000, -1, 30, 40] + ras = np.arange(-4000.0, 1000.0, 100.0) + decs = np.arange(-1000.0, 1000.0, 2000.0 // len(ras)) + colats = 90 - decs + for order in invalid_orders: + with pytest.raises(ValueError, match="Invalid"): + hps.ang2pix(int(2**order), np.deg2rad(colats), np.deg2rad(ras), nest=True) + with pytest.raises(ValueError, match="Invalid"): + hps.ang2pix(int(2**order), ras, decs, nest=True, lonlat=True) + for order in orders: + with pytest.raises(ValueError, match="angle"): + hps.ang2pix(hps.order2nside(order), np.deg2rad(colats), np.deg2rad(ras), nest=True) + with pytest.raises(ValueError, match="angle"): + hps.ang2pix(hps.order2nside(order), ras, decs, nest=True, lonlat=True) + + +def test_ring2nest(): + orders = [0, 1, 5, 10, 20, 29] + for order in orders: + ipix = np.arange(0, 12 * (4**order), 12 * (4**order) // 10) + expected_ring_ipix = cdshealpix.from_ring(ipix, order) + test_ring_ipix = hps.ring2nest(2**order, ipix) + assert np.all(test_ring_ipix == expected_ring_ipix) From 312f55772a40c332fb5fdd508a77b7277057c386 Mon Sep 17 00:00:00 2001 From: Sean McGuire Date: Wed, 20 Nov 2024 18:40:26 -0500 Subject: [PATCH 2/5] isort --- src/hats/pixel_math/healpix_shim.py | 2 +- tests/hats/pixel_math/test_healpix_shim.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hats/pixel_math/healpix_shim.py b/src/hats/pixel_math/healpix_shim.py index 1c8a06f9..f46c57bc 100644 --- a/src/hats/pixel_math/healpix_shim.py +++ b/src/hats/pixel_math/healpix_shim.py @@ -6,7 +6,7 @@ import cdshealpix import healpy as hp import numpy as np -from astropy.coordinates import SkyCoord, Longitude, Latitude +from astropy.coordinates import Latitude, Longitude, SkyCoord # pylint: disable=missing-function-docstring diff --git a/tests/hats/pixel_math/test_healpix_shim.py b/tests/hats/pixel_math/test_healpix_shim.py index bc12ca9e..dd13654a 100644 --- a/tests/hats/pixel_math/test_healpix_shim.py +++ b/tests/hats/pixel_math/test_healpix_shim.py @@ -1,7 +1,7 @@ import cdshealpix import numpy as np import pytest -from astropy.coordinates import Longitude, Latitude +from astropy.coordinates import Latitude, Longitude from numpy.testing import assert_allclose, assert_array_equal from hats.pixel_math import healpix_shim as hps From 420a0443f1d1fb39158baaafe378a25a366d1421 Mon Sep 17 00:00:00 2001 From: Sean McGuire Date: Wed, 20 Nov 2024 18:48:41 -0500 Subject: [PATCH 3/5] support np arrays --- src/hats/pixel_math/healpix_shim.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hats/pixel_math/healpix_shim.py b/src/hats/pixel_math/healpix_shim.py index f46c57bc..965f83d1 100644 --- a/src/hats/pixel_math/healpix_shim.py +++ b/src/hats/pixel_math/healpix_shim.py @@ -17,7 +17,7 @@ def is_order_valid(order: int) -> bool: - return 0 <= order <= MAX_HEALPIX_ORDER + return np.all(0 <= order) and np.all(order <= MAX_HEALPIX_ORDER) def npix2order(npix: int) -> int: From c7738f06c67d6a03f5ff4031f135654296c9fd5c Mon Sep 17 00:00:00 2001 From: Sean McGuire Date: Fri, 22 Nov 2024 11:27:13 -0500 Subject: [PATCH 4/5] use order instead of nside --- src/hats/catalog/partition_info.py | 2 +- src/hats/pixel_math/box_filter.py | 2 +- src/hats/pixel_math/healpix_shim.py | 35 ++++------- src/hats/pixel_math/partition_stats.py | 6 +- src/hats/pixel_math/spatial_index.py | 2 +- tests/hats/pixel_math/test_healpix_shim.py | 67 ++++++--------------- tests/hats/pixel_math/test_spatial_index.py | 18 ++---- 7 files changed, 40 insertions(+), 92 deletions(-) diff --git a/src/hats/catalog/partition_info.py b/src/hats/catalog/partition_info.py index d073702d..5188cca0 100644 --- a/src/hats/catalog/partition_info.py +++ b/src/hats/catalog/partition_info.py @@ -274,7 +274,7 @@ def calculate_fractional_coverage(self): """Calculate what fraction of the sky is covered by partition tiles.""" pixel_orders = [p.order for p in self.pixel_list] cov_order, cov_count = np.unique(pixel_orders, return_counts=True) - area_by_order = [hp.nside2pixarea(hp.order2nside(order), degrees=True) for order in cov_order] + area_by_order = [hp.order2pixarea(order, degrees=True) for order in cov_order] # 41253 is the number of square degrees in a sphere # https://en.wikipedia.org/wiki/Square_degree return (area_by_order * cov_count).sum() / (360**2 / np.pi) diff --git a/src/hats/pixel_math/box_filter.py b/src/hats/pixel_math/box_filter.py index d6155709..58c4b868 100644 --- a/src/hats/pixel_math/box_filter.py +++ b/src/hats/pixel_math/box_filter.py @@ -87,7 +87,7 @@ def _generate_dec_strip_moc(dec_range: Tuple[float, float], order: int) -> MOC: colat_rad = np.sort(np.radians([90 - dec if dec > 0 else 90 + abs(dec) for dec in dec_range])) # Figure out which pixels in nested order are contained in the declination band pixels_in_range = hp.ring2nest( - nside, hp.query_strip(nside, theta1=colat_rad[0], theta2=colat_rad[1], inclusive=True) + order, hp.query_strip(nside, theta1=colat_rad[0], theta2=colat_rad[1], inclusive=True) ) orders = np.full(pixels_in_range.shape, fill_value=order) return MOC.from_healpix_cells(ipix=pixels_in_range, depth=orders, max_depth=order) diff --git a/src/hats/pixel_math/healpix_shim.py b/src/hats/pixel_math/healpix_shim.py index 965f83d1..96eb18b7 100644 --- a/src/hats/pixel_math/healpix_shim.py +++ b/src/hats/pixel_math/healpix_shim.py @@ -41,8 +41,8 @@ def order2npix(order: int) -> int: return 12 * (1 << (2 * order)) -def nside2resol(nside: int, arcmin: bool = False) -> float: - resol_rad = np.sqrt(nside2pixarea(nside)) +def order2resol(order: int, arcmin: bool = False) -> float: + resol_rad = np.sqrt(order2pixarea(order)) if arcmin: return np.rad2deg(resol_rad) * 60 @@ -50,35 +50,25 @@ def nside2resol(nside: int, arcmin: bool = False) -> float: return resol_rad -def nside2pixarea(nside: int, degrees: bool = False) -> float: - npix = 12 * nside * nside +def order2pixarea(order: int, degrees: bool = False) -> float: + npix = order2npix(order) pix_area_rad = 4 * np.pi / npix if degrees: return pix_area_rad * (180 / np.pi) * (180 / np.pi) return pix_area_rad -def ang2pix(nside: int, theta: float, phi: float, nest: bool = False, lonlat: bool = False) -> int: - if not nest: - raise NotImplementedError("RING order ang2pix not supported") - order = nside2order(nside) - if lonlat: - ra = Longitude(theta, unit="deg") - dec = Latitude(phi, unit="deg") - else: - ra = Longitude(phi, unit="rad") - dec = Latitude(np.pi / 2 - theta, unit="rad") - - return cdshealpix.lonlat_to_healpix(ra, dec, order) +def radec2pix(order: int, ra: float, dec: float) -> int: + if not is_order_valid(order): + raise ValueError("Invalid value for order") + ra = Longitude(ra, unit="deg") + dec = Latitude(dec, unit="deg") -def nside2order(nside: int) -> int: - npix = 12 * nside * nside - return npix2order(npix) + return cdshealpix.lonlat_to_healpix(ra, dec, order) -def ring2nest(nside: int, ipix: int) -> int: - order = nside2order(nside) +def ring2nest(order: int, ipix: int) -> int: return cdshealpix.from_ring(ipix, order) @@ -220,6 +210,5 @@ def order2mindist(order: np.ndarray | int) -> np.ndarray | float: np.ndarray of float or a single scalar float The minimum distance between pixels in arcminutes """ - pixel_nside = order2nside(order) - pixel_avgsize = nside2resol(pixel_nside, arcmin=True) + pixel_avgsize = order2resol(order, arcmin=True) return avgsize2mindist(pixel_avgsize) diff --git a/src/hats/pixel_math/partition_stats.py b/src/hats/pixel_math/partition_stats.py index 34f8c8f1..bc31345b 100644 --- a/src/hats/pixel_math/partition_stats.py +++ b/src/hats/pixel_math/partition_stats.py @@ -43,12 +43,10 @@ def generate_histogram( required_columns = [ra_column, dec_column] if not all(x in data.columns for x in required_columns): raise ValueError(f"Invalid column names in input: {ra_column}, {dec_column}") - mapped_pixels = hp.ang2pix( - 2**highest_order, + mapped_pixels = hp.radec2pix( + highest_order, data[ra_column].values, data[dec_column].values, - lonlat=True, - nest=True, ) mapped_pixel, count_at_pixel = np.unique(mapped_pixels, return_counts=True) histogram_result[mapped_pixel] += count_at_pixel.astype(np.int64) diff --git a/src/hats/pixel_math/spatial_index.py b/src/hats/pixel_math/spatial_index.py index 43c04b42..bc7ac6da 100644 --- a/src/hats/pixel_math/spatial_index.py +++ b/src/hats/pixel_math/spatial_index.py @@ -24,7 +24,7 @@ def compute_spatial_index(ra_values: List[float], dec_values: List[float]) -> np if len(ra_values) != len(dec_values): raise ValueError("ra and dec arrays should have the same length") - mapped_pixels = hp.ang2pix(2**SPATIAL_INDEX_ORDER, ra_values, dec_values, nest=True, lonlat=True) + mapped_pixels = hp.radec2pix(SPATIAL_INDEX_ORDER, ra_values, dec_values) return mapped_pixels diff --git a/tests/hats/pixel_math/test_healpix_shim.py b/tests/hats/pixel_math/test_healpix_shim.py index dd13654a..9d80e714 100644 --- a/tests/hats/pixel_math/test_healpix_shim.py +++ b/tests/hats/pixel_math/test_healpix_shim.py @@ -22,8 +22,7 @@ def test_mindist2avgsize2mindist(): def test_order2avgsize2order(): """Test that avgsize2order is inverse of hps.nside2resol(hps.order2nside, arcmin=True)""" order = np.arange(20) - nside = hps.order2nside(order) - assert_array_equal(hps.avgsize2order(hps.nside2resol(nside, arcmin=True)), order) + assert_array_equal(hps.avgsize2order(hps.order2resol(order, arcmin=True)), order) def test_margin2order(): @@ -97,92 +96,60 @@ def test_order2npix_invalid(): hps.order2npix(order) -def test_nside2pixarea(): +def test_order2pixarea(): orders = [0, 1, 5, 10, 20, 29] - nsides = [2**x for x in orders] npix = [12 * (4**order) for order in orders] pix_area_expected = [4 * np.pi / x for x in npix] - pix_area_test = [hps.nside2pixarea(nside) for nside in nsides] + pix_area_test = [hps.order2pixarea(order) for order in orders] assert pix_area_test == pix_area_expected -def test_nside2pixarea_degrees(): +def test_order2pixarea_degrees(): orders = [0, 1, 5, 10, 20, 29] - nsides = [2**x for x in orders] npix = [12 * (4**order) for order in orders] pix_area_expected = [np.rad2deg(np.rad2deg(4 * np.pi / x)) for x in npix] - pix_area_test = [hps.nside2pixarea(nside, degrees=True) for nside in nsides] + pix_area_test = [hps.order2pixarea(order, degrees=True) for order in orders] assert pix_area_test == pix_area_expected -def test_nside2resol(): +def test_order2resol(): orders = [0, 1, 5, 10, 20, 29] - nsides = [2**x for x in orders] - resol_expected = [np.sqrt(hps.nside2pixarea(nside)) for nside in nsides] - resol_test = [hps.nside2resol(nside) for nside in nsides] + resol_expected = [np.sqrt(hps.order2pixarea(order)) for order in orders] + resol_test = [hps.order2resol(order) for order in orders] assert resol_test == resol_expected -def test_nside2resol_arcmin(): +def test_order2resol_arcmin(): orders = [0, 1, 5, 10, 20, 29] nsides = [2**x for x in orders] - resol_expected = [np.rad2deg(np.sqrt(hps.nside2pixarea(nside))) * 60 for nside in nsides] - resol_test = [hps.nside2resol(nside, arcmin=True) for nside in nsides] + resol_expected = [np.rad2deg(np.sqrt(hps.order2pixarea(order))) * 60 for order in orders] + resol_test = [hps.order2resol(order, arcmin=True) for order in orders] assert resol_test == resol_expected -def test_ang2pix(): +def test_radec2pix_lonlat(): orders = [0, 1, 5, 10, 20, 29] ras = np.arange(-180.0, 180.0, 10.0) decs = np.arange(-90.0, 90.0, 180 // len(ras)) - colats = 90 - decs for order in orders: expected_pixels = cdshealpix.lonlat_to_healpix( Longitude(ras, unit="deg"), Latitude(decs, unit="deg"), order ) - pixels = hps.ang2pix(hps.order2nside(order), np.deg2rad(colats), np.deg2rad(ras), nest=True) + pixels = hps.radec2pix(order, ras, decs) assert np.all(pixels == expected_pixels) -def test_ang2pix_lonlat(): - orders = [0, 1, 5, 10, 20, 29] - ras = np.arange(-180.0, 180.0, 10.0) - decs = np.arange(-90.0, 90.0, 180 // len(ras)) - for order in orders: - expected_pixels = cdshealpix.lonlat_to_healpix( - Longitude(ras, unit="deg"), Latitude(decs, unit="deg"), order - ) - pixels = hps.ang2pix(hps.order2nside(order), ras, decs, nest=True, lonlat=True) - assert np.all(pixels == expected_pixels) - - -def test_ang2pix_ring(): - order = 4 - ras = np.arange(-180.0, 180.0, 10.0) - decs = np.arange(-90.0, 90.0, 180 // len(ras)) - colats = 90 - decs - with pytest.raises(NotImplementedError, match="RING"): - hps.ang2pix(hps.order2nside(order), ras, decs, lonlat=True) - with pytest.raises(NotImplementedError, match="RING"): - hps.ang2pix(hps.order2nside(order), colats, ras) - - -def test_ang2pix_invalid(): +def test_radec2pix_invalid(): orders = [0, 1, 5, 10, 20, 29] invalid_orders = [-1000, -1, 30, 40] ras = np.arange(-4000.0, 1000.0, 100.0) decs = np.arange(-1000.0, 1000.0, 2000.0 // len(ras)) - colats = 90 - decs for order in invalid_orders: with pytest.raises(ValueError, match="Invalid"): - hps.ang2pix(int(2**order), np.deg2rad(colats), np.deg2rad(ras), nest=True) - with pytest.raises(ValueError, match="Invalid"): - hps.ang2pix(int(2**order), ras, decs, nest=True, lonlat=True) + hps.radec2pix(order, ras, decs) for order in orders: with pytest.raises(ValueError, match="angle"): - hps.ang2pix(hps.order2nside(order), np.deg2rad(colats), np.deg2rad(ras), nest=True) - with pytest.raises(ValueError, match="angle"): - hps.ang2pix(hps.order2nside(order), ras, decs, nest=True, lonlat=True) + hps.radec2pix(order, ras, decs) def test_ring2nest(): @@ -190,5 +157,5 @@ def test_ring2nest(): for order in orders: ipix = np.arange(0, 12 * (4**order), 12 * (4**order) // 10) expected_ring_ipix = cdshealpix.from_ring(ipix, order) - test_ring_ipix = hps.ring2nest(2**order, ipix) + test_ring_ipix = hps.ring2nest(order, ipix) assert np.all(test_ring_ipix == expected_ring_ipix) diff --git a/tests/hats/pixel_math/test_spatial_index.py b/tests/hats/pixel_math/test_spatial_index.py index ca9b04eb..98377a07 100644 --- a/tests/hats/pixel_math/test_spatial_index.py +++ b/tests/hats/pixel_math/test_spatial_index.py @@ -16,12 +16,10 @@ def test_single(): """Single point. Adheres to specification.""" result = compute_spatial_index([5], [5]) - expected = hp.ang2pix( - 2**SPATIAL_INDEX_ORDER, + expected = hp.radec2pix( + SPATIAL_INDEX_ORDER, [5], [5], - nest=True, - lonlat=True, ) npt.assert_array_equal(result, expected) @@ -38,12 +36,10 @@ def test_short_list(): ra = [5, 1, 5] dec = [5, 1, 5] result = compute_spatial_index(ra, dec) - expected = hp.ang2pix( - 2**SPATIAL_INDEX_ORDER, + expected = hp.radec2pix( + SPATIAL_INDEX_ORDER, ra, dec, - nest=True, - lonlat=True, ) npt.assert_array_equal(result, expected) @@ -53,12 +49,10 @@ def test_list(): ra = [5, 5, 5, 1, 5, 5, 5, 1, 5] dec = [5, 5, 5, 1, 5, 5, 5, 1, 5] result = compute_spatial_index(ra, dec) - expected = hp.ang2pix( - 2**SPATIAL_INDEX_ORDER, + expected = hp.radec2pix( + SPATIAL_INDEX_ORDER, ra, dec, - nest=True, - lonlat=True, ) npt.assert_array_equal(result, expected) From f495c43a0577515dfec794f679ac87f1ac6aeaf0 Mon Sep 17 00:00:00 2001 From: Sean McGuire Date: Fri, 22 Nov 2024 11:36:30 -0500 Subject: [PATCH 5/5] remove unused variable --- tests/hats/pixel_math/test_healpix_shim.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/hats/pixel_math/test_healpix_shim.py b/tests/hats/pixel_math/test_healpix_shim.py index 9d80e714..7cc97f80 100644 --- a/tests/hats/pixel_math/test_healpix_shim.py +++ b/tests/hats/pixel_math/test_healpix_shim.py @@ -121,7 +121,6 @@ def test_order2resol(): def test_order2resol_arcmin(): orders = [0, 1, 5, 10, 20, 29] - nsides = [2**x for x in orders] resol_expected = [np.rad2deg(np.sqrt(hps.order2pixarea(order))) * 60 for order in orders] resol_test = [hps.order2resol(order, arcmin=True) for order in orders] assert resol_test == resol_expected