Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smcguire-cmu committed Nov 18, 2024
1 parent 665eb0c commit f503f81
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/lsdb/catalog/test_moc_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pandas as pd
import astropy.units as u
import numpy as np
from hats.pixel_math import HealpixPixel
from mocpy import MOC


def test_moc_search_filters_correct_points(small_sky_order1_catalog):
search_moc = MOC.from_healpix_cells(ipix=np.array([176, 177]), depth=np.array([2, 2]), max_depth=2)
filtered_cat = small_sky_order1_catalog.moc_search(search_moc)
assert filtered_cat.get_healpix_pixels() == [HealpixPixel(1, 44)]
filtered_cat_comp = filtered_cat.compute()
cat_comp = small_sky_order1_catalog.compute()
assert np.all(
search_moc.contains_lonlat(
filtered_cat_comp["ra"].to_numpy() * u.deg, filtered_cat_comp["dec"].to_numpy() * u.deg
)
)
assert np.sum(
search_moc.contains_lonlat(cat_comp["ra"].to_numpy() * u.deg, cat_comp["dec"].to_numpy() * u.deg)
) == len(filtered_cat_comp)


def test_moc_search_non_fine(small_sky_order1_catalog):
search_moc = MOC.from_healpix_cells(ipix=np.array([176, 180]), depth=np.array([2, 2]), max_depth=2)
filtered_cat = small_sky_order1_catalog.moc_search(search_moc, fine=False)
assert filtered_cat.get_healpix_pixels() == [HealpixPixel(1, 44), HealpixPixel(1, 45)]
pd.testing.assert_frame_equal(
filtered_cat.compute(),
small_sky_order1_catalog.pixel_search([HealpixPixel(1, 44), HealpixPixel(1, 45)]).compute(),
)

0 comments on commit f503f81

Please sign in to comment.