Skip to content
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
5 changes: 2 additions & 3 deletions src/hats/catalog/healpix_dataset/healpix_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,10 @@ def filter_by_moc(self, moc: MOC) -> Self:

Returns:
A new catalog with only the pixels that overlap with the moc. Note that we reset the total_rows
to None, as updating would require a scan over the new pixel sizes."""
to 0, as updating would require a scan over the new pixel sizes."""
filtered_tree = filter_by_moc(self.pixel_tree, moc)
filtered_moc = self.moc.intersection(moc) if self.moc is not None else None
filtered_catalog_info = self.catalog_info.model_copy()
filtered_catalog_info.total_rows = None
filtered_catalog_info = self.catalog_info.copy_and_update(total_rows=0)
return self.__class__(filtered_catalog_info, filtered_tree, moc=filtered_moc, schema=self.schema)

def align(
Expand Down
16 changes: 8 additions & 8 deletions tests/hats/catalog/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_cone_filter(small_sky_order1_catalog):
assert filtered_pixels == [HealpixPixel(1, 44)]

assert (1, 44) in filtered_catalog.pixel_tree
assert filtered_catalog.catalog_info.total_rows is None
assert filtered_catalog.catalog_info.total_rows == 0

assert filtered_catalog.moc is not None
cone_moc = MOC.from_cone(
Expand Down Expand Up @@ -200,7 +200,7 @@ def test_polygonal_filter(small_sky_order1_catalog):
assert len(filtered_pixels) == 1
assert filtered_pixels == [HealpixPixel(1, 46)]
assert (1, 46) in filtered_catalog.pixel_tree
assert filtered_catalog.catalog_info.total_rows is None
assert filtered_catalog.catalog_info.total_rows == 0
assert filtered_catalog.moc is not None
ra, dec = np.array(polygon_vertices).T
polygon_moc = MOC.from_polygon(
Expand Down Expand Up @@ -291,7 +291,7 @@ def test_box_filter_ra(small_sky_order1_catalog):
assert (1, 44) in filtered_catalog.pixel_tree
assert (1, 46) in filtered_catalog.pixel_tree
assert len(filtered_catalog.pixel_tree.pixels[1]) == 2
assert filtered_catalog.catalog_info.total_rows is None
assert filtered_catalog.catalog_info.total_rows == 0

assert filtered_catalog.moc is not None
box_moc = generate_box_moc(ra=ra, dec=None, order=small_sky_order1_catalog.get_max_coverage_order())
Expand All @@ -310,7 +310,7 @@ def test_box_filter_wrapped_ra(small_sky_order1_catalog):
assert (1, 44) in filtered_catalog.pixel_tree
assert (1, 45) in filtered_catalog.pixel_tree
assert len(filtered_catalog.pixel_tree.pixels[1]) == 2
assert filtered_catalog.catalog_info.total_rows is None
assert filtered_catalog.catalog_info.total_rows == 0


def test_box_filter_ra_divisions_edge_cases(small_sky_order1_catalog):
Expand Down Expand Up @@ -377,14 +377,14 @@ def test_box_filter_dec(small_sky_order1_catalog):
filtered_catalog = small_sky_order1_catalog.filter_by_box(dec=(10, 20))
assert len(filtered_catalog.get_healpix_pixels()) == 0
assert len(filtered_catalog.pixel_tree) == 0
assert filtered_catalog.catalog_info.total_rows is None
assert filtered_catalog.catalog_info.total_rows == 0

filtered_catalog_1 = small_sky_order1_catalog.filter_by_box(dec=(-10, 10))
filtered_pixels_1 = filtered_catalog_1.get_healpix_pixels()
assert filtered_pixels_1 == [HealpixPixel(1, 47)]
assert (1, 47) in filtered_catalog_1.pixel_tree
assert len(filtered_catalog_1.pixel_tree) == 1
assert filtered_catalog_1.catalog_info.total_rows is None
assert filtered_catalog_1.catalog_info.total_rows == 0

filtered_catalog_2 = small_sky_order1_catalog.filter_by_box(dec=(-30, -20))
filtered_pixels_2 = filtered_catalog_2.get_healpix_pixels()
Expand All @@ -393,7 +393,7 @@ def test_box_filter_dec(small_sky_order1_catalog):
assert (1, 46) in filtered_catalog_2.pixel_tree
assert (1, 47) in filtered_catalog_2.pixel_tree
assert len(filtered_catalog_2.pixel_tree) == 3
assert filtered_catalog_2.catalog_info.total_rows is None
assert filtered_catalog_2.catalog_info.total_rows == 0


def test_box_filter_ra_and_dec(small_sky_order1_catalog):
Expand All @@ -407,7 +407,7 @@ def test_box_filter_ra_and_dec(small_sky_order1_catalog):
assert (1, 46) in filtered_catalog.pixel_tree
assert (1, 47) in filtered_catalog.pixel_tree
assert len(filtered_catalog.pixel_tree.pixels[1]) == 2
assert filtered_catalog.catalog_info.total_rows is None
assert filtered_catalog.catalog_info.total_rows == 0

# Check that the previous filter is the same as intersecting the ra and dec filters
filtered_catalog_ra = small_sky_order1_catalog.filter_by_box(ra=(280, 300))
Expand Down