From d33ed6fbecda29636ba78cf9588142187a5a6e28 Mon Sep 17 00:00:00 2001 From: "David H. Irving" Date: Fri, 6 Sep 2024 15:04:41 -0700 Subject: [PATCH] Allow negative values for ra and dec Fix an issue where ra and dec values in POINT() query expressions could not be negative. --- .../lsst/daf/butler/queries/_expression_strings.py | 2 ++ python/lsst/daf/butler/tests/butler_queries.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/python/lsst/daf/butler/queries/_expression_strings.py b/python/lsst/daf/butler/queries/_expression_strings.py index 3930b80d7a..50051c7904 100644 --- a/python/lsst/daf/butler/queries/_expression_strings.py +++ b/python/lsst/daf/butler/queries/_expression_strings.py @@ -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.") diff --git a/python/lsst/daf/butler/tests/butler_queries.py b/python/lsst/daf/butler/tests/butler_queries.py index b61cc76a5b..34ae03be95 100644 --- a/python/lsst/daf/butler/tests/butler_queries.py +++ b/python/lsst/daf/butler/tests/butler_queries.py @@ -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(