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 Near-Infrared Echellette Spectrometer (NIRES); 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_nires where koaid like '%20181218%'"
results= koa.run_async(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_nires where koaid like '%20181218%' "
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_nires where koaid like '%20181218%' "
results = koa.run_async(sql)
table=results.to_table()
table.write ('./table_csv.csv',format='csv', overwrite=True)
sql = "select * from koa_nires where koaid like '%20181218%' "
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_nires where koaid like '%20181218%'"
results = koa.run_async(sql)
print (results)
table = results.to_table()
table.write('./select_columns.tbl',format='ascii.ipac',overwrite=True)
sql="select koaid, filehand, frameno from koa_nires \
where koaid like '%20181218%'"
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_nires \
where (utdatetime >= to_date('2018-12-18 15:00:00', \
'yyyy-mm-dd HH24:MI:SS') and \
utdatetime <= to_date('2018-12-18 15: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_nires where (progid = 'Y025') ")
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_nires where \
contains(point('icrs', ra, dec), \
circle('icrs', 194.25 22.03, 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_nires where \
contains(point('icrs', ra, dec), \
box('icrs',194.25 22.03,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_nires where \
contains(point('icrs', ra, dec), \
polygon('icrs',209.80225,53.34894,209.80225,55.34894,211.80225,54.34894)) = 1")
results = koa.run_async(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_nires where \
date_obs=to_date('2018-12-18', 'YYYY-MM-DD')")
results = koa.run_async(sql)
print(results)
sql="select count(*) as total from koa_nires"
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