Skip to content

Commit

Permalink
Merge pull request #3200 from bsipocz/ENH_irsa_collection_kwarg
Browse files Browse the repository at this point in the history
ENH: IRSA: adding servicetype to list_collections
  • Loading branch information
bsipocz authored Feb 12, 2025
2 parents 1e8c4dd + 90a44d5 commit e58ae49
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ gaia

- Update DR4 retrieval_type names and include the new one EPOCH_ASTROMETRY_BRIGHT [#3207]

ipac.irsa
^^^^^^^^^

- Adding the "servicetype" kwarg to ``list_collections`` to be able to list SIA
and SSA collections separately. [#3200]

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

Expand Down
27 changes: 25 additions & 2 deletions astroquery/ipac/irsa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,39 @@ def query_sia(self, *, pos=None, band=None, time=None, pol=None,

query_sia.__doc__ = query_sia.__doc__.replace('_SIA2_PARAMETERS', SIA2_PARAMETERS_DESC)

def list_collections(self):
def list_collections(self, servicetype=None):
"""
Return information of available IRSA SIAv2 collections to be used in ``query_sia`` queries.
Parameters
----------
servicetype : str or None
Service type to list collections for. Returns all collections when not provided.
Currently supported service types are: 'SIA', 'SSA'.
Returns
-------
collections : A `~astropy.table.Table` object.
A table listing all the possible collections for IRSA SIA queries.
"""
query = "SELECT DISTINCT collection from caom.observation ORDER by collection"

if not servicetype:
query = "SELECT DISTINCT collection from caom.observation ORDER by collection"
else:
servicetype = servicetype.upper()
if servicetype == 'SIA':
query = ("SELECT DISTINCT o.collection FROM caom.observation o "
"JOIN caom.plane p ON o.obsid = p.obsid "
"WHERE (p.dataproducttype = 'image' OR p.dataproducttype = 'cube') "
"order by collection")
elif servicetype == 'SSA':
query = ("SELECT DISTINCT o.collection FROM caom.observation o "
"JOIN caom.plane p ON o.obsid = p.obsid "
"WHERE (p.dataproducttype = 'spectrum' OR p.dataproducttype = 'cube') "
"order by collection")
else:
raise ValueError("if specified, servicetype should be 'SIA' or 'SSA'")

collections = self.query_tap(query=query)
return collections.to_table()

Expand Down
17 changes: 11 additions & 6 deletions astroquery/ipac/irsa/tests/test_irsa_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,18 @@ def test_list_catalogs(self):
# (at the time of writing there are 933 tables in the list).
assert len(catalogs) > 900

def test_list_collections(self):
collections = Irsa.list_collections()
@pytest.mark.parametrize('servicetype', (None, 'sia', 'ssa'))
def test_list_collections(self, servicetype):
collections = Irsa.list_collections(servicetype=servicetype)
# Number of available collections may change over time, test only for significant drop.
# (at the time of writing there are 110 collections in the list).
assert len(collections) > 100
assert 'spitzer_seip' in collections['collection']
assert 'wise_allwise' in collections['collection']
# (at the time of writing there are 104 SIA and 35 SSA collections in the list).
if servicetype == 'ssa':
assert len(collections) > 30
assert 'sofia_exes' in collections['collection']
else:
assert len(collections) > 100
assert 'spitzer_seip' in collections['collection']
assert 'wise_allwise' in collections['collection']

def test_tap(self):
query = "SELECT TOP 5 ra,dec FROM cosmos2015"
Expand Down
8 changes: 5 additions & 3 deletions docs/ipac/irsa/irsa.rst
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,15 @@ Enhanced Imaging products in the centre of the COSMOS field as an `~astropy.tabl

To list available collections for SIA queries, the
`~astroquery.ipac.irsa.IrsaClass.list_collections` method is provided, and
will return a `~astropy.table.Table`:
will return a `~astropy.table.Table`. You can use the ``servicetype``
argument to filter for image or spectral collections using ``'SIA'`` or
``'SSA'`` respectively:

.. doctest-remote-data::

>>> from astroquery.ipac.irsa import Irsa
>>> Irsa.list_collections()
<Table length=124>
>>> Irsa.list_collections(servicetype='SIA')
<Table length=104>
collection
object
---------------------
Expand Down

0 comments on commit e58ae49

Please sign in to comment.