99
99
constraints.
100
100
"""
101
101
102
-
103
102
import warnings
103
+ from io import BytesIO
104
104
import xml .etree .ElementTree as tree
105
105
106
- import six
107
106
import astropy .units as u
108
107
import astropy .coordinates as coord
109
108
import astropy .io .votable as votable
110
109
111
- from . .query import BaseQuery
112
- from .. utils import commons
113
- from . import conf
114
- from . .exceptions import TableParseError , NoResultsWarning , InvalidQueryError
110
+ from astroquery .query import BaseQuery
111
+ from astroquery . utils import commons , async_to_sync
112
+ from astroquery . irsa import conf
113
+ from astroquery .exceptions import TableParseError , NoResultsWarning , InvalidQueryError
115
114
116
115
117
116
__all__ = ['Irsa' , 'IrsaClass' ]
118
117
119
118
119
+ @async_to_sync
120
120
class IrsaClass (BaseQuery ):
121
121
IRSA_URL = conf .server
122
122
GATOR_LIST_URL = conf .gator_list_catalogs
123
123
TIMEOUT = conf .timeout
124
124
ROW_LIMIT = conf .row_limit
125
125
126
- def query_region (self , coordinates = None , catalog = None , spatial = 'Cone' ,
127
- radius = 10 * u .arcsec , width = None , polygon = None ,
128
- get_query_payload = False , verbose = False , selcols = None ):
129
- """
130
- This function can be used to perform either cone, box, polygon or
131
- all-sky search in the catalogs hosted by the NASA/IPAC Infrared
132
- Science Archive (IRSA).
133
-
134
- Parameters
135
- ----------
136
- coordinates : str, `astropy.coordinates` object
137
- Gives the position of the center of the cone or box if
138
- performing a cone or box search. The string can give coordinates
139
- in various coordinate systems, or the name of a source that will
140
- be resolved on the server (see `here
141
- <https://irsa.ipac.caltech.edu/search_help.html>`_ for more
142
- details). Required if spatial is ``'Cone'`` or ``'Box'``. Optional
143
- if spatial is ``'Polygon'``.
144
- catalog : str
145
- The catalog to be used. To list the available catalogs, use
146
- :meth:`~astroquery.irsa.IrsaClass.print_catalogs`.
147
- spatial : str
148
- Type of spatial query: ``'Cone'``, ``'Box'``, ``'Polygon'``, and
149
- ``'All-Sky'``. If missing then defaults to ``'Cone'``.
150
- radius : str or `~astropy.units.Quantity` object, [optional for spatial is ``'Cone'``]
151
- The string must be parsable by `~astropy.coordinates.Angle`. The
152
- appropriate `~astropy.units.Quantity` object from
153
- `astropy.units` may also be used. Defaults to 10 arcsec.
154
- width : str, `~astropy.units.Quantity` object [Required for spatial is ``'Polygon'``.]
155
-
156
- The string must be parsable by `~astropy.coordinates.Angle`. The
157
- appropriate `~astropy.units.Quantity` object from `astropy.units`
158
- may also be used.
159
- polygon : list, [Required for spatial is ``'Polygon'``]
160
- A list of ``(ra, dec)`` pairs (as tuples), in decimal degrees,
161
- outlining the polygon to search in. It can also be a list of
162
- `astropy.coordinates` object or strings that can be parsed by
163
- `astropy.coordinates.ICRS`.
164
- get_query_payload : bool, optional
165
- If `True` then returns the dictionary sent as the HTTP request.
166
- Defaults to `False`.
167
- verbose : bool, optional.
168
- If `True` then displays warnings when the returned VOTable does not
169
- conform to the standard. Defaults to `False`.
170
- selcols : str, optional
171
- Target column list with value separated by a comma(,)
172
-
173
-
174
- Returns
175
- -------
176
- table : `~astropy.table.Table`
177
- A table containing the results of the query
178
- """
179
- response = self .query_region_async (coordinates , catalog = catalog ,
180
- spatial = spatial , radius = radius ,
181
- width = width , polygon = polygon ,
182
- get_query_payload = get_query_payload ,
183
- selcols = selcols )
184
- if get_query_payload :
185
- return response
186
- return self ._parse_result (response , verbose = verbose )
187
-
188
- def query_region_async (self , coordinates = None , catalog = None ,
126
+ def query_region_async (self , coordinates = None , * , catalog = None ,
189
127
spatial = 'Cone' , radius = 10 * u .arcsec , width = None ,
190
128
polygon = None , get_query_payload = False ,
191
- selcols = None ):
129
+ selcols = None , verbose = False , cache = True ):
192
130
"""
193
131
This function serves the same purpose as
194
132
:meth:`~astroquery.irsa.IrsaClass.query_region`, but returns the raw
@@ -228,6 +166,11 @@ def query_region_async(self, coordinates=None, catalog=None,
228
166
Defaults to `False`.
229
167
selcols : str, optional
230
168
Target column list with value separated by a comma(,)
169
+ verbose : bool, optional.
170
+ If `True` then displays warnings when the returned VOTable does not
171
+ conform to the standard. Defaults to `False`.
172
+ cache : bool, optional
173
+ Use local cache when set to `True`.
231
174
232
175
Returns
233
176
-------
@@ -246,7 +189,8 @@ def query_region_async(self, coordinates=None, catalog=None,
246
189
if get_query_payload :
247
190
return request_payload
248
191
response = self ._request ("GET" , url = Irsa .IRSA_URL ,
249
- params = request_payload , timeout = Irsa .TIMEOUT )
192
+ params = request_payload , timeout = Irsa .TIMEOUT ,
193
+ cache = cache )
250
194
return response
251
195
252
196
def _parse_spatial (self , spatial , coordinates , radius = None , width = None ,
@@ -391,7 +335,7 @@ def _parse_result(self, response, verbose=False):
391
335
392
336
# Read it in using the astropy VO table reader
393
337
try :
394
- first_table = votable .parse (six . BytesIO (response .content ),
338
+ first_table = votable .parse (BytesIO (response .content ),
395
339
pedantic = False ).get_first_table ()
396
340
except Exception as ex :
397
341
self .response = response
@@ -410,33 +354,41 @@ def _parse_result(self, response, verbose=False):
410
354
411
355
return table
412
356
413
- def list_catalogs (self ):
357
+ def list_catalogs (self , cache = False ):
414
358
"""
415
359
Return a dictionary of the catalogs in the IRSA Gator tool.
416
360
361
+ Parameters
362
+ ----------
363
+ cache : bool
364
+ Use local cache when set to `True`. Default is `False`.
365
+
417
366
Returns
418
367
-------
419
368
catalogs : dict
420
369
A dictionary of catalogs where the key indicates the catalog
421
370
name to be used in query functions, and the value is the verbose
422
371
description of the catalog.
372
+
423
373
"""
424
374
response = self ._request ("GET" , url = Irsa .GATOR_LIST_URL ,
425
- params = dict (mode = 'xml' ), timeout = Irsa .TIMEOUT )
375
+ params = dict (mode = 'xml' ), cache = cache ,
376
+ timeout = Irsa .TIMEOUT )
426
377
427
378
root = tree .fromstring (response .content )
428
379
catalogs = {}
429
380
for catalog in root .findall ('catalog' ):
430
381
catname = catalog .find ('catname' ).text
431
382
desc = catalog .find ('desc' ).text
432
383
catalogs [catname ] = desc
384
+
433
385
return catalogs
434
386
435
- def print_catalogs (self ):
387
+ def print_catalogs (self , cache = False ):
436
388
"""
437
389
Display a table of the catalogs in the IRSA Gator tool.
438
390
"""
439
- catalogs = self .list_catalogs ()
391
+ catalogs = self .list_catalogs (cache = cache )
440
392
for catname in catalogs :
441
393
print ("{:30s} {:s}" .format (catname , catalogs [catname ]))
442
394
@@ -447,7 +399,7 @@ def print_catalogs(self):
447
399
def _parse_coordinates (coordinates ):
448
400
# borrowed from commons.parse_coordinates as from_name wasn't required in
449
401
# this case
450
- if isinstance (coordinates , six . string_types ):
402
+ if isinstance (coordinates , str ):
451
403
try :
452
404
c = coord .SkyCoord (coordinates , frame = 'icrs' )
453
405
warnings .warn ("Coordinate string is being interpreted as an "
0 commit comments