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, includung 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 HIRES instrument; 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 sys
import os
import time
sql = "select koaid, filehand from koa_hires where koaid like '%20040824%' "
job = koa.submit_job(sql)
print('url: ', job.url)
print('job_id: ', job.job_id)
print('phase: ', job.phase)
job.run()
while job.phase == 'EXECUTING':
time.sleep(2)
print('phase: ', job.phase)
resultsAS = job.fetch_result()
print(resultsAS)
# write output file
table=resultsAS.to_table()
table.write ('./table_select_AS20040824.vot',format='votable',overwrite=True)
# IPAC ASCII
table=resultsAS.to_table()
table.write ('./table_ipacasciiAS_20040824.tbl',format='ascii.ipac', \
overwrite=True)
# CSV
table_csv=resultsAS.to_table()
table.write ('./table_csvAS_20040824.csv',format='csv',overwrite=True)
sql = "select * from koa_hires where koaid like '%20040824%' "
job = koa.submit_job(sql)
print('url: ', job.url)
print('job_id: ', job.job_id)
print('phase: ', job.phase)
job.run()
while job.phase == 'EXECUTING':
time.sleep(2)
print('phase: ', job.phase)
resultsALL= job.fetch_result()
print(resultsALL)
# write output file in VTtable format
table_selectall=resultsALL.to_table()
table_selectall.write ('./table_select_asynchALL.vot', \
format='votable',overwrite=True)
sql = "select koaid, filehand, sig2nois from koa_hires \
where koaid like '%20040824%'order by sig2nois"
job = koa.submit_job(sql)
print('url: ', job.url)
print('job_id: ', job.job_id)
print('phase: ', job.phase)
job.run()
while job.phase == 'EXECUTING':
time.sleep(2)
print('phase: ', job.phase)
resultsASK = job.fetch_result()
print(resultsASK)
## write output file
table=resultsASK.to_table()
table.write ('./table_asynch_orderbysig2nois.vot',format='votable',overwrite=True)
sql = "select koaid, filehand, frameno from koa_hires where koaid like '%20040824%'"
job = koa.submit_job(sql,maxrec=20)
print('url: ', job.url)
print('job_id: ', job.job_id)
print('phase: ', job.phase)
job.run()
while job.phase == 'EXECUTING':
time.sleep(2)
print('phase: ', job.phase)
resultsASK20 = job.fetch_result( )
print(resultsASK20)
## write output file
table=resultsASK20.to_table()
table.write ('./table_asynch_max20.vot',format='votable',overwrite=True)
sql="select koaid, filehand from koa_hires \
where (utdatetime >= to_date('2009-01-01 00:00:00', 'yyyy-mm-dd HH24:MI:SS') \
and utdatetime <= to_date('2009-01-05 23:59:59', 'yyyy-mm-dd HH24:MI:SS'))"
job = koa.submit_job(sql)
print('url: ', job.url)
print('job_id: ', job.job_id)
print('phase: ', job.phase)
job.run()
while job.phase == 'EXECUTING':
time.sleep(2)
print('phase: ', job.phase)
resultsDATERANGE = job.fetch_result()
print(resultsDATERANGE)
## write to output file
table=resultsDATERANGE.to_table()
table.write ('./table_asynch_daterange.vot',format='votable',overwrite=True)
sql=("select koaid, filehand, progid, iodin, koaimtyp from \
koa_hires where (progid = 'C307')")
job = koa.submit_job(sql)
print('url: ', job.url)
print('job_id: ', job.job_id)
print('phase: ', job.phase)
job.run()
while job.phase == 'EXECUTING':
time.sleep(2)
print('phase: ', job.phase)
resultsPROGID= job.fetch_result( )
print(resultsPROGID)
## write to output file
table_progID_C307=resultsPROGID.to_table()
table.write ('./table_progID_C307.vot',format='votable',overwrite=True)
sql=("select koaid, filehand, ra, dec from koa_hires \
where contains(point('icrs', ra, dec), circle('icrs',262.0,17.0,1.0)) = 1")
job = koa.submit_job(sql)
print('url: ', job.url)
print('job_id: ', job.job_id)
print('phase: ', job.phase)
job.run()
while job.phase == 'EXECUTING':
time.sleep(2)
print('phase: ', job.phase)
resultsSPA= job.fetch_result( )
print(resultsSPA)
# write to output file
table=resultsSPA.to_table()
table.write ('./table_asynch_spatial_cone.vot',format='votable',overwrite=True)
sql=("select koaid, filehand, ra, dec from koa_hires where \
contains(point('icrs', ra, dec), \
box('icrs',262.0,17.0,2.0,120)) = 1")
job = koa.submit_job(sql)
print('url: ', job.url)
print('job_id: ', job.job_id)
print('phase: ', job.phase)
job.run()
while job.phase == 'EXECUTING':
time.sleep(2)
print('phase: ', job.phase)
resultsSPA_BOX= job.fetch_result( )
print(resultsSPA_BOX)
## write to output file
table=resultsSPA_BOX.to_table()
table.write ('./table_spatial_Box.vot',format='votable',overwrite=True)
sql=("select koaid, filehand, ra, dec from koa_hires where \
contains(point('icrs', ra, dec), \
polygon('icrs',209.80225,53.34894,209.80225,55.34894,211.80225,54.34894)) = 1")
job = koa.submit_job(sql)
print('url: ', job.url)
print('job_id: ', job.job_id)
print('phase: ', job.phase)
job.run()
while job.phase == 'EXECUTING':
time.sleep(2)
print('phase: ', job.phase)
resultsSPA_POLY= job.fetch_result( )
print(resultsSPA_POLY)
## write to output file
table=resultsSPA_POLY.to_table()
table.write ('./table_spatial_P.vot',format='votable',overwrite=True)
sql=("select count(*) from koa_hires where \
(utdatetime >= to_date('2009-01-01 00:00:00', 'yyyy-mm-dd HH24:MI:SS') \
and utdatetime <= to_date('2009-01-05 23:59:59', 'yyyy-mm-dd HH24:MI:SS'))")
job = koa.submit_job(sql)
print('url: ', job.url)
print('job_id: ', job.job_id)
print('phase: ', job.phase)
job.run()
while job.phase == 'EXECUTING':
time.sleep(2)
print('phase: ', job.phase)
results_count= job.fetch_result( )
print(results_count)
sql="select count(*) as total from koa_hires"
job = koa.submit_job(sql)
print('url: ', job.url)
print('job_id: ', job.job_id)
print('phase: ', job.phase)
job.run()
while job.phase == 'EXECUTING':
time.sleep(2)
print('phase: ', job.phase)
results_count= job.fetch_result( )
print(results_count)
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