Skip to content

Commit 0c90d6e

Browse files
authored
Merge pull request #3201 from bsipocz/ENH_irsa_async_tap
ENH: adding async mode to IRSA TAP based queries
2 parents e58ae49 + 29ba772 commit 0c90d6e

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ ipac.irsa
2727
- Adding the "servicetype" kwarg to ``list_collections`` to be able to list SIA
2828
and SSA collections separately. [#3200]
2929

30+
- Adding support for asynchronous queries using the new ``async_job``
31+
keyword. [#3201]
32+
3033
ipac.nexsci.nasa_exoplanet_archive
3134
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3235

astroquery/ipac/irsa/core.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def tap(self):
4747
self._tap = TAPService(baseurl=self.tap_url, session=self._session)
4848
return self._tap
4949

50-
def query_tap(self, query, *, maxrec=None):
50+
def query_tap(self, query, *, async_job=False, maxrec=None):
5151
"""
5252
Send query to IRSA TAP. Results in `~pyvo.dal.TAPResults` format.
5353
result.to_qtable in `~astropy.table.QTable` format
@@ -56,7 +56,9 @@ def query_tap(self, query, *, maxrec=None):
5656
----------
5757
query : str
5858
ADQL query to be executed
59-
maxrec : int
59+
async_job : bool, optional
60+
if True query is run in asynchronous mode
61+
maxrec : int, optional
6062
maximum number of records to return
6163
6264
Returns
@@ -69,8 +71,12 @@ def query_tap(self, query, *, maxrec=None):
6971
TAP query result as `~astropy.table.QTable`
7072
7173
"""
72-
log.debug(f'TAP query: {query}')
73-
return self.tap.search(query, language='ADQL', maxrec=maxrec)
74+
log.debug(f'Query is run in async mode: {async_job}\n TAP query: {query}')
75+
76+
if async_job:
77+
return self.tap.run_async(query, language='ADQL', maxrec=maxrec)
78+
else:
79+
return self.tap.run_sync(query, language='ADQL', maxrec=maxrec)
7480

7581
def query_sia(self, *, pos=None, band=None, time=None, pol=None,
7682
field_of_view=None, spatial_resolution=None,
@@ -155,7 +161,7 @@ def list_collections(self, servicetype=None):
155161
@deprecated_renamed_argument(("selcols", "cache", "verbose"), ("columns", None, None), since="0.4.7")
156162
def query_region(self, coordinates=None, *, catalog=None, spatial='Cone',
157163
radius=10 * u.arcsec, width=None, polygon=None,
158-
get_query_payload=False, columns='*',
164+
get_query_payload=False, columns='*', async_job=False,
159165
verbose=False, cache=True):
160166
"""
161167
Queries the IRSA TAP server around a coordinate and returns a `~astropy.table.Table` object.
@@ -190,6 +196,8 @@ def query_region(self, coordinates=None, *, catalog=None, spatial='Cone',
190196
Defaults to `False`.
191197
columns : str, optional
192198
Target column list with value separated by a comma(,)
199+
async_job : bool, optional
200+
if True query is run in asynchronous mode
193201
194202
Returns
195203
-------
@@ -239,7 +247,7 @@ def query_region(self, coordinates=None, *, catalog=None, spatial='Cone',
239247

240248
if get_query_payload:
241249
return adql
242-
response = self.query_tap(query=adql)
250+
response = self.query_tap(query=adql, async_job=async_job)
243251

244252
return response.to_table()
245253

docs/ipac/irsa/irsa.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,21 @@ star HIP 12 with just the ra, dec and w1mpro columns would be:
183183
--------- ----------- ------
184184
0.0407905 -35.9602605 4.837
185185

186+
Async queries
187+
--------------
188+
189+
For bigger queries it is recommended using the ``async_job`` keyword option. When used,
190+
the query is send in asynchronous mode.
191+
192+
.. doctest-remote-data::
193+
194+
>>> from astroquery.ipac.irsa import Irsa
195+
>>> table = Irsa.query_region("HIP 12", catalog="allwise_p3as_psd", spatial="Cone", async_job=True)
196+
>>> print(table)
197+
designation ra dec sigra ... y z spt_ind htm20
198+
deg deg arcsec ...
199+
------------------- --------- ----------- ------ ... ------------------ ------------------- --------- -------------
200+
J000009.78-355736.9 0.0407905 -35.9602605 0.0454 ... 0.0005762523295116 -0.5872239888098030 100102010 8873706189183
186201

187202
Direct TAP query to the IRSA server
188203
-----------------------------------

0 commit comments

Comments
 (0)