9999 constraints.
100100"""
101101
102-
103102import warnings
103+ from io import BytesIO
104104import xml .etree .ElementTree as tree
105105
106- import six
107106import astropy .units as u
108107import astropy .coordinates as coord
109108import astropy .io .votable as votable
110109
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
115114
116115
117116__all__ = ['Irsa' , 'IrsaClass' ]
118117
119118
119+ @async_to_sync
120120class IrsaClass (BaseQuery ):
121121 IRSA_URL = conf .server
122122 GATOR_LIST_URL = conf .gator_list_catalogs
123123 TIMEOUT = conf .timeout
124124 ROW_LIMIT = conf .row_limit
125125
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 ,
189127 spatial = 'Cone' , radius = 10 * u .arcsec , width = None ,
190128 polygon = None , get_query_payload = False ,
191- selcols = None ):
129+ selcols = None , verbose = False , cache = True ):
192130 """
193131 This function serves the same purpose as
194132 :meth:`~astroquery.irsa.IrsaClass.query_region`, but returns the raw
@@ -228,6 +166,11 @@ def query_region_async(self, coordinates=None, catalog=None,
228166 Defaults to `False`.
229167 selcols : str, optional
230168 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`.
231174
232175 Returns
233176 -------
@@ -246,7 +189,8 @@ def query_region_async(self, coordinates=None, catalog=None,
246189 if get_query_payload :
247190 return request_payload
248191 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 )
250194 return response
251195
252196 def _parse_spatial (self , spatial , coordinates , radius = None , width = None ,
@@ -391,7 +335,7 @@ def _parse_result(self, response, verbose=False):
391335
392336 # Read it in using the astropy VO table reader
393337 try :
394- first_table = votable .parse (six . BytesIO (response .content ),
338+ first_table = votable .parse (BytesIO (response .content ),
395339 pedantic = False ).get_first_table ()
396340 except Exception as ex :
397341 self .response = response
@@ -410,33 +354,41 @@ def _parse_result(self, response, verbose=False):
410354
411355 return table
412356
413- def list_catalogs (self ):
357+ def list_catalogs (self , cache = False ):
414358 """
415359 Return a dictionary of the catalogs in the IRSA Gator tool.
416360
361+ Parameters
362+ ----------
363+ cache : bool
364+ Use local cache when set to `True`. Default is `False`.
365+
417366 Returns
418367 -------
419368 catalogs : dict
420369 A dictionary of catalogs where the key indicates the catalog
421370 name to be used in query functions, and the value is the verbose
422371 description of the catalog.
372+
423373 """
424374 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 )
426377
427378 root = tree .fromstring (response .content )
428379 catalogs = {}
429380 for catalog in root .findall ('catalog' ):
430381 catname = catalog .find ('catname' ).text
431382 desc = catalog .find ('desc' ).text
432383 catalogs [catname ] = desc
384+
433385 return catalogs
434386
435- def print_catalogs (self ):
387+ def print_catalogs (self , cache = False ):
436388 """
437389 Display a table of the catalogs in the IRSA Gator tool.
438390 """
439- catalogs = self .list_catalogs ()
391+ catalogs = self .list_catalogs (cache = cache )
440392 for catname in catalogs :
441393 print ("{:30s} {:s}" .format (catname , catalogs [catname ]))
442394
@@ -447,7 +399,7 @@ def print_catalogs(self):
447399def _parse_coordinates (coordinates ):
448400 # borrowed from commons.parse_coordinates as from_name wasn't required in
449401 # this case
450- if isinstance (coordinates , six . string_types ):
402+ if isinstance (coordinates , str ):
451403 try :
452404 c = coord .SkyCoord (coordinates , frame = 'icrs' )
453405 warnings .warn ("Coordinate string is being interpreted as an "
0 commit comments