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-46173: Allow negative values for ra and dec #1072

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/lsst/daf/butler/queries/_expression_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,5 +365,7 @@ def _get_float_literal_value(value: _VisitorResult, node: Node) -> float:
return expr.value
elif expr.expression_type == "int":
return float(expr.value)
elif expr.expression_type == "unary" and expr.operator == "-":
return -1 * _get_float_literal_value(_ColExpr(expr.operand), node)

raise InvalidQueryError(f"Expression '{node}' in POINT() is not a literal number.")
14 changes: 14 additions & 0 deletions python/lsst/daf/butler/tests/butler_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,20 @@ def _check_visit_id(query: Query) -> None:
# conversion of integer to float.
_check_visit_id(query.where(f"visit_detector_region.region OVERLAPS POINT({ra}, 1)"))

# Negative values are allowed for dec, since it's defined as -90 to
# 90. Tract 1, patch 4 slightly overlaps some negative dec values.
result = list(query.where("patch.region OVERLAPS POINT(0.335, -0.000000001)").data_ids(["patch"]))
self.assertEqual(len(result), 1)
id = result[0]
self.assertEqual(id["patch"], 4)
self.assertEqual(id["tract"], 1)
# Out of bounds dec values are not allowed.
with self.assertRaisesRegex(ValueError, "invalid latitude angle"):
list(query.where("patch.region OVERLAPS POINT(0.335, -91)").data_ids(["patch"]))

# Negative ra values are allowed.
_check_visit_id(query.where(f"POINT({ra-360}, {dec}) OVERLAPS visit_detector_region.region"))

# Substitute ra and dec values via bind instead of literals in the
# string.
_check_visit_id(
Expand Down
Loading