Skip to content

Commit

Permalink
Fix crossmatch for empty left partition (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
camposandro authored May 13, 2024
1 parent b532108 commit 422fda5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/lsdb/dask/crossmatch_catalog_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def perform_crossmatch(
algorithm,
suffixes,
right_columns,
meta_df,
**kwargs,
):
"""Performs a crossmatch on data from a HEALPix pixel in each catalog
Expand All @@ -52,6 +53,9 @@ def perform_crossmatch(
if right_pix.order > left_pix.order:
left_df = filter_by_hipscat_index_to_pixel(left_df, right_pix.order, right_pix.pixel)

if len(left_df) == 0:
return meta_df

right_joined_df = concat_partition_and_margin(right_df, right_margin_df, right_columns)

return algorithm(
Expand Down Expand Up @@ -125,22 +129,22 @@ def crossmatch_catalog_data(
# get lists of HEALPix pixels from alignment to pass to cross-match
left_pixels, right_pixels = get_healpix_pixels_from_alignment(alignment)

# perform the crossmatch on each partition pairing using dask delayed for lazy computation
# generate meta table structure for dask df
meta_df = generate_meta_df_for_joined_tables(
[left, right], suffixes, extra_columns=crossmatch_algorithm.extra_columns
)

# perform the crossmatch on each partition pairing using dask delayed for lazy computation
joined_partitions = align_and_apply(
[(left, left_pixels), (right, right_pixels), (right.margin, right_pixels)],
perform_crossmatch,
crossmatch_algorithm,
suffixes,
right.columns,
meta_df,
**kwargs,
)

# generate meta table structure for dask df
meta_df = generate_meta_df_for_joined_tables(
[left, right], suffixes, extra_columns=crossmatch_algorithm.extra_columns
)

return construct_catalog_args(joined_partitions, meta_df, alignment)


Expand Down
16 changes: 16 additions & 0 deletions tests/lsdb/catalog/test_crossmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,22 @@ def test_self_crossmatch(algo, small_sky_catalog, small_sky_dir):
assert len(xmatched) == len(small_sky_catalog.compute())
assert all(xmatched["_dist_arcsec"] == 0)

@staticmethod
def test_crossmatch_empty_left_partition(algo, small_sky_order1_catalog, small_sky_xmatch_catalog):
ra = 300
dec = -60
radius_arcsec = 1 * 3600
cone = small_sky_order1_catalog.cone_search(ra, dec, radius_arcsec)
assert len(cone.get_healpix_pixels()) == 2
assert len(cone.get_partition(1, 44)) == 2
# There is an empty partition in the left catalog
assert len(cone.get_partition(1, 46)) == 0
xmatched = cone.crossmatch(
small_sky_xmatch_catalog, radius_arcsec=0.01 * 3600, algorithm=algo
).compute()
assert len(xmatched) == 2
assert all(xmatched["_dist_arcsec"] <= 0.01 * 3600)


# pylint: disable=too-few-public-methods
class MockCrossmatchAlgorithm(AbstractCrossmatchAlgorithm):
Expand Down

0 comments on commit 422fda5

Please sign in to comment.