astronomy-commons/hats-tap
Translate nearest-neighbor searches from AQDL
Open
#15 opened on Dec 1, 2025
enhancementgood first issue
Repository metrics
- Stars
- (1 star)
- PR merge metrics
- (PR metrics pending)
Description
Feature request
A query like this:
SELECT
o1.diaObjectId AS id1,
o2.diaObjectId AS id2,
DISTANCE(POINT('ICRS', o1.ra, o1.dec), POINT('ICRS', o2.ra, o2.dec)) AS d
FROM
ppdb.DiaObject AS o1
JOIN
ppdb.DiaObject AS o2 ON o1.diaObjectId <> o2.diaObjectId AND o1.validityStart = o2.validityStart
WHERE
CONTAINS(POINT('ICRS', o1.ra, o1.dec), CIRCLE('ICRS', 186.84, 7.01, 0.05)) = 1
AND
DISTANCE(POINT('ICRS', o1.ra, o1.dec), POINT('ICRS', o2.ra, o2.dec)) < 0.02;
should be translated to:
from lsdb.core.crossmatch.bounded_kdtree_match import BoundedKdTreeCrossmatch
cone = ppdb.cone_search(ra=186.84, dec=7.01, radius_arcsec=0.05*3600)
xmatch = cone.crossmatch(ppdb, algorithm=BoundedKdTreeCrossmatch, min_radius_arcsec=1e-5, radius_arcsec=0.02*3600, suffixes=("_1", "_2"))
xmatch = xmatch[xmatch["validityStart_1"] == xmatch["validityStart_2"]]
compute(xmatch[["diaObjectId_1","diaObjectId_2","_dist_arcsec"]])
This is a difficult one, but it's possible, if the translator knows:
- Why
o1ando2should be joined on ID in order to be equivalent toppdb. - That the
DISTANCEconstraint should be converted intoradius_arcsec=(this should be done for existing crossmatch translation anyway, and should be its own issue). - To do the validity-start match after the crossmatch. The way the ADQL is written, it would be reasonable to do that search first, but of course it's more efficient to do that post-crossmatch.
Before submitting Please check the following:
- I have described the purpose of the suggested change, specifying what I need the enhancement to accomplish, i.e. what problem it solves.
- I have included any relevant links, screenshots, environment information, and data relevant to implementing the requested feature, as well as pseudocode for how I want to access the new functionality.
- If I have ideas for how the new feature could be implemented, I have provided explanations and/or pseudocode and/or task lists for the steps.