Skip to content

Commit

Permalink
add more helpful error with non overlapping catalogs (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
smcguire-cmu authored Jan 8, 2025
1 parent 965ef8f commit 95df3bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/lsdb/dask/merge_catalog_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,19 @@ def func(
aligned partitions of the catalogs
"""

# aligns the catalog's partitions to the given pixels for each catalog
aligned_partitions = [align_catalog_to_partitions(cat, pixels) for (cat, pixels) in catalog_mappings]

# gets the pixels and hc_structures to pass to the function
pixels = [pixels for (_, pixels) in catalog_mappings]
for p in pixels:
if len(p) == 0:
raise RuntimeError("Catalogs do not overlap")

catalog_infos = [
cat.hc_structure.catalog_info if cat is not None else None for (cat, _) in catalog_mappings
]

# aligns the catalog's partitions to the given pixels for each catalog
aligned_partitions = [align_catalog_to_partitions(cat, pixels) for (cat, pixels) in catalog_mappings]

# defines an inner function that can be vectorized to apply the given function to each of the partitions
# with the additional arguments including as the hc_structures and any specified additional arguments
def apply_func(*partitions_and_pixels):
Expand Down Expand Up @@ -208,6 +212,8 @@ def get_healpix_pixels_from_alignment(
a tuple of (primary_pixels, join_pixels) with lists of HealpixPixel objects
"""
pixel_mapping = alignment.pixel_mapping
if len(pixel_mapping) == 0:
return ([], [])
make_pixel = np.vectorize(HealpixPixel)
left_pixels = make_pixel(
pixel_mapping[PixelAlignment.PRIMARY_ORDER_COLUMN_NAME],
Expand Down
7 changes: 7 additions & 0 deletions tests/lsdb/catalog/test_crossmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,10 @@ def test_algorithm_has_no_extra_columns_specified(small_sky_xmatch_catalog):
def test_raise_for_unknown_kwargs(small_sky_catalog):
with pytest.raises(TypeError, match="unexpected keyword argument"):
small_sky_catalog.crossmatch(small_sky_catalog, unknown_kwarg="value")


def test_raise_for_non_overlapping_catalogs(small_sky_order1_catalog, small_sky_xmatch_catalog):
small_sky_order1_catalog = small_sky_order1_catalog.pixel_search([HealpixPixel(1, 44)])
small_sky_xmatch_catalog = small_sky_xmatch_catalog.pixel_search([HealpixPixel(1, 45)])
with pytest.raises(RuntimeError, match="overlap"):
small_sky_order1_catalog.crossmatch(small_sky_xmatch_catalog)

0 comments on commit 95df3bd

Please sign in to comment.