Skip to content

Commit

Permalink
Add small to range validation
Browse files Browse the repository at this point in the history
  • Loading branch information
camposandro committed Feb 3, 2024
1 parent 90b53d6 commit e1a9d45
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/hipscat/catalog/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))

Expand Down
7 changes: 2 additions & 5 deletions src/hipscat/pixel_math/box_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 = []
Expand Down
8 changes: 3 additions & 5 deletions tests/hipscat/catalog/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit e1a9d45

Please sign in to comment.