Skip to content

Commit 9344740

Browse files
committed
make search_offset optional
1 parent dba6380 commit 9344740

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

astroquery/heasarc/core.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def query_tap(self, query, *, maxrec=None):
298298
True, True, True, False)
299299
)
300300
def query_region(self, position=None, catalog=None, radius=None, *,
301-
spatial='cone', width=None, polygon=None,
301+
spatial='cone', width=None, polygon=None, add_offset=False,
302302
get_query_payload=False, columns=None, cache=False,
303303
verbose=False, maxrec=None,
304304
**kwargs):
@@ -335,6 +335,10 @@ def query_region(self, position=None, catalog=None, radius=None, *,
335335
outlining the polygon to search in. It can also be a list of
336336
`astropy.coordinates` object or strings that can be parsed by
337337
`astropy.coordinates.ICRS`.
338+
add_offset: bool
339+
If True and spatial=='cone', add a search_offset column that
340+
indicates the separation (in arcmin) between the requested
341+
coordinate and the entry coordinates in the catalog. Default is False.
338342
get_query_payload : bool, optional
339343
If `True` then returns the generated ADQL query as str.
340344
Defaults to `False`.
@@ -399,9 +403,10 @@ def query_region(self, position=None, catalog=None, radius=None, *,
399403
radius = coordinates.Angle(radius)
400404
where = (" WHERE CONTAINS(POINT('ICRS',ra,dec),CIRCLE("
401405
f"'ICRS',{ra},{dec},{radius.to(u.deg).value}))=1")
402-
# add search_offset_ for the case of cone
403-
columns += (",DISTANCE(POINT('ICRS',ra,dec), "
404-
f"POINT('ICRS',{ra},{dec})) as search_offset_")
406+
# add search_offset for the case of cone
407+
if add_offset:
408+
columns += (",DISTANCE(POINT('ICRS',ra,dec), "
409+
f"POINT('ICRS',{ra},{dec})) as search_offset")
405410
elif spatial.lower() == 'box':
406411
if isinstance(width, str):
407412
width = coordinates.Angle(width)
@@ -423,8 +428,8 @@ def query_region(self, position=None, catalog=None, radius=None, *,
423428
self._catalog_name = catalog
424429

425430
table = response.to_table()
426-
if 'search_offset_' in table.colnames:
427-
table['search_offset_'].unit = u.arcmin
431+
if add_offset:
432+
table['search_offset'].unit = u.arcmin
428433
if len(table) == 0:
429434
warnings.warn(
430435
NoResultsWarning("No matching rows were found in the query.")

astroquery/heasarc/tests/test_heasarc.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ def mock_meta():
8282

8383
@pytest.mark.parametrize("coordinates", OBJ_LIST)
8484
@pytest.mark.parametrize("radius", SIZE_LIST)
85-
def test_query_region_cone(coordinates, radius):
85+
@pytest.mark.parametrize("offset", [True, False])
86+
def test_query_region_cone(coordinates, radius, offset):
8687
# use columns='*' to avoid remote call to obtain the default columns
8788
query = Heasarc.query_region(
8889
coordinates,
@@ -91,12 +92,16 @@ def test_query_region_cone(coordinates, radius):
9192
radius=radius,
9293
columns="*",
9394
get_query_payload=True,
95+
add_offset=True,
9496
)
9597

9698
# We don't fully float compare in this string, there are slight
9799
# differences due to the name-coordinate resolution and conversions
98-
assert ("SELECT *,DISTANCE(POINT('ICRS',ra,dec), "
99-
"POINT('ICRS',182.63") in query
100+
if offset:
101+
distance_text = ",DISTANCE(POINT('ICRS',ra,dec), POINT('ICRS',182.63"
102+
else:
103+
distance_text = ""
104+
assert (f"SELECT *{distance_text}") in query
100105
assert (
101106
"FROM suzamaster WHERE CONTAINS(POINT('ICRS',ra,dec),"
102107
"CIRCLE('ICRS',182.63" in query

0 commit comments

Comments
 (0)