PyKOA offers access to public raw science and calibration files acquired at the W. M. Keck Observatory Archive, and for Keck Observatory PIs, secure access to their protected data with the KOA credentials assigned to them. PyKOA also supports queries to the nexsciTAP Table Access Protocol (TAP) server https://github.com/Caltech-IPAC/nexsciTAP. The PyKOA client thus enables a rich variety of searches, including cone, box, polygon, or all-sky spatial searches; temporal searches; searches on program information; and complex searches on multiple attributes.
This Jupyter Notebook provides examples of how to discover and access raw science and calibration data acquired with the Near-Infrared Echellette Spectrometer (NIRES) with the methods supported by PyKOA, and examples of how Keck PIs may access their protected data.
PyKOA can be installed from PyPI:
$ pip install --upgrade pykoa
Requires Python 3.6 (or above), plus table read and write functions from Astropy. We have tested with Astropy 4.0.1. We recommend using the Anaconda Python distribution.
PyKOA supports methods for discovering and downloading public and private data archived at KOA. It writes the output metadata data to an output file, in the IPAC ASCII, VOTable, CSV or TSV data formats. A dedicated method enables downloads of data discovered through queries.
This tutorial illustrates methods for discovering and accessing public and private raw science and calibration files for HIRES:
The number of records returned by each query may differ from the number returned in this Notebook because new data are made public daily.
import sys
import io
import os
from pykoa.koa import Koa
from astropy.table import Table,Column
help(Koa)
try:
os.mkdir('./outputNI')
except:
print(" Directory exists already", flush=True)
Koa.query_date ('nires', \
'2018-12-18', \
'./outputNI/NIRES_date.tbl', overwrite=True, format='ipac')
rec = Table.read ('./outputNI/NIRES_date.tbl',format='ipac')
print (rec)
Koa.query_date ('nires', \
'2018-12-18/2018-12-19', \
'./outputNI/nires_daterange.vot', overwrite=True, format='votable')
rec = Table.read ('./outputNI/nires_daterange.vot',format='votable')
print (rec)
Koa.query_datetime ('nires', \
'2018-12-18 15:00:00/2018-12-18 15:30:00', \
'./outputNI/nires_datetime.csv', overwrite=True, format='csv' )
rec = Table.read ('./outputNI/nires_datetime.csv',format='csv')
print (rec)
Koa.query_date ('nires', \
'2018-12-19', \
'./outputNI/nires_date.tsv', overwrite=True, format='tsv' )
rec = Table.read ('./outputNI/nires_date.tsv',format='ascii.fast_tab')
print (rec)
Koa.query_position ('nires', \
'circle 194.25 22.03 0.5', \
'./outputNI/position_search.tbl', overwrite=True )
rec = Table.read ('./outputNI/position_search.tbl', format='ascii.ipac' )
print (rec)
Koa.query_object ('nires', \
'GD153', './outputNI/GD153.tbl', overwrite=True, format='ipac')
rec = Table.read ('./outputNI/GD153.tbl', format='ascii.ipac')
print (rec)
query ="select koaid, filehand, progid from koa_nires where (progid = 'Y025') "
Koa.query_adql (query, \
'./outputNI/program_info.tbl', overwrite=True, format='ipac' )
rec = Table.read('./outputNI/program_info.tbl', format='ascii.ipac')
print (rec)
param = dict()
param['instrument'] = 'nires'
param['date'] = '2018-12-18'
param['target'] = 'HP37074'
Koa.query_criteria (param, \
'./outputNI/parameters.tbl', overwrite=True )
rec = Table.read('./outputNI/parameters.tbl', format='ipac')
print (rec)
query = "select koaid, object, koaimtyp, frameno, ra, dec, \
to_char(date_obs,'YYYY-MM-DD') as date_obs, elaptime, \
waveblue, wavered, airmass, filter, instr, slitlen, slitwidt, spatscal, \
progid, proginst, progpi, progtitl, semester, ofname, filehand \
from koa_nires \
where (contains(point('J2000',ra ,dec), circle('J2000', 194.25 22.03, 1))=1) \
order by utdatetime"
Koa.query_adql(query,'./outputNI/adql_cone.tbl', overwrite=True, format='ipac' )
rec = Table.read ('./outputNI/adql_cone.tbl', format='ascii.ipac')
print (rec)
query = "select koaid from koa_nires where \
(contains(point('J2000',ra ,dec), box('J2000', 194.25 22.03, 1, 2))=1) "
Koa.query_adql (query, './outputNI/adql_radec.tbl',overwrite=True, \
format='ipac' )
rec = Table.read ('./outputNI/adql_radec.tbl', format='ascii.ipac')
print (rec)
query = "select top 10 koaid, ra ,dec, utdatetime from koa_nires \
where (contains(point('J2000',ra ,dec), \
box('J2000', 194.25 22.03, 2, 2))) =1) order by utdatetime desc "
Koa.query_adql (query, \
'./outputNI/adql_radec.tbl',overwrite=True, \
format='ipac' )
rec = Table.read ('./outputNI/adql_radec.tbl', format='ascii.ipac')
print (rec)
query = "select count(koaid) from koa_nires \
where (contains(point('J2000',ra,dec), box('J2000', 194.25 22.03, 2, 2)))=1) "
Koa.query_adql (query, \
'./outputNI/adql_count.tbl',overwrite=True, \
format='ipac' )
rec = Table.read ('./outputNI/adql_count.tbl', format='ascii.ipac')
print (rec)
query = "select koaid, filehand, ra, dec from koa_nires\
where contains(point('icrs', ra, dec), \
polygon('icrs',193.25,21.03,193.25,23.03,196.25,22.03)) = 1"
Koa.query_adql(query, './outputNI/polygon_os.tbl', overwrite=True, format='ipac')
rec = Table.read ('./outputNI/polygon_os.tbl', format='ascii.ipac')
print (rec)
Koa.download ('./outputNI/parameters.tbl', \
'ipac', \
'./dnload_dir1', \
start_row=1, \
end_row=3)
Koa.download ('./outputNI/parameters.tbl', \
'ipac', \
'./dnload_dir2')
Koa.download ('./outputNI/parameters.tbl',
'ipac', \
'./dnload_dir3',
calibfile=1)
The next query shows how a PI can login with their KOA credentials, assigned when the data were acquired, and access their protected data. The example is a query for public data to show the syntax. Please login with your KOA supplied credentials to access your private data. While logged in, you can access all public data as well. Koa.login creates the cookie file at login.
Koa.login ('./tapcookie.txt')
Include the cookiepath in your query to access your data, as in this example:
Koa.query_date ('nires', \
'2018-12-18', \
'./outputNI/nires_login.tbl', overwrite=True, format='ipac', \
cookiepath='./tapcookie.txt' )
rec = Table.read ('./outputNI/nires_login.tbl',format='ipac')
print (rec)
Please acknowledge the use of KOA by including this text in your publications: "This research has made use of the Keck Observatory Archive (KOA), which is operated by the W. M. Keck Observatory and the NASA Exoplanet Science Institute (NExScI), under contract with the National Aeronautics and Space Administration."
Please also acknowledge the PI(s) of datasets that have been obtained through KOA, and please contact the KOA Help Desk if you publish archival data:
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