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 Low Resolution Imaging Spectrograph (LRIS), 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
warnings.simplefilter("ignore")
instrument = 'LRIS'
instr = 'lris'
koatable = 'koa_lris'
outdir = './outputLR/'
koaid_date = '20150123'
startdate = '2015-01-01 00:00:00'
enddate = '2015-03-01 23:59:59'
date='20150123'
program = 'C305'
circle_pos = '174.27 29.8 1.0'
box_pos = '174.27 29.8 1 1'
polygon_pos = '173.27 28.8 173.27 30.8 176.27 29.8 '
try:
os.mkdir(outdir)
except:
print(instrument + " Directory exists already", flush=True)
# write results to VOTable format
sql = "select koaid, filehand from " + koatable + " where koaid like '%" + koaid_date + "%'"
results = koa.run_sync(sql)
print(results)
table=results.to_table()
table.write (outdir + instr + "_table_ipacascii.vot",format='votable',overwrite=True)
# write results to an IPAC ASCII table
sql = "select koaid, filehand from " + koatable + " where koaid like '%" + koaid_date + "%' "
results = koa.run_sync(sql)
print(results)
table=results.to_table()
table.write (outdir + instr + "_table_ipacascii.tbl",format='ascii.ipac',overwrite=True)
# write results to CSV file
sql = "select koaid, filehand from " + koatable + " where koaid like '%" + koaid_date + "%' "
results = koa.run_sync(sql)
print(results)
table=results.to_table()
table.write (outdir + instr + "_table_csv.csv",format='csv', overwrite=True)
sql = "select * from " + koatable + " where koaid like '%" + koaid_date + "%' "
results = koa.run_sync(sql)
print (results)
table_selectall=results.to_table()
table_selectall.write (outdir + instr + "_table_selectall.vot",format='votable',overwrite=True)
sql = "select koaid, filehand from " + koatable + " where koaid like '%" + koaid_date + "%'"
results = koa.run_sync(sql)
print(results)
table = results.to_table()
table.write(outdir + instr + "_select_columns.tbl",format='ascii.ipac',overwrite=True)
sql = "select koaid, filehand, frameno from " + koatable + " where koaid like '%" + koaid_date + "%'"
results = koa.run_sync(sql, maxrec=20)
print (results)
table = results.to_table()
table.write(outdir + instr + "_select_maxrec.tbl",format='ascii.ipac',overwrite=True)
sql = "select koaid, filehand from " + koatable + " where (utdatetime >= to_date('" + startdate + "', 'yyyy-mm-dd HH24:MI:SS') and utdatetime <= to_date('" + enddate + "', 'yyyy-mm-dd HH24:MI:SS'))"
results = koa.run_sync(sql)
print (results)
table_daterange=results.to_table()
table.write (outdir + instr + "_table_daterange.vot",format='votable',overwrite=True)
sql= ("select koaid, filehand, progid from " + koatable + " where (progid = '" + program + "')")
results = koa.run_sync(sql)
print(results)
table_progid=results.to_table()
table.write (outdir + instr + "_progid.vot",format='votable',overwrite=True)
sql=("select koaid, filehand, ra, dec from " + koatable + " where contains(point('J2000', ra, dec), circle('J2000', " + circle_pos + ")) = 1")
results = koa.run_sync(sql)
print(results)
table_spatial_1=results.to_table()
table.write (outdir + instr + "_table_spatial_circle.vot",format='votable',overwrite=True)
sql=("select koaid, filehand, ra, dec from " + koatable + " where contains(point('J2000', ra, dec), box('J2000', " + box_pos + ")) = 1")
results = koa.run_sync(sql)
print(results)
table_spatial_1=results.to_table()
table.write (outdir + instr + "_table_spatial_box.vot",format='votable',overwrite=True)
sql=("select koaid, filehand, ra, dec from " + koatable + " where contains(point('icrs', ra, dec), polygon('J2000', " + polygon_pos + ")) = 1")
results = koa.run_sync(sql)
print(results)
table_spatial_1=results.to_table()
table.write (outdir + instr + "_table_spatial_polygon.vot",format='votable',overwrite=True)
sql=("select count(*) as count from " + koatable + " where date_obs=to_date('" + date + "', 'YYYY-MM-DD')")
results = koa.run_sync(sql)
print(results)
sql="select count(*) as total from " + koatable
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