Skip to content

Commit

Permalink
Merge pull request #1072 from lsst/tickets/DM-46173
Browse files Browse the repository at this point in the history
DM-46173: Allow negative values for ra and dec
  • Loading branch information
dhirving committed Sep 10, 2024
2 parents 5c4a71f + d33ed6f commit 5a6ff82
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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

0 comments on commit 5a6ff82

Please sign in to comment.