Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-45752: Support region overlap against points #1054

Merged
merged 4 commits into from
Aug 14, 2024
Merged

Conversation

dhirving
Copy link
Contributor

@dhirving dhirving commented Aug 13, 2024

Region overlap queries can now use points as regions. Points can be specified
as region OVERLAPS POINT(ra, dec), or by binding an lsst.sphgeom.LonLat or
astropy.coordinates.SkyCoord value. (At the moment, this feature is only
available when using client/server Butler.)

Checklist

  • ran Jenkins
  • added a release note for user-visible changes to doc/changes
  • (if changing dimensions.yaml) make a copy of dimensions.yaml in configs/old_dimensions

Copy link

codecov bot commented Aug 13, 2024

Codecov Report

Attention: Patch coverage is 98.38710% with 1 line in your changes missing coverage. Please review.

Project coverage is 89.53%. Comparing base (6ba7992) to head (659e30c).
Report is 5 commits behind head on main.

Files Patch % Lines
...hon/lsst/daf/butler/queries/_expression_strings.py 93.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1054      +/-   ##
==========================================
+ Coverage   89.51%   89.53%   +0.02%     
==========================================
  Files         361      361              
  Lines       46147    46200      +53     
  Branches     9460     9469       +9     
==========================================
+ Hits        41309    41366      +57     
+ Misses       3504     3499       -5     
- Partials     1334     1335       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dhirving dhirving marked this pull request as ready for review August 14, 2024 00:09
case lsst.sphgeom.LonLat():
return _make_region_literal_from_lonlat(value)
case astropy.coordinates.SkyCoord():
icrs = value.transform_to("icrs")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is ICRS the right coordinate system?

ra_value = _get_float_literal_value(ra, node.ra)
dec_value = _get_float_literal_value(dec, node.dec)

lon_lat = lsst.sphgeom.LonLat.fromDegrees(ra_value, dec_value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you notice whether those preexisting docs specifically said the values were supposed to be decimal degrees? If we don't want to get into handling multiple angular units (to say nothing of H:M:S angles), decimal degrees is probably the best choice, but it definitely needs to be documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing it previously said about units was "similar to ADQL syntax", which implies decimal degrees.

I had already tweaked the docs to say this:

You can check for overlap of a region with a point using the POINT(ra, dec) syntax,
where ra and dec are specified as an ICRS sky position in degrees.

Is that a good way to phrase it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

case lsst.sphgeom.LonLat():
vec = lsst.sphgeom.UnitVector3d(value)
# Convert the point to a Region by representing it as a zero-radius
# Circle.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure whether zero-radius would work, but if it does, great!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to, and from the docs it seems to be intended to with slight caveats (e.g. they go into a discussion of an edge case where two zero-radius circles that are very close but not exact might still be considered overlapping.)

icrs = value.transform_to("icrs")
ra = icrs.ra.degree
dec = icrs.dec.degree
lon_lat = lsst.sphgeom.LonLat.fromDegrees(ra, dec)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

astropy.coordinates.SkyCoord can be array-valued (which I think means that icrs.ra.degree and icrs.dec.degree will come back as something numpy-based. We should probably guard against this to make the exception raised friendlier.

Spatial queries using the new query system can now be constrained using the `POINT()` function in `where` strings.  This has long been documented to exist, but never worked.
Region overlaps can now be tested against points specified as `lsst.sphgeom.LonLat` or `astropy.coordinates.SkyCoord` values.
Added more information about region overlap queries .

Removed information about "IN" syntax for regions -- this has never been supported.
astropy's SkyCoord can be array-valued, but when specifying a point we can only use a scalar.  We now raise a better error message when this occurs.
@dhirving dhirving merged commit 05928f5 into main Aug 14, 2024
18 checks passed
@dhirving dhirving deleted the tickets/DM-45752 branch August 14, 2024 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants