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 ssynchronous TAP-based queries for public raw science and calibation data acquired with the Keck Planet Finder (KPF) these data are hosted at the Keck Observatory Archive (KOA; https://koa.ipac.caltech.edu).
KPF entered shared-risk usage at the W. M. Keck Observatory in February 2023. Calibration data are immediately made public, and are accessible anonymously through PyKOA. Science data are protected and accessible only by PIs until August 202
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 later), 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_kpf where koaid like '%20230203%'"
results= koa.run_sync(sql)
print(results)
# write results to VOTable format
table=results.to_table()
table.write ('./table_ipacascii.vot',format='ascii.ipac',overwrite=True)
<Table length=176> koaid filehand object object ------------------------- ------------------------------------------------- KP.20230203.04645.81.fits /KPF/2023/20230203/lev0/KP.20230203.04645.81.fits KP.20230203.04707.10.fits /KPF/2023/20230203/lev0/KP.20230203.04707.10.fits KP.20230203.04768.58.fits /KPF/2023/20230203/lev0/KP.20230203.04768.58.fits KP.20230203.04829.85.fits /KPF/2023/20230203/lev0/KP.20230203.04829.85.fits KP.20230203.04891.27.fits /KPF/2023/20230203/lev0/KP.20230203.04891.27.fits KP.20230203.04952.81.fits /KPF/2023/20230203/lev0/KP.20230203.04952.81.fits KP.20230203.05013.97.fits /KPF/2023/20230203/lev0/KP.20230203.05013.97.fits KP.20230203.05075.24.fits /KPF/2023/20230203/lev0/KP.20230203.05075.24.fits KP.20230203.05136.75.fits /KPF/2023/20230203/lev0/KP.20230203.05136.75.fits KP.20230203.05198.15.fits /KPF/2023/20230203/lev0/KP.20230203.05198.15.fits ... ... KP.20230203.71589.50.fits /KPF/2023/20230203/lev0/KP.20230203.71589.50.fits KP.20230203.71687.88.fits /KPF/2023/20230203/lev0/KP.20230203.71687.88.fits KP.20230203.71950.07.fits /KPF/2023/20230203/lev0/KP.20230203.71950.07.fits KP.20230203.72212.26.fits /KPF/2023/20230203/lev0/KP.20230203.72212.26.fits KP.20230203.74273.23.fits /KPF/2023/20230203/lev0/KP.20230203.74273.23.fits KP.20230203.74342.62.fits /KPF/2023/20230203/lev0/KP.20230203.74342.62.fits KP.20230203.74412.34.fits /KPF/2023/20230203/lev0/KP.20230203.74412.34.fits KP.20230203.74611.03.fits /KPF/2023/20230203/lev0/KP.20230203.74611.03.fits KP.20230203.74681.56.fits /KPF/2023/20230203/lev0/KP.20230203.74681.56.fits KP.20230203.74752.55.fits /KPF/2023/20230203/lev0/KP.20230203.74752.55.fits
# write results to an IPAC ASCII table
sql = "select koaid, filehand from koa_kpf where koaid like '%20230203%' "
results = koa.run_sync(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_kpf where koaid like '%20230203%' "
results = koa.run_sync(sql)
table=results.to_table()
table.write ('./table_csv.csv',format='csv', overwrite=True)
sql = "select * from koa_kpf where koaid like '%20230203%' "
results = koa.run_sync(sql)
print (results)
## write to an output file
table_selectall=results.to_table()
table_selectall.write ('./table_selectall.vot',format='votable',overwrite=True)
<Table length=176> koaid propint koaimtyp ... y z spt_ind ... object int32 object ... float64 float64 int32 ------------------------- ------- -------- ... --------- -------- --------- KP.20230203.04645.81.fits 0 bias ... -0.358368 0.000675 200020012 KP.20230203.04707.10.fits 0 bias ... -0.358368 0.000675 200020012 KP.20230203.04768.58.fits 0 bias ... -0.358368 0.000675 200020012 KP.20230203.04829.85.fits 0 bias ... -0.358368 0.000675 200020012 KP.20230203.04891.27.fits 0 bias ... -0.358368 0.000675 200020012 KP.20230203.04952.81.fits 0 bias ... -0.358368 0.000675 200020012 KP.20230203.05013.97.fits 0 bias ... -0.358368 0.000675 200020012 KP.20230203.05075.24.fits 0 bias ... -0.358368 0.000675 200020012 KP.20230203.05136.75.fits 0 bias ... -0.358368 0.000675 200020012 ... ... ... ... ... ... ... KP.20230203.71589.50.fits 0 arclamp ... -0.358368 0.000675 200020012 KP.20230203.71687.88.fits 0 arclamp ... -0.358368 0.000675 200020012 KP.20230203.71950.07.fits 0 arclamp ... -0.358368 0.000675 200020012 KP.20230203.72212.26.fits 0 arclamp ... -0.358368 0.000675 200020012 KP.20230203.74273.23.fits 0 flatlamp ... -0.358368 0.000675 200020012 KP.20230203.74342.62.fits 0 flatlamp ... -0.358368 0.000675 200020012 KP.20230203.74412.34.fits 0 flatlamp ... -0.358368 0.000675 200020012 KP.20230203.74611.03.fits 0 arclamp ... -0.358368 0.000675 200020012 KP.20230203.74681.56.fits 0 arclamp ... -0.358368 0.000675 200020012 KP.20230203.74752.55.fits 0 arclamp ... -0.358368 0.000675 200020012
WARNING: W50: ?:?:?: W50: Invalid unit string 'pixels' [astropy.io.votable.tree] WARNING: W50: ?:?:?: W50: Invalid unit string 'arcseconds' [astropy.io.votable.tree] WARNING: W50: ?:?:?: W50: Invalid unit string 'degrees' [astropy.io.votable.tree] WARNING: W50: ?:?:?: W50: Invalid unit string 'e/Dn' [astropy.io.votable.tree] WARNING: W50: ?:?:?: W50: Invalid unit string 'arcseconds/s' [astropy.io.votable.tree] WARNING: W50: ?:?:?: W50: Invalid unit string 'Celsius' [astropy.io.votable.tree]
sql = "select koaid, filehand, imtype from koa_kpf where koaid like '%20230203%'"
results = koa.run_sync(sql)
print (results)
table = results.to_table()
table.write('./select_columns.vot',format='ascii.ipac',overwrite=True)
<Table length=176> koaid ... imtype object ... object ------------------------- ... -------- KP.20230203.04645.81.fits ... Bias KP.20230203.04707.10.fits ... Bias KP.20230203.04768.58.fits ... Bias KP.20230203.04829.85.fits ... Bias KP.20230203.04891.27.fits ... Bias KP.20230203.04952.81.fits ... Bias KP.20230203.05013.97.fits ... Bias KP.20230203.05075.24.fits ... Bias KP.20230203.05136.75.fits ... Bias KP.20230203.05198.15.fits ... Bias ... ... ... KP.20230203.71589.50.fits ... Arclamp KP.20230203.71687.88.fits ... Arclamp KP.20230203.71950.07.fits ... Arclamp KP.20230203.72212.26.fits ... Arclamp KP.20230203.74273.23.fits ... Flatlamp KP.20230203.74342.62.fits ... Flatlamp KP.20230203.74412.34.fits ... Flatlamp KP.20230203.74611.03.fits ... Arclamp KP.20230203.74681.56.fits ... Arclamp KP.20230203.74752.55.fits ... Arclamp
sql="select koaid, filehand, frameno from koa_kpf \
where koaid like '%20230203%'"
results = koa.run_sync(sql, maxrec=5)
print (results)
table = results.to_table()
table.write('./select_maxrec.tbl',format='ascii.ipac',overwrite=True)
<Table length=5> koaid ... frameno object ... int32 ------------------------- ... ------- KP.20230203.04645.81.fits ... 29404 KP.20230203.04707.10.fits ... 29405 KP.20230203.04768.58.fits ... 29406 KP.20230203.04829.85.fits ... 29407 KP.20230203.04891.27.fits ... 29408
sql="select koaid, filehand from koa_kpf \
where (utdatetime >= to_date('2023-02-03 00:00:00', \
'yyyy-mm-dd HH24:MI:SS') and \
utdatetime <= to_date('2023-02-04 23:59:59', 'yyyy-mm-dd HH24:MI:SS'))"
results = koa.run_sync(sql)
print (results)
table_daterange=results.to_table()
table.write ('./table_daterange.vot',format='votable',overwrite=True)
<Table length=355> koaid filehand object object ------------------------- ------------------------------------------------- KP.20230203.04645.81.fits /KPF/2023/20230203/lev0/KP.20230203.04645.81.fits KP.20230203.04707.10.fits /KPF/2023/20230203/lev0/KP.20230203.04707.10.fits KP.20230203.04768.58.fits /KPF/2023/20230203/lev0/KP.20230203.04768.58.fits KP.20230203.04829.85.fits /KPF/2023/20230203/lev0/KP.20230203.04829.85.fits KP.20230203.04891.27.fits /KPF/2023/20230203/lev0/KP.20230203.04891.27.fits KP.20230203.04952.81.fits /KPF/2023/20230203/lev0/KP.20230203.04952.81.fits KP.20230203.05013.97.fits /KPF/2023/20230203/lev0/KP.20230203.05013.97.fits KP.20230203.05075.24.fits /KPF/2023/20230203/lev0/KP.20230203.05075.24.fits KP.20230203.05136.75.fits /KPF/2023/20230203/lev0/KP.20230203.05136.75.fits KP.20230203.05198.15.fits /KPF/2023/20230203/lev0/KP.20230203.05198.15.fits ... ... KP.20230204.71583.28.fits /KPF/2023/20230204/lev0/KP.20230204.71583.28.fits KP.20230204.71680.83.fits /KPF/2023/20230204/lev0/KP.20230204.71680.83.fits KP.20230204.71942.91.fits /KPF/2023/20230204/lev0/KP.20230204.71942.91.fits KP.20230204.72205.05.fits /KPF/2023/20230204/lev0/KP.20230204.72205.05.fits KP.20230204.74268.25.fits /KPF/2023/20230204/lev0/KP.20230204.74268.25.fits KP.20230204.74338.59.fits /KPF/2023/20230204/lev0/KP.20230204.74338.59.fits KP.20230204.74408.86.fits /KPF/2023/20230204/lev0/KP.20230204.74408.86.fits KP.20230204.74551.83.fits /KPF/2023/20230204/lev0/KP.20230204.74551.83.fits KP.20230204.74621.89.fits /KPF/2023/20230204/lev0/KP.20230204.74621.89.fits KP.20230204.74690.44.fits /KPF/2023/20230204/lev0/KP.20230204.74690.44.fits
sql= ("select koaid, filehand, imtype, ha, az \
from koa_kpf where (progid = 'ENG') ")
results = koa.run_sync(sql)
print (results)
table_progid=results.to_table()
table.write ('./progid.vot',format='votable',overwrite=True)
<Table length=36743> koaid ... az ... degrees object ... float64 ------------------------- ... ------- KP.20230111.77177.87.fits ... -74.22 KP.20230111.77910.84.fits ... -124.35 KP.20230111.76444.02.fits ... -20.0 KP.20230111.78033.13.fits ... -124.35 KP.20230111.77544.02.fits ... -124.35 KP.20230111.77666.50.fits ... -124.35 KP.20230111.77788.75.fits ... -124.35 KP.20230111.78155.23.fits ... -124.35 KP.20230111.77300.07.fits ... -119.51 ... ... ... KP.20230619.63712.69.fits ... -112.66 KP.20230619.63784.66.fits ... -112.66 KP.20230619.63928.29.fits ... -112.66 KP.20230618.84870.52.fits ... 233.0 KP.20230618.81560.93.fits ... 233.0 KP.20230618.10511.01.fits ... 233.0 KP.20230619.02607.83.fits ... 233.0 KP.20230618.09865.08.fits ... 233.0 KP.20230618.06010.73.fits ... 233.0 KP.20230618.85422.24.fits ... 233.0
sql=("select count(*) from koa_kpf where \
(utdatetime >= to_date('2023-02-03 00:00:00', 'yyyy-mm-dd HH24:MI:SS') and \
utdatetime <= to_date('2023-02-04 23:59:59', 'yyyy-mm-dd HH24:MI:SS'))" )
results = koa.run_sync(sql)
print(results)
<Table length=1> count(*) int32 -------- 355
sql="select count(*) as total from koa_kpf"
results = koa.run_sync(sql)
print(results)
<Table length=1> total int32 ----- 36769
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