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 Echellette Spectrograph and Imager (ESI); 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_esi where koaid like '%20150902%' "
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_AStime.vot',format='votable',overwrite=True)
# IPAC ASCII
table=resultsAS.to_table()
table.write ('./table_ipacasciiAS_time.tbl',format='ascii.ipac', \
overwrite=True)
# CSV
table_csv=resultsAS.to_table()
table.write ('./table_csvAS_time.csv',format='csv',overwrite=True)
sql = "select * from koa_esi where koaid like '%20150902%' "
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 from koa_esi where koaid like '%20150902%' "
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_cols.vot',format='votable',overwrite=True)
sql = "select koaid, filehand, frameno from koa_esi where koaid like '%20150902%'"
job = koa.submit_job(sql,maxrec=10)
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)
resultsASK10 = job.fetch_result( )
print(resultsASK10)
## write output file
table=resultsASK10.to_table()
table.write ('./table_asynch_max10.vot',format='votable',overwrite=True)
sql="select koaid, filehand from koa_esi \
where (utdatetime >= to_date('2015-09-01 00:00:00', 'yyyy-mm-dd HH24:MI:SS') \
and utdatetime <= to_date('2015-09-30 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 from \
koa_esi where (progid = 'K197E')")
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=resultsPROGID.to_table()
table.write ('./table_progID.vot',format='votable',overwrite=True)
sql=("select koaid, filehand, ra, dec from koa_esi \
where contains(point('icrs', ra, dec), circle('icrs',255.03913 -11.82214 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_esi where \
contains(point('icrs', ra, dec), \
box('icrs',23.48, 30.60,1.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_esi 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_esi where \
(utdatetime >= to_date('2015-09-01 00:00:00', 'yyyy-mm-dd HH24:MI:SS') and \
utdatetime <= to_date('2015-09-30 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_esi"
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