Skip to content

Commit fb9fef1

Browse files
authored
Merge pull request #3265 from bsipocz/ENH_irsa_list_columns
ENH: adding ``Irsa.list_columns``
2 parents 1a666c1 + d677fa1 commit fb9fef1

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ ipac.irsa
5858

5959
- Making ``'spatial'`` keyword in ``query_region`` case insensitive. [#3224]
6060

61+
- Adding new ``list_columns`` method to list available columns for a given
62+
catalog. [#3265]
63+
6164
ipac.nexsci.nasa_exoplanet_archive
6265
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6366

astroquery/ipac/irsa/core.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,5 +335,27 @@ def print_catalogs(self):
335335
for catname in catalogs:
336336
print("{:30s} {:s}".format(catname, catalogs[catname]))
337337

338+
def list_columns(self, catalog, *, full=False):
339+
"""
340+
Return list of columns of a given IRSA catalog.
341+
342+
Parameters
343+
----------
344+
catalog : str
345+
The name of the catalog.
346+
full : bool
347+
If True returns the full schema as a `~astropy.table.Table`.
348+
If False returns a dictionary of the column names and their description.
349+
"""
350+
351+
query = f"SELECT * from TAP_SCHEMA.columns where table_name='{catalog}'"
352+
353+
column_table = self.query_tap(query).to_table()
354+
355+
if full:
356+
return column_table
357+
else:
358+
return {column['column_name']: column['description'] for column in column_table}
359+
338360

339361
Irsa = IrsaClass()

astroquery/ipac/irsa/tests/test_irsa_remote.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ def test_query_region_polygon(self):
6161
assert isinstance(result, Table)
6262
assert len(result) == 7
6363

64+
def test_list_columns(self):
65+
columns = Irsa.list_columns('slphotdr4')
66+
assert len(columns) == 203
67+
assert isinstance(columns, dict)
68+
69+
full_columns = Irsa.list_columns('slphotdr4', full=True)
70+
assert isinstance(full_columns, Table)
71+
6472
def test_list_catalogs(self):
6573
catalogs = Irsa.list_catalogs()
6674
# Number of available catalogs may change over time, test only for significant drop.

docs/ipac/irsa/irsa.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,26 @@ star HIP 12 with just the ra, dec and w1mpro columns would be:
224224
--------- ----------- ------
225225
0.0407905 -35.9602605 4.837
226226

227+
228+
You can use the `~astroquery.ipac.irsa.IrsaClass.list_columns` method to
229+
list all available columns for a given catalog. This method behaves
230+
similarly to what we saw above with ``list_catalogs`` and either returns
231+
pairs of column names and column descriptions; or a full list of information
232+
available about the columns in a `~astropy.table.Table`.
233+
234+
.. doctest-remote-data::
235+
236+
>>> from astroquery.ipac.irsa import Irsa
237+
>>> Irsa.list_columns(catalog="allwise_p3as_psd")
238+
{'designation': 'WISE source designation',
239+
'ra': 'right ascension (J2000)',
240+
'dec': 'declination (J2000)',
241+
'sigra': 'uncertainty in RA',
242+
'sigdec': 'uncertainty in DEC',
243+
...
244+
'htm20': 'HTM20 spatial index key'}
245+
246+
227247
Async queries
228248
--------------
229249

0 commit comments

Comments
 (0)