Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: adding async mode to IRSA TAP based queries #3201

Merged
merged 5 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ ipac.irsa
- Adding the "servicetype" kwarg to ``list_collections`` to be able to list SIA
and SSA collections separately. [#3200]

- Adding support for asynchronous queries using the new ``async_job``
keyword. [#3201]

ipac.nexsci.nasa_exoplanet_archive
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
20 changes: 14 additions & 6 deletions astroquery/ipac/irsa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def tap(self):
self._tap = TAPService(baseurl=self.tap_url, session=self._session)
return self._tap

def query_tap(self, query, *, maxrec=None):
def query_tap(self, query, *, async_job=False, maxrec=None):
"""
Send query to IRSA TAP. Results in `~pyvo.dal.TAPResults` format.
result.to_qtable in `~astropy.table.QTable` format
Expand All @@ -56,7 +56,9 @@ def query_tap(self, query, *, maxrec=None):
----------
query : str
ADQL query to be executed
maxrec : int
async_job : bool, optional
if True query is run in asynchronous mode
maxrec : int, optional
maximum number of records to return

Returns
Expand All @@ -69,8 +71,12 @@ def query_tap(self, query, *, maxrec=None):
TAP query result as `~astropy.table.QTable`

"""
log.debug(f'TAP query: {query}')
return self.tap.search(query, language='ADQL', maxrec=maxrec)
log.debug(f'Query is run in async mode: {async_job}\n TAP query: {query}')

if async_job:
return self.tap.run_async(query, language='ADQL', maxrec=maxrec)
else:
return self.tap.run_sync(query, language='ADQL', maxrec=maxrec)

def query_sia(self, *, pos=None, band=None, time=None, pol=None,
field_of_view=None, spatial_resolution=None,
Expand Down Expand Up @@ -155,7 +161,7 @@ def list_collections(self, servicetype=None):
@deprecated_renamed_argument(("selcols", "cache", "verbose"), ("columns", None, None), since="0.4.7")
def query_region(self, coordinates=None, *, catalog=None, spatial='Cone',
radius=10 * u.arcsec, width=None, polygon=None,
get_query_payload=False, columns='*',
get_query_payload=False, columns='*', async_job=False,
verbose=False, cache=True):
"""
Queries the IRSA TAP server around a coordinate and returns a `~astropy.table.Table` object.
Expand Down Expand Up @@ -190,6 +196,8 @@ def query_region(self, coordinates=None, *, catalog=None, spatial='Cone',
Defaults to `False`.
columns : str, optional
Target column list with value separated by a comma(,)
async_job : bool, optional
if True query is run in asynchronous mode

Returns
-------
Expand Down Expand Up @@ -239,7 +247,7 @@ def query_region(self, coordinates=None, *, catalog=None, spatial='Cone',

if get_query_payload:
return adql
response = self.query_tap(query=adql)
response = self.query_tap(query=adql, async_job=async_job)

return response.to_table()

Expand Down
15 changes: 15 additions & 0 deletions docs/ipac/irsa/irsa.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,21 @@ star HIP 12 with just the ra, dec and w1mpro columns would be:
--------- ----------- ------
0.0407905 -35.9602605 4.837

Async queries
--------------

For bigger queries it is recommended using the ``async_job`` keyword option. When used,
the query is send in asynchronous mode.

.. doctest-remote-data::

>>> from astroquery.ipac.irsa import Irsa
>>> table = Irsa.query_region("HIP 12", catalog="allwise_p3as_psd", spatial="Cone", async_job=True)
>>> print(table)
designation ra dec sigra ... y z spt_ind htm20
deg deg arcsec ...
------------------- --------- ----------- ------ ... ------------------ ------------------- --------- -------------
J000009.78-355736.9 0.0407905 -35.9602605 0.0454 ... 0.0005762523295116 -0.5872239888098030 100102010 8873706189183

Direct TAP query to the IRSA server
-----------------------------------
Expand Down
Loading