The NASA Exoplanet Science Institute (NExScI) (visit https://nexsci.caltech.edu) has developed a Python-based server to implement an API that complies with the Virtual Observatory (VO) Table Access Protocol(TAP) version 1.1 (September 2019) (http://ivoa.net/documents/TAP/20190927/index.html), a standard recommended by the International Virtual Observatory alliance (IVOA) (http://ivoa.net).
The TAP API enables a rich variety of searches against tabular data, including cone, box or all-sky searches, temporal searches, combinations of spatial searches and temporal searches, searches against instrumental attributes and program attributes.
This tutorial supports demonstrates how to use the PyVO client to perform synchronous TAP-based queries for public raw science and calibation data acquired with the NIRSPEC cross-dispersed echelle spectrograph; these data are hosted at the Keck Observatory Archive (KOA; https://koa.ipac.caltech.edu).
This tutorial uses PyVO version 1.1.1, and can be installed from PyPI:
$ pip install --upgrade PyVO
The tutorial requires Python 3.6 (or above), plus the table read and write functions from Astropy. We have tested with Astropy 4.0.1, but any version should work. We recommend using the Ananconda Python distribution.
The number of records returned here may differ from those returned here because new data are released daily.
from pyvo.dal import tap
koa = tap.TAPService("https://koa.ipac.caltech.edu/TAP")
import time
import sys
import os
import time
import warnings
sql = "select koaid, filehand from koa_nirspec where koaid like '%20170605%'"
results= koa.run_sync(sql)
print(results)
# write results to VOTable format
table=results.to_table()
table.write ('./table_ipacascii.vot',format='votable',overwrite=True)
# write results to an IPAC ASCII table
sql = "select koaid, filehand from koa_nirspec where koaid like '%20170605%' "
results = koa.run_sync(sql)
table=results.to_table()
table.write ('./table_ipacascii.tbl',format='ascii.ipac',overwrite=True)
# write results to CSV file
sql = "select koaid, filehand from koa_nirspec where koaid like '%20170605%' "
results = koa.run_sync(sql)
table=results.to_table()
table.write ('./table_csv.csv',format='csv', overwrite=True)
sql = "select * from koa_nirspec where koaid like '%20170605%' "
results = koa.run_sync(sql)
print (results)
## write to an output file
table_selectall=results.to_table()
table_selectall.write ('./table_selectall.vot',format='votable',overwrite=True)
sql = "select koaid, filehand from koa_nirspec where koaid like '%20170605%'"
results = koa.run_sync(sql)
print (results)
table = results.to_table()
table.write('./select_columns.tbl',format='ascii.ipac',overwrite=True)
sql="select koaid, filehand, frameno from koa_nirspec \
where koaid like '%20170605%'"
results = koa.run_sync(sql, maxrec=20)
print (results)
table = results.to_table()
table.write('./select_maxrec.tbl',format='ascii.ipac',overwrite=True)
sql="select koaid, filehand from koa_nirspec \
where (utdatetime >= to_date('2017-06-05 13:00:00', \
'yyyy-mm-dd HH24:MI:SS') and \
utdatetime <= to_date('2017-06-05 14:00:00', 'yyyy-mm-dd HH24:MI:SS'))"
results = koa.run_sync(sql)
print (results)
table_daterange=results.to_table()
table.write ('./table_daterange.vot',format='votable',overwrite=True)
sql= ("select koaid, filehand, progid \
from koa_nirspec where (progid = 'K236') ")
results = koa.run_sync(sql)
print (results)
table_progid=results.to_table()
table.write ('./progid.vot',format='votable',overwrite=True)
sql=("select koaid, filehand, ra, dec from koa_nirspec where \
contains(point('J2000', ra, dec), \
circle('J2000', 277.93 -9.985, 0.5)) = 1")
results = koa.run_sync(sql)
print(results)
table_spatial_1=results.to_table()
table.write ('./table_spatial_1.vot',format='votable',overwrite=True)
sql=("select koaid, filehand, ra, dec from koa_nirspec where \
(contains(point('J2000',ra ,dec), box('J2000', 277.93 -9.985, 0.5, 0.5)) = 1)")
results = koa.run_sync(sql)
print (results)
table_spatial_box=results.to_table()
table.write('./table_spatial_box.vot',format='votable',overwrite=True)
sql=("select koaid, filehand, ra, dec from koa_nirspec where \
contains(point('icrs', ra, dec), \
polygon('icrs',277.43 -10.485 277.43 -9.485 278.43 -9.485 278.43 -10.485)) = 1")
results = koa.run_sync(sql)
print(results)
table_spatial_P=results.to_table()
table.write ('./table_spatial_P.vot',format='votable',overwrite=True)
sql=("select count(*) as count from koa_nirspec where \
date_obs=to_date('2017-06-05', 'YYYY-MM-DD')")
results = koa.run_sync(sql)
print(results)
sql="select count(*) as total from koa_nirspec"
results = koa.run_sync(sql)
print(results)
Visit KOA at https://koa.ipac.caltech.edu.
The Keck Observatory Archive (KOA) is a collaboration between the NASA Exoplanet Science Institute (NExScI) and the W. M. Keck Observatory (WMKO). NExScI is sponsored by NASA's Exoplanet Exploration Program, and operated by the California Institute of Technology in coordination with the Jet Propulsion Laboratory (JPL).
Need help? Submit your questions to the KOA Help Desk at https://koa.ipac.caltech.edu/cgi-bin/Helpdesk/nph-genTicketForm?projname=KOA