diff --git a/CHANGES.rst b/CHANGES.rst index 73bdabdaf2..fa180f8f02 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/astroquery/ipac/irsa/core.py b/astroquery/ipac/irsa/core.py index 1adf93437c..28523ba222 100644 --- a/astroquery/ipac/irsa/core.py +++ b/astroquery/ipac/irsa/core.py @@ -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 @@ -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 @@ -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, @@ -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. @@ -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 ------- @@ -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() diff --git a/docs/ipac/irsa/irsa.rst b/docs/ipac/irsa/irsa.rst index b6b103ffc6..61c2a74145 100644 --- a/docs/ipac/irsa/irsa.rst +++ b/docs/ipac/irsa/irsa.rst @@ -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 -----------------------------------