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 asynchronous TAP-based queries for public raw science and calibation data acquired with the KCWI integral field 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
sql = "select koaid, filehand from koa_kcwi where koaid like '%20190509%'"
results= koa.run_async(sql)
print(results)
# write results to VOTable format
table=results.to_table()
table.write ('./table_ipacascii.vot',format='ascii.ipac',overwrite=True)
# write results to an IPAC ASCII table
sql = "select koaid, filehand from koa_kcwi where koaid like '%20190509%' "
results = koa.run_async(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_kcwi where koaid like '%20190509%' "
results = koa.run_async(sql)
table=results.to_table()
table.write ('./table_csv.csv',format='csv', overwrite=True)
sql = "select * from koa_kcwi where koaid like '%20190509%' "
results = koa.run_async(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_kcwi where koaid like '%20190509%'"
results = koa.run_async(sql)
print (results)
table = results.to_table()
table.write('./select_columns.vot',format='ascii.ipac',overwrite=True)
sql="select koaid, filehand, frameno from koa_kcwi \
where koaid like '%20190509%'"
results = koa.run_async(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_kcwi \
where (utdatetime >= to_date('2019-05-09 03:00:00', \
'yyyy-mm-dd HH24:MI:SS') and \
utdatetime <= to_date('2019-05-09 03:30:00', 'yyyy-mm-dd HH24:MI:SS'))"
results = koa.run_async(sql)
print (results)
table_daterange=results.to_table()
table.write ('./table_daterange.vot',format='votable',overwrite=True)
sql= ("select koaid, filehand, progid \
from koa_kcwi where (progid = 'U216') ")
results = koa.run_async(sql)
print (results)
table_progid=results.to_table()
table.write ('./progid.vot',format='votable',overwrite=True)
sql=("select koaid, filehand, ra, dec from koa_kcwi where \
contains(point('icrs', ra, dec), \
circle('icrs', 23.48 ,30.60 1.0)) = 1")
results = koa.run_async(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_kcwi where \
contains(point('icrs', ra, dec), \
box('icrs',23.48 ,30.60,1.0,120)) = 1")
results = koa.run_async(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_kcwi where \
contains(point('icrs', ra, dec), \
polygon('icrs',160.0, 43.2, 160.0, 43.0, 159.8, 43.0, 159.8, 43.2))) = 1")
results = koa.run_async(sql)
print(results)
table_spatial_P=results.to_table()
table.write ('./table_spatial_P.tbl',format='votable',overwrite=True)
sql=("select count(*) as count from koa_kcwi where \
date_obs=to_date('2019-05-09', 'YYYY-MM-DD')")
results = koa.run_async(sql)
print(results)
sql="select count(*) as total from koa_kcwi"
results = koa.run_async(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