Skip to content

Commit 55f6459

Browse files
authored
Merge pull request #3264 from bsipocz/ENH_irsa_filter_lists
ENH: adding ``filter`` to IRSA's list_collections and list_catalogs
2 parents 2b259cb + 1212344 commit 55f6459

File tree

4 files changed

+76
-42
lines changed

4 files changed

+76
-42
lines changed

CHANGES.rst

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

51+
- Addding "filter" kwarg to ``list_collections`` and ``list_catalogs`` to
52+
filter out collections/catalogs with names containing the filter string. [#3264]
53+
5154
- Adding support for asynchronous queries using the new ``async_job``
5255
keyword. [#3201]
5356

astroquery/ipac/irsa/core.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def query_ssa(self, *, pos=None, radius=None, band=None, time=None, collection=N
165165
format='all', collection=collection)
166166
return results.to_table()
167167

168-
def list_collections(self, servicetype=None):
168+
def list_collections(self, *, servicetype=None, filter=None):
169169
"""
170170
Return information of available IRSA SIAv2 collections to be used in ``query_sia`` queries.
171171
@@ -174,6 +174,9 @@ def list_collections(self, servicetype=None):
174174
servicetype : str or None
175175
Service type to list collections for. Returns all collections when not provided.
176176
Currently supported service types are: 'SIA', 'SSA'.
177+
filter : str or None
178+
If specified we only return collections then their collection_name
179+
contains the filter string.
177180
178181
Returns
179182
-------
@@ -198,8 +201,12 @@ def list_collections(self, servicetype=None):
198201
else:
199202
raise ValueError("if specified, servicetype should be 'SIA' or 'SSA'")
200203

201-
collections = self.query_tap(query=query)
202-
return collections.to_table()
204+
collections = self.query_tap(query=query).to_table()
205+
206+
if filter:
207+
mask = [filter in collection for collection in collections['collection']]
208+
collections = collections[mask]
209+
return collections
203210

204211
@deprecated_renamed_argument(("selcols", "cache", "verbose"), ("columns", None, None), since="0.4.7")
205212
def query_region(self, coordinates=None, *, catalog=None, spatial='Cone',
@@ -297,7 +304,7 @@ def query_region(self, coordinates=None, *, catalog=None, spatial='Cone',
297304
return response.to_table()
298305

299306
@deprecated_renamed_argument("cache", None, since="0.4.7")
300-
def list_catalogs(self, full=False, cache=False):
307+
def list_catalogs(self, *, full=False, filter=None, cache=False):
301308
"""
302309
Return information of available IRSA catalogs.
303310
@@ -306,8 +313,15 @@ def list_catalogs(self, full=False, cache=False):
306313
full : bool
307314
If True returns the full schema as a `~astropy.table.Table`.
308315
If False returns a dictionary of the table names and their description.
316+
filter : str or None
317+
If specified we only return catalogs when their catalog_name
318+
contains the filter string.
309319
"""
310-
tap_tables = Irsa.query_tap("SELECT * FROM TAP_SCHEMA.tables").to_table()
320+
tap_tables = self.query_tap("SELECT * FROM TAP_SCHEMA.tables").to_table()
321+
322+
if filter:
323+
mask = [filter in name for name in tap_tables['table_name']]
324+
tap_tables = tap_tables[mask]
311325

312326
if full:
313327
return tap_tables

astroquery/ipac/irsa/tests/test_irsa_remote.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,19 @@ def test_list_catalogs(self):
6666
# Number of available catalogs may change over time, test only for significant drop.
6767
# (at the time of writing there are 933 tables in the list).
6868
assert len(catalogs) > 900
69+
assert isinstance(catalogs, dict)
70+
71+
def test_list_catalogs_filter(self):
72+
spitzer_catalogs = Irsa.list_catalogs(filter='spitzer')
73+
74+
assert len(spitzer_catalogs) == 142
6975

7076
@pytest.mark.parametrize('servicetype', (None, 'sia', 'ssa'))
7177
def test_list_collections(self, servicetype):
7278
collections = Irsa.list_collections(servicetype=servicetype)
7379
# Number of available collections may change over time, test only for significant drop.
7480
# (at the time of writing there are 104 SIA and 35 SSA collections in the list).
81+
assert isinstance(collections, Table)
7582
if servicetype == 'ssa':
7683
assert len(collections) > 30
7784
assert 'sofia_exes' in collections['collection']
@@ -80,6 +87,11 @@ def test_list_collections(self, servicetype):
8087
assert 'spitzer_seip' in collections['collection']
8188
assert 'wise_allwise' in collections['collection']
8289

90+
def test_list_collections_filter(self):
91+
spitzer_collections = Irsa.list_collections(filter='spitzer')
92+
93+
assert len(spitzer_collections) == 47
94+
8395
def test_tap(self):
8496
query = "SELECT TOP 5 ra,dec FROM cosmos2015"
8597
with pytest.warns(expected_warning=DALOverflowWarning,

docs/ipac/irsa/irsa.rst

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,27 @@ Available IRSA catalogs
2525

2626
To get a concise list of IRSA catalogs available to query, use the
2727
`~.astroquery.ipac.irsa.IrsaClass.list_catalogs` method.
28-
The output consists of two fields for each catalog. To query a
28+
The output consists of two fields for each catalog, the name of the catalog
29+
and a very short description. To query a
2930
specific catalog, the first field can be entered as the value of the
3031
``catalog`` parameter in the `~.astroquery.ipac.irsa.IrsaClass.query_region` method.
32+
You can also use the ``filter`` argument to return only the catalogs with
33+
name matches to the specified string.
34+
3135

3236
.. doctest-remote-data::
3337

3438
>>> from astroquery.ipac.irsa import Irsa
35-
>>> Irsa.list_catalogs() # doctest: +IGNORE_OUTPUT
36-
{'a1763t2': 'Abell 1763 Source Catalog',
37-
'a1763t3': 'Abell 1763 MIPS 70 micron Catalog',
38-
'acs_iphot_sep07': 'COSMOS ACS I-band photometry catalog September 2007',
39-
'akari_fis': 'Akari/FIS Bright Source Catalogue',
40-
'akari_irc': 'Akari/IRC Point Source Catalogue',
41-
'astsight': 'IRAS Minor Planet Survey',
42-
...
39+
>>> Irsa.list_catalogs(filter='spitzer') # doctest: +IGNORE_OUTPUT
40+
{'spitzer.safires_images': 'Spitzer Archival FIR Extragalactic Survey (SAFIRES) Images',
41+
'spitzer.safires_science': 'Spitzer SAFIRES Science Image Metadata',
42+
'spitzer.safires_ancillary': 'Spitzer SAFIRES Ancillary Image Metadata',
43+
'spitzer.sage_images': 'SAGE Images',
44+
'spitzer.sage_mips_mos': 'Spitzer SAGE MIPS Mosaic Image Metadata',
4345
...
44-
'xmm_cat_s05': "SWIRE XMM_LSS Region Spring '05 Spitzer Catalog"}
46+
'spitzer.ssgss_irs_sl_ll': 'SSGSS IRS SL LL Spectra',
47+
'spitzer.swire_images': 'Spitzer Wide-area InfraRed Extragalactic Survey (SWIRE) Images',
48+
'herschel.hops_spitzer': 'HOPS Spitzer Metadata'}
4549

4650
To get a full list of information available for each available
4751
catalog, use the ``full`` keyword argument. The output consists of many columns for each catalog.
@@ -52,14 +56,16 @@ the `~astroquery.ipac.irsa.IrsaClass.query_region` method.
5256

5357
>>> from astroquery.ipac.irsa import Irsa
5458
>>> Irsa.list_catalogs(full=True) # doctest: +IGNORE_OUTPUT
55-
<DALResultsTable length=934>
56-
table_index schema_name table_name description ... irsa_access_flag irsa_nrows irsa_odbc_datasource irsa_spatial_idx_name
57-
int32 object object object ... int32 int64 object object
58-
----------- ----------- ---------------------------------- --------------------------------------------- ... ---------------- ---------- -------------------- ---------------------
59-
303 spitzer spitzer.m31irac_image M31IRAC Images ... 30 4 postgres
60-
304 spitzer mipslg MIPS Local Galaxies Catalog ... 30 240 spitzer SPT_IND_MIPSLG
61-
305 spitzer spitzer.mips_lg_images MIPS Local Galaxies Images ... 30 606 postgres
62-
...
59+
<Table length=951>
60+
table_index schema_name table_name ... irsa_nrows irsa_odbc_datasource irsa_spatial_idx_name
61+
int32 object object ... int64 object object
62+
----------- ----------- ---------------------------- ... ---------- -------------------- ---------------------
63+
101 wax cf_info ... 456480 wax SPTC01
64+
102 wax cf_link ... 204143440 wax
65+
103 twomass ext_src_c ... 403811 twomass EXT_SRC_CIX413
66+
104 wax ecf_info ... 2146 wax SPTETC01
67+
105 wax ecf_link ... 473971 wax
68+
...
6369

6470

6571
Spatial search types
@@ -286,29 +292,28 @@ To list available collections for SIA queries, the
286292
`~astroquery.ipac.irsa.IrsaClass.list_collections` method is provided, and
287293
will return a `~astropy.table.Table`. You can use the ``servicetype``
288294
argument to filter for image or spectral collections using ``'SIA'`` or
289-
``'SSA'`` respectively:
295+
``'SSA'`` respectively. You can also use the ``filter`` argument to show
296+
only the collections with the given filter strings in the collection names.
290297

291298
.. doctest-remote-data::
292299

293300
>>> from astroquery.ipac.irsa import Irsa
294-
>>> Irsa.list_collections(servicetype='SIA')
295-
<Table length=104>
296-
collection
297-
object
298-
---------------------
299-
akari_allskymaps
300-
blast
301-
bolocam_gps
302-
bolocam_lh
303-
bolocam_planck_sz
304-
...
305-
wise_allsky
306-
wise_allwise
307-
wise_fdepa
308-
wise_prelim
309-
wise_prelim_2bandcryo
310-
wise_unwise
311-
wise_z0mgs
301+
>>> Irsa.list_collections(servicetype='SIA', filter='spitzer')
302+
<Table length=38>
303+
collection
304+
object
305+
-------------------
306+
spitzer_abell1763
307+
spitzer_clash
308+
spitzer_cosmic_dawn
309+
spitzer_cygx
310+
spitzer_deepdrill
311+
...
312+
spitzer_spuds
313+
spitzer_srelics
314+
spitzer_ssdf
315+
spitzer_swire
316+
spitzer_taurus
312317

313318
Now open a cutout image for one of the science images. You could either use
314319
the the IRSA on-premise data or the cloud version of it using the

0 commit comments

Comments
 (0)