Skip to content

Commit a3df89c

Browse files
committed
Move logic into commons
1 parent 3fcac9b commit a3df89c

File tree

8 files changed

+66
-118
lines changed

8 files changed

+66
-118
lines changed

CHANGES.rst

Lines changed: 20 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -35,66 +35,34 @@ simbad
3535
Service fixes and enhancements
3636
------------------------------
3737

38-
linelists.cdms
39-
^^^^^^^^^^^^^^
40-
41-
- Add whole catalog retrieval, improve error messaging for unparseable lines,
42-
improve metadata catalog, and improve lookuptable behavior [#3173,#2901]
43-
44-
heasarc
45-
^^^^^^^
46-
47-
- Fix Heasarc.download_data for Sciserver. [#3183]
48-
49-
jplspec
50-
^^^^^^^
51-
52-
- minor improvement to lookuptable behavior [#3173,#2901]
53-
54-
mocserver
55-
^^^^^^^^^
56-
57-
- Switch to https instead of http for the default url (allows pyodide to use the
58-
module) [#3139]
59-
60-
- Add ``TimeMOC`` and ``STMOC`` as possible entries in ``MOCServer.query_region`` to
61-
allow temporal and space-time searches [#3139]
62-
63-
- ``return_moc`` now allows to ask for a Time-MOC or a Space-Time MOC rather than only
64-
Space-MOCs [#3139]
65-
66-
- Fix query by MOC that would write a file ``moc.fits`` where the method was executed in
67-
overwriting mode (potentially deleting data if there was a conflicting file) [#3139]
68-
69-
- [:warning: BREAKING] Returned tables now have a default list of fields instead of the
70-
> 130 columns returned previously. The full list of fields can be displayed with the
71-
new method ``MOCServer.list_fields`` [#3139]
38+
mast
39+
^^^^
7240

73-
- Add ``casesensitive`` parameter in the queries (previously, this was hardcoded
74-
to ``True``) [#3139]
41+
- Handle a MAST URI string as input for ``Observations.get_cloud_uri`` and a list of MAST URIs as input for
42+
``Observations.get_cloud_uris``. [#3193]
7543

76-
- Add ``coordinate_system`` parameter to the queries to allow to filter on the different
77-
bodies or frames. The list of available space systems can be printed with the new
78-
method ``MOCServer.list_coordinates_systems`` [#3139]
44+
simbad
45+
^^^^^^
7946

80-
- Add ``query_hips`` method, which is convenient to filter only Hierarchical progressive
81-
surveys [#3139]
47+
- The detailed hierarchy is now returned by default in ``query_hierarchy``
48+
(it was hidden by default in the previous versions) [#3195]
8249

83-
- New parameter ``criteria`` in ``query_region`` and ``query_hips`` that has the same
84-
use than ``meta_data`` in the deprecated method ``find_datasets`` [#3139]
50+
Service fixes and enhancements
51+
------------------------------
8552

86-
simbad
87-
^^^^^^
53+
gaia
54+
^^^^
8855

89-
- Fixed adding a list of fluxes with the deprecated notation
90-
``Simbad.add_votable_fields("flux(U)", "flux(J)")`` [#3186]
56+
- Update DR4 retrieval_type names and include the new one EPOCH_ASTROMETRY_BRIGHT [#3207]
9157

92-
- Support more of the 0.4.7 votable fields. Raise more significant error messages
93-
for the discontinued ones. [#3186]
58+
ipac.irsa
59+
^^^^^^^^^
9460

95-
- Fix the deprecated votable fields ``otype(V)`` and ``otype(S)`` [#3186]
61+
- Adding the "servicetype" kwarg to ``list_collections`` to be able to list SIA
62+
and SSA collections separately. [#3200]
9663

97-
- Fixed non existing flux filters as votable fields would fail silently [#3186]
64+
- Adding support for asynchronous queries using the new ``async_job``
65+
keyword. [#3201]
9866

9967
- Making ``'spatial'`` keyword in ``query_region`` case insensitive. [#3224]
10068

@@ -110,8 +78,6 @@ mast
11078

11179
- Bugfix where ``Observations.get_cloud_uri`` and ``Observations.get_cloud_uris`` fail if the MAST relative path is not found. [#3193]
11280

113-
- Handle coordinates that are not in the ICRS frame in query functions. [#3164]
114-
11581
simbad
11682
^^^^^^
11783

@@ -2166,4 +2132,4 @@ Infrastructure, Utility and Other Changes and Additions
21662132
0.1 (2013-09-19)
21672133
================
21682134

2169-
- Initial release. Includes features!
2135+
- Initial release. Includes features!

astroquery/mast/collections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from astropy.table import Table, Row
2121

22-
from ..utils import async_to_sync
22+
from ..utils import commons, async_to_sync
2323
from ..utils.class_or_instance import class_or_instance
2424
from ..exceptions import InvalidQueryError, MaxResultsWarning, InputWarning
2525

@@ -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 = utils.parse_coordinates(coordinates)
207+
coordinates = commons.parse_coordinates(coordinates, '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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from requests import HTTPError, RequestException
2020

2121
from astroquery import log
22-
from astroquery.utils import async_to_sync
22+
from astroquery.utils import commons, async_to_sync
2323
from astroquery.utils.class_or_instance import class_or_instance
2424
from astroquery.exceptions import InvalidQueryError, MaxResultsWarning, InputWarning, NoResultsWarning
2525

@@ -184,7 +184,7 @@ def query_region_async(self, coordinates, *, radius=3*u.arcmin, limit=5000, offs
184184
self._validate_criteria(**criteria)
185185

186186
# Put coordinates and radius into consistent format
187-
coordinates = utils.parse_coordinates(coordinates)
187+
coordinates = commons.parse_coordinates(coordinates, 'icrs')
188188

189189
# if radius is just a number we assume degrees
190190
radius = coord.Angle(radius, u.arcmin)

astroquery/mast/observations.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
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

2627
from ..utils import async_to_sync
2728
from ..utils.class_or_instance import class_or_instance
@@ -227,7 +228,7 @@ def query_region_async(self, coordinates, *, radius=0.2*u.deg, pagesize=None, pa
227228
"""
228229

229230
# Put coordinates and radius into consistent format
230-
coordinates = utils.parse_coordinates(coordinates)
231+
coordinates = commons.parse_coordinates(coordinates, 'icrs')
231232

232233
# if radius is just a number we assume degrees
233234
radius = coord.Angle(radius, u.deg)
@@ -346,7 +347,7 @@ def query_region_count(self, coordinates, *, radius=0.2*u.deg, pagesize=None, pa
346347
"""
347348

348349
# build the coordinates string needed by ObservationsClass._caom_filtered_position
349-
coordinates = utils.parse_coordinates(coordinates)
350+
coordinates = commons.parse_coordinates(coordinates, 'icrs')
350351

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

astroquery/mast/tests/test_mast.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,33 +1157,3 @@ def test_zcut_get_cutouts(patch_post, tmpdir):
11571157
assert isinstance(cutout_list, list)
11581158
assert len(cutout_list) == 1
11591159
assert isinstance(cutout_list[0], fits.HDUList)
1160-
1161-
1162-
################
1163-
# Utils tests #
1164-
################
1165-
1166-
1167-
def test_utils_parse_coordinates(patch_post):
1168-
1169-
def compare_coords(coords1, coords2):
1170-
assert coords1.ra.deg == coords2.ra.deg
1171-
assert coords1.dec.deg == coords2.dec.deg
1172-
assert coords1.frame.name == 'icrs'
1173-
assert coords2.frame.name == 'icrs'
1174-
1175-
# Expected result
1176-
expected = SkyCoord('266.40498829 -28.93617776', unit='deg')
1177-
1178-
# Parse a string
1179-
coords = mast.utils.parse_coordinates('266.40498829 -28.93617776')
1180-
compare_coords(coords, expected)
1181-
1182-
# Parse a SkyCoord in ICRS frame
1183-
coords = mast.utils.parse_coordinates(expected)
1184-
compare_coords(coords, expected)
1185-
1186-
# Parse a SkyCoord in galactic frame
1187-
galactic = SkyCoord('0 0', unit='deg', frame='galactic')
1188-
coords = mast.utils.parse_coordinates(galactic)
1189-
compare_coords(coords, galactic.transform_to('icrs'))

astroquery/mast/utils.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -122,32 +122,6 @@ def resolve_object(objectname):
122122
return coordinates
123123

124124

125-
def parse_coordinates(coordinates):
126-
"""
127-
Convenience function to parse user input of coordinates.
128-
129-
Parameters
130-
----------
131-
coordinates : str or `astropy.coordinates` object, optional
132-
The target around which to search. It may be specified as a
133-
string or as the appropriate `astropy.coordinates` object.
134-
135-
Returns
136-
-------
137-
response : `~astropy.coordinates.SkyCoord`
138-
The given coordinates as an `~astropy.coordinates.SkyCoord` object in the ICRS frame.
139-
"""
140-
141-
# Parse into SkyCoord object
142-
coordinates = commons.parse_coordinates(coordinates)
143-
144-
# Convert to ICRS frame, if needed
145-
if coordinates.frame.name != 'icrs':
146-
coordinates = coordinates.transform_to('icrs')
147-
148-
return coordinates
149-
150-
151125
def parse_input_location(coordinates=None, objectname=None):
152126
"""
153127
Convenience function to parse user input of coordinates and objectname.
@@ -183,7 +157,7 @@ def parse_input_location(coordinates=None, objectname=None):
183157

184158
# Parse coordinates, if given
185159
if coordinates:
186-
obj_coord = parse_coordinates(coordinates)
160+
obj_coord = commons.parse_coordinates(coordinates, 'icrs')
187161

188162
return obj_coord
189163

astroquery/utils/commons.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
ASTROPY_LT_6_0 = not minversion('astropy', '6.0')
3939

4040

41-
def parse_coordinates(coordinates):
41+
def parse_coordinates(coordinates, return_frame=None):
4242
"""
4343
Takes a string or astropy.coordinates object. Checks if the
4444
string is parsable as an `astropy.coordinates`
@@ -49,6 +49,10 @@ def parse_coordinates(coordinates):
4949
----------
5050
coordinates : str or `astropy.coordinates` object
5151
Astronomical coordinate
52+
return_frame : `astropy.coordinates` frame
53+
The frame to return the coordinates in. If None and `coordinates` is
54+
a string, the frame will be ICRS. If `coordinates` is an `astropy.coordinates` object, the
55+
frame will be the same as the input object.
5256
5357
Returns
5458
-------
@@ -91,6 +95,14 @@ def parse_coordinates(coordinates):
9195
c = SkyCoord(coordinates)
9296
else:
9397
raise TypeError("Argument cannot be parsed as a coordinate")
98+
99+
# Convert to requested frame, if given
100+
if return_frame and c.frame.name != return_frame.lower():
101+
try:
102+
c = c.transform_to(return_frame)
103+
except ValueError:
104+
warnings.warn(f"Failed to transform coordinates to requested frame: {return_frame}.", InputWarning)
105+
94106
return c
95107

96108

astroquery/utils/tests/test_utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import astropy.utils.data as aud
1616
from astropy.logger import log
1717

18+
from ...exceptions import InputWarning
1819
from ...utils import chunk_read, chunk_report, class_or_instance, commons
1920
from ...utils.process_asyncs import async_to_sync_docstr, async_to_sync
2021
from ...utils.docstr_chompers import remove_sections, prepend_docstr_nosections
@@ -80,6 +81,30 @@ def test_parse_coordinates_4():
8081
assert c.to_string() == coordinates
8182

8283

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

0 commit comments

Comments
 (0)