diff --git a/src/hipscat/catalog/catalog.py b/src/hipscat/catalog/catalog.py index c165400b..4f783893 100644 --- a/src/hipscat/catalog/catalog.py +++ b/src/hipscat/catalog/catalog.py @@ -12,7 +12,7 @@ from hipscat.catalog.catalog_type import CatalogType from hipscat.catalog.healpix_dataset.healpix_dataset import HealpixDataset, PixelInputTypes from hipscat.pixel_math import HealpixPixel -from hipscat.pixel_math.box_filter import filter_pixels_by_box +from hipscat.pixel_math.box_filter import filter_pixels_by_box, wrap_ra_values from hipscat.pixel_math.cone_filter import filter_pixels_by_cone from hipscat.pixel_math.polygon_filter import ( CartesianCoordinates, @@ -95,6 +95,7 @@ def filter_by_box( Returns: A new catalog with only the pixels that overlap with the specified region """ + ra = wrap_ra_values(ra) validate_box_search(ra, dec) return self.filter_from_pixel_list(filter_pixels_by_box(self.pixel_tree, ra, dec)) diff --git a/src/hipscat/pixel_math/box_filter.py b/src/hipscat/pixel_math/box_filter.py index 4539ca0c..9ba3e24d 100644 --- a/src/hipscat/pixel_math/box_filter.py +++ b/src/hipscat/pixel_math/box_filter.py @@ -10,7 +10,6 @@ from hipscat.pixel_math import HealpixPixel from hipscat.pixel_math.filter import get_filtered_pixel_list from hipscat.pixel_math.polygon_filter import SphericalCoordinates -from hipscat.pixel_math.validators import validate_box_search from hipscat.pixel_tree.pixel_tree import PixelTree from hipscat.pixel_tree.pixel_tree_builder import PixelTreeBuilder @@ -24,15 +23,13 @@ def filter_pixels_by_box( Args: pixel_tree (PixelTree): The catalog tree to filter pixels from - ra (Tuple[float, float]): Right ascension range, in degrees - dec (Tuple[float, float]): Declination range, in degrees + ra (Tuple[float, float]): Right ascension range, in [0,360] degrees + dec (Tuple[float, float]): Declination range, in [-90,90] degrees Returns: List of HealpixPixels representing only the pixels that overlap with the right ascension or the declination region. """ - ra = wrap_ra_values(ra) - validate_box_search(ra, dec) max_order = pixel_tree.get_max_depth() result_pixels = [] diff --git a/tests/hipscat/catalog/test_catalog.py b/tests/hipscat/catalog/test_catalog.py index bef8fdf0..ec9aed9c 100644 --- a/tests/hipscat/catalog/test_catalog.py +++ b/tests/hipscat/catalog/test_catalog.py @@ -262,17 +262,15 @@ def test_box_filter_ra_divisions_edge_cases(small_sky_order1_catalog): def assert_is_subset_of(catalog, catalog_complement): pixels_catalog = catalog.get_healpix_pixels() pixels_catalog_complement = catalog_complement.get_healpix_pixels() - assert all(pixel in pixels_catalog_complement for pixel in pixels_catalog) assert len(pixels_catalog) < len(pixels_catalog_complement) + assert all(pixel in pixels_catalog_complement for pixel in pixels_catalog) filtered_catalog = small_sky_order1_catalog.filter_by_box(ra=(0, 180)) filtered_catalog_complement = small_sky_order1_catalog.filter_by_box(ra=(180, 0)) assert_is_subset_of(filtered_catalog, filtered_catalog_complement) filtered_catalog = small_sky_order1_catalog.filter_by_box(ra=(10, 50)) - assert len(filtered_catalog.get_healpix_pixels()) == 1 filtered_catalog_complement = small_sky_order1_catalog.filter_by_box(ra=(50, 10)) - assert filtered_catalog_complement.get_healpix_pixels() == small_sky_order1_catalog.get_healpix_pixels() assert_is_subset_of(filtered_catalog, filtered_catalog_complement) filtered_catalog = small_sky_order1_catalog.filter_by_box(ra=(10, 220)) @@ -306,8 +304,8 @@ def test_box_filter_ra_pixel_tree_generation(): assert len(pixel_tree_complement) < len(pixel_tree) assert pixel_tree.pixels[1].values() not in pixel_tree_complement.pixels[1].values() - pixel_tree = _generate_ra_strip_pixel_tree(ra_range=(200, 300), order=1) - pixel_tree_complement = _generate_ra_strip_pixel_tree(ra_range=(300, 200), order=1) + pixel_tree = _generate_ra_strip_pixel_tree(ra_range=(200, 350), order=1) + pixel_tree_complement = _generate_ra_strip_pixel_tree(ra_range=(350, 200), order=1) assert len(pixel_tree) < len(pixel_tree_complement) assert pixel_tree.pixels[1].values() not in pixel_tree_complement.pixels[1].values()