Skip to content

Commit 01939a4

Browse files
authored
Merge pull request #3164 from snbianco/ASB-29990-coord-frame
2 parents 54d6dec + 12425e2 commit 01939a4

File tree

8 files changed

+47
-15
lines changed

8 files changed

+47
-15
lines changed

CHANGES.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ utils
143143

144144
- Raising cleaner errors earlier when server returns with error. [#3284]
145145

146+
- ``return_frame`` parameter in ``utils.commons.parse_coordinates`` returns coordinates in the specified frame. [#3164]
147+
146148

147149
0.4.10 (2025-03-18)
148150
===================
@@ -2279,4 +2281,4 @@ Infrastructure, Utility and Other Changes and Additions
22792281
0.1 (2013-09-19)
22802282
================
22812283

2282-
- Initial release. Includes features!
2284+
- Initial release. Includes features!

astroquery/mast/collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def query_region_async(self, coordinates, *, radius=0.2*u.deg, catalog="Hsc",
204204
"""
205205

206206
# Put coordinates and radius into consistent format
207-
coordinates = commons.parse_coordinates(coordinates)
207+
coordinates = commons.parse_coordinates(coordinates, return_frame='icrs')
208208

209209
# if radius is just a number we assume degrees
210210
radius = coord.Angle(radius, u.deg)

astroquery/mast/missions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def query_region_async(self, coordinates, *, radius=3*u.arcmin, limit=5000, offs
245245
self._validate_criteria(**criteria)
246246

247247
# Put coordinates and radius into consistent format
248-
coordinates = commons.parse_coordinates(coordinates)
248+
coordinates = commons.parse_coordinates(coordinates, return_frame='icrs')
249249

250250
# If radius is just a number, assume arcminutes
251251
radius = coord.Angle(radius, u.arcmin)

astroquery/mast/observations.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
from astropy.table import Table, Row, vstack
2323
from astroquery import log
2424
from astroquery.mast.cloud import CloudAccess
25+
from astroquery.utils import commons
2526

26-
from ..utils import commons, async_to_sync
27+
from ..utils import async_to_sync
2728
from ..utils.class_or_instance import class_or_instance
2829
from ..exceptions import (InvalidQueryError, RemoteServiceError,
2930
NoResultsWarning, InputWarning)
@@ -234,7 +235,7 @@ def query_region_async(self, coordinates, *, radius=0.2*u.deg, pagesize=None, pa
234235
"""
235236

236237
# Put coordinates and radius into consistent format
237-
coordinates = commons.parse_coordinates(coordinates)
238+
coordinates = commons.parse_coordinates(coordinates, return_frame='icrs')
238239

239240
# if radius is just a number we assume degrees
240241
radius = coord.Angle(radius, u.deg)
@@ -363,7 +364,7 @@ def query_region_count(self, coordinates, *, radius=0.2*u.deg, pagesize=None, pa
363364
"""
364365

365366
# build the coordinates string needed by ObservationsClass._caom_filtered_position
366-
coordinates = commons.parse_coordinates(coordinates)
367+
coordinates = commons.parse_coordinates(coordinates, return_frame='icrs')
367368

368369
# if radius is just a number we assume degrees
369370
radius = coord.Angle(radius, u.deg)

astroquery/mast/tests/test_mast_remote.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,6 @@ def test_mast_service_request(self):
416416
# Is result limited to ten rows
417417
assert len(result) == 10
418418

419-
# Are the GALEX observations in the results table
420-
assert "GALEX" in result['obs_collection']
421-
422-
# Are the two GALEX observations with obs_id 6374399093149532160 in the results table
423-
assert len(result[np.where(result["obs_id"] == "6374399093149532160")]) == 2
424-
425419
def test_mast_query(self):
426420
result = Mast.mast_query('Mast.Caom.Cone', ra=184.3, dec=54.5, radius=0.2)
427421

astroquery/mast/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ def parse_input_location(*, coordinates=None, objectname=None, resolver=None):
216216
Returns
217217
-------
218218
response : `~astropy.coordinates.SkyCoord`
219-
The given coordinates, or object's location as an `~astropy.coordinates.SkyCoord` object.
219+
The given coordinates, or object's location as an `~astropy.coordinates.SkyCoord` object
220+
in the ICRS frame.
220221
"""
221222

222223
# Checking for valid input
@@ -232,8 +233,9 @@ def parse_input_location(*, coordinates=None, objectname=None, resolver=None):
232233
if objectname:
233234
obj_coord = resolve_object(objectname, resolver=resolver)
234235

236+
# Parse coordinates, if given
235237
if coordinates:
236-
obj_coord = commons.parse_coordinates(coordinates)
238+
obj_coord = commons.parse_coordinates(coordinates, return_frame='icrs')
237239

238240
return obj_coord
239241

astroquery/utils/commons.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
ASTROPY_LT_7_1_1 = not minversion('astropy', '7.1.1')
4141

4242

43-
def parse_coordinates(coordinates):
43+
def parse_coordinates(coordinates, *, return_frame=None):
4444
"""
4545
Takes a string or astropy.coordinates object. Checks if the
4646
string is parsable as an `astropy.coordinates`
@@ -51,6 +51,10 @@ def parse_coordinates(coordinates):
5151
----------
5252
coordinates : str or `astropy.coordinates` object
5353
Astronomical coordinate
54+
return_frame : `astropy.coordinates` frame
55+
The frame to return the coordinates in. If None and ``coordinates`` is
56+
a string, the frame will be ICRS. If ``coordinates`` is an `astropy.coordinates` object, the
57+
frame will be the same as the input object.
5458
5559
Returns
5660
-------
@@ -93,6 +97,11 @@ def parse_coordinates(coordinates):
9397
c = SkyCoord(coordinates)
9498
else:
9599
raise TypeError("Argument cannot be parsed as a coordinate")
100+
101+
# Convert to requested frame, if given
102+
if return_frame and c.frame.name != return_frame.lower():
103+
c = c.transform_to(return_frame)
104+
96105
return c
97106

98107

astroquery/utils/tests/test_utils.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,30 @@ def test_parse_coordinates_4():
8080
assert c.to_string() == coordinates
8181

8282

83+
def test_parse_coordinates_return_frame():
84+
# String input should return in icrs frame
85+
coords = commons.parse_coordinates('266.40498829 -28.93617776')
86+
assert coords.frame.name == 'icrs'
87+
88+
# SkyCoord input without return_frame should return in original frame
89+
galactic = coord.SkyCoord('0 0', unit='deg', frame='galactic')
90+
coords = commons.parse_coordinates(galactic)
91+
assert coords.frame.name == 'galactic'
92+
93+
# Parse a SkyCoord in galactic frame into icrs frame
94+
galactic = coord.SkyCoord('0 0', unit='deg', frame='galactic')
95+
icrs = galactic.transform_to('icrs') # Expected result
96+
coords = commons.parse_coordinates(galactic, return_frame='icrs')
97+
assert icrs.ra.deg == coords.ra.deg
98+
assert icrs.dec.deg == coords.dec.deg
99+
assert galactic.frame.name == 'galactic'
100+
assert coords.frame.name == 'icrs'
101+
102+
# ValueError if transformation fails
103+
with pytest.raises(ValueError):
104+
coords = commons.parse_coordinates(galactic, return_frame='invalid')
105+
106+
83107
col_1 = [1, 2, 3]
84108
col_2 = [0, 1, 0, 1, 0, 1]
85109
col_3 = ['v', 'w', 'x', 'y', 'z']

0 commit comments

Comments
 (0)