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: IRSA: adding servicetype to list_collections #3200

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ simbad
Service fixes and enhancements
------------------------------

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 @@

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"

Check warning on line 136 in astroquery/ipac/irsa/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/ipac/irsa/core.py#L135-L136

Added lines #L135 - L136 were not covered by tests
else:
servicetype = servicetype.upper()
if servicetype == 'SIA':
query = ("SELECT DISTINCT o.collection FROM caom.observation o "

Check warning on line 140 in astroquery/ipac/irsa/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/ipac/irsa/core.py#L138-L140

Added lines #L138 - L140 were not covered by tests
"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 "

Check warning on line 145 in astroquery/ipac/irsa/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/ipac/irsa/core.py#L144-L145

Added lines #L144 - L145 were not covered by tests
"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'")

Check warning on line 150 in astroquery/ipac/irsa/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/ipac/irsa/core.py#L150

Added line #L150 was not covered by tests

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
Loading