PyKOA offers access to public raw science and calibration files acquired with the Near Infrared Camera 2 (NIRC2) and quick-look reduced images derived from them. The quick-look files are intended for visuaization and are not intended for scientific analysis. See https://koa.ipac.caltech.edu/UserGuide/NIRC2/calibrated_data.html for a description of the reduction. For Keck Observatory PIs, PyKOA offers secure access to their protected data with the KOA credentials assigned to them.
Queries can be launched through several dedicated methods, or through the IVOA Astronomical Data Query Langage (ADQL); ADQL queries are underpinned by nexsciTAP, a NExScI Python-based server that implements the IVOA Table Access Protocol (TAP). PyKOA enables a rich variety of searches, including cone, box, polygon, or all-sky spatial searches; temporal searches; searches on program infotmation; and complex searches on multiple attributes.
This Jupyter Notebook provides examples of 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 IPAC ASCII, VOTable, CSV or TSV data formats.
This Tutorial illustrates methods for discovering and accessing public and private raw science and calibration files for HIRES:
General, complex metadata queries using the IVOA Astronomical Data Query Langage (ADQL).
Download raw science and associated calibration files, level 1 files or a subset of data, corresponding to a collection of metadata.
Queries for protected data (available to Keck PIs only).
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)
Help on Archive in module pykoa.koa.core object: class Archive(builtins.object) | Archive(**kwargs) | | The 'Archive' class provides functions for accessing data stored in the | Keck Observatory Archive (KOA). Queries are performed via the nexsciTAP | server. | | Keck PIs can use the KOA credentials assigned to them when data were | acquired (given at login) to search for their proprietary data. | | Example: | -------- | | import os | import sys | | from pykoa.koa import Koa | | Koa.query_datetime ('hires', '2018-03-16 00:00:00/2018-03-18 00:00:00', outpath= './meta.xml', format='ipac') | | Methods defined here: | | __init__(self, **kwargs) | 'init' method initializes the class with optional debugfile flag. | | Optional inputs: | ---------------- | debugfile: a file path for the debug output | | download(self, metapath, format, outdir, **kwargs) | 'download' method allows download of FITS files shown in the | metadata file. The same method has the option of download the | associated calibration files and level 1 files. | | *** Requirement: | | To download FITS files, the following two columns: | instrume and filehand must be included in the metadata file. | | To download associated calibrated files, the following three | columns: instrume, koaid, and filehand must be included in the | metadata file. | | | Required input: | ----- | metapath (string): a full path metadata table obtained from running | query methods | | format (string): metadata table's format: ipac, votable, csv, or tsv. | | outdir (string): the directory for depositing the returned files | | At least one of the following three optional parameters: | lev1file, lev1file, and calibfile should be set to 1.: | | | Optional input: | ---------------- | cookiepath (string): cookie file path for downloading the proprietary | KOA data; | | start_row (integer): default is start_row = 0; | | end_row (integer): default is end_row = nrows - 1 where nrows is the | number of rows in the metadata file; | | lev0file (integer): 1/0; | 1: download level0 files (i.e. raw data) in 'lev0' directory; | 0: do not download level0 files. | default is 1. | | calibfile (integer): 1/0; | 1: download calibration files; | 0: do not download calibration files. | default is 0. | | lev1file (integer): 1/0; | 1: download level1 files in 'lev1' directory; | 0: do not download level1 files. | default is 0. | | calibdir (integer): 1/0; | 1: put calibration files in their own directory named 'calib'; | 0: put the calibration files in the 'lev0' directory with other | raw, science files. | default is 1. | | login(self, cookiepath, **kwargs) | 'login' method validates a user has a valid KOA account; it takes two | 'keyword' arguments: userid and password. If the inputs are not | provided in the keyword, the login method prompts for inputs. | | Required input: | --------------- | cookiepath (string): a file path provided by the user to save | returned cookie (in login method) or to serve | as input parameter for the subsequent koa | query and download methods. | | Keyword input: | --------------- | userid (string): a valid user id assigned by KOA; | | password (string): a valid password in the KOA's user table; | | | Calling synopsis: | | koa.login (cookiepath, userid='xxxx', password='xxxxxx'), or | | koa.login (cookiepath): and the program will prompt for | userid and password | | print_data(self) | | query_adql(self, query, outpath, **kwargs) | 'query_adql' method receives a qualified ADQL query string from | the user input. | | Required Inputs: | --------------- | query (string): an ADQL query | | outpath (string): the output filename of the returned metadata table | | Optional inputs: | ---------------- | cookiepath (string): cookie file path for query the proprietary | KOA data. | | format (string): output format: votable, ipac, csv, or tsv | (default: ipac) | | maxrec (integer): maximum records to be returned | default: -1 or not specified will return all requested records | | query_criteria(self, param, outpath, **kwargs) | 'query_criteria' method allows searches of KOA by multiple | parameters specified in a python dictionary (param). | | param: a dictionary containing a list of acceptable parameters: | | instrument (required): HIRES | | datetime (string): a datetime range string in the format of | datetime1/datetime2, '/' being the separator between first | and second datetime valaues where datetime format is | 'yyyy-mm-dd hh:mm:ss' | | date (string): a date range string in the format of | date1/date2, '/' being the separator between first | and second date valaues where date format is 'yyyy-mm-dd' | | pos (string): a position string in the format of | | 1. circle ra dec radius; | | 2. polygon ra1 dec1 ra2 dec2 ra3 dec3 ra4 dec4; | | 3. box ra dec width height; | | all RA Dec in decimal degree J2000 coordinate. | | target (string): target name used in the project, this will be | searched against the database -- not SIMBAD or NED. | | outpath (string): file path for the returned metadata table | | Optional parameters: | -------------------- | cookiepath (string): cookie file path obtained via login method, only | required for querying the proprietary KOA data. | | format (string): output table format -- votable, ipac, csv, or tsv; | default: ipac | | maxrec (integer): maximum records to be returned | default: -1 or not specified will return all requested records | | query_date(self, instrument, date, outpath, **kwargs) | 'query_date' method searches KOA by 'date_obs' range | | Required Inputs: | --------------- | instrument (string): HIRES | | date (string): a date_obs string in the format of | date1/date2 where '/' separates the two date values` | of format 'yyyy-mm-dd' | | the following inputs are acceptable: | | date1/: will search data with date later than (>=) | date1 | | /date2: will search data with date earlier than (<=) | date2 | | date1: will search data with date equal to (=) date1 | | outpath (string): a full output filepath of the returned metadata | table | | e.g. | instrument = 'hires', | date = '2018-03-16/2018-03-18' | | e.g. | instrument = 'hires', | date = '2018-03-16/' | | e.g. | instrument = 'hires', | date = '/2018-03-18' | | e.g. | instrument = 'hires', | date = '2018-03-16' | | Optional inputs: | ---------------- | cookiepath (string): cookie file path for querying the proprietary | KOA data | | format (string): Output format: votable, ipac, csv, or tsv | (default: ipac) | | maxrec (integer): maximum records to be returned | default: -1 or not specified will return all requested records | | query_datetime(self, instrument, datetime, outpath, **kwargs) | 'query_datetime' method searches KOA by 'datetime' range | | Required Inputs: | --------------- | instrument (string): HIRES | | datetime (string): a datetime string in the format of | datetime1/datetime2 where '/' separates the two datetime values | of format 'yyyy-mm-dd hh:mm:ss' | | the following inputs are acceptable: | | datetime1/: will search data with datetime later than (>=) | datetime1 | | /datetime2: will search data with datetime earlier than (<=) | datetime2 | | datetime1: will search data with datetime equal to (=) datetime1 | | outpath (string): a full output filepath of the returned metadata | table | | e.g. | instrument = 'hires', | datetime = '2018-03-16 06:10:55/2018-03-18 00:00:00' | | e.g. | instrument = 'hires', | datetime = '2018-03-16 06:10:55/' | | e.g. | instrument = 'hires', | datetime = '/2018-03-18 00:00:00' | | e.g. | instrument = 'hires', | datetime = '2018-03-16 06:10:55' | | Optional inputs: | ---------------- | cookiepath (string): cookie file path for query the proprietary | KOA data | | format (string): Output format: votable, ipac, csv, or tsv | (default: ipac) | | maxrec (integer): maximum records to be returned | default: -1 or not specified will return all requested records | | query_object(self, instrument, object, outpath, **kwargs) | 'query_object' method searches KOA by 'object name' | | Required Inputs: | --------------- | | instrument: HIRES | | object (string): an object name resolvable by SIMBAD, NED, and | ExoPlanet's name_resolve; | | This method resolves the object name into coordiates to be used as the | center of the circle position search with default radius of 0.5 deg. | | e.g. | instrument = 'hires', | object = 'WD 1145+017' | | Optional Input: | --------------- | cookiepath (string): cookie file path for query the proprietary | KOA data. | | format (string): Output format: votable, ipac, csv, tsv (default: ipac) | | radius (float): search radius in deg (default = 0.5 deg) | | maxrec (integer): maximum records to be returned | default: -1 or not specified will return all requested records | | query_position(self, instrument, pos, outpath, **kwargs) | 'query_position' method searches KOA by 'position' | | Required Inputs: | --------------- | | instrument (string): HIRES | | pos (string): a position string in the format of | | 1. circle ra dec radius; | | 2. polygon ra1 dec1 ra2 dec2 ra3 dec3 ra4 dec4; | | 3. box ra dec width height; | | All RA Dec in decimal degree J2000 coordinate. | | e.g. | instrument = 'hires', | pos = 'circle 230.0 45.0 0.5' | | outpath (string): a full filepath for the returned metadata table | | Optional Input: | --------------- | cookiepath (string): cookie file path for querying the proprietary | KOA data. | | format (string): votable, ipac, csv, tsv (default: ipac) | | maxrec (integer): maximum records to be returned | default: -1 or not specified will return all requested records | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | astropytbl = None | | content_type = '' | | debug = 0 | | debugfname = './koa.debug' | | format = 'ipac' | | maxrec = -1 | | msg = '' | | ncaliblist = 0 | | ndnloaded = 0 | | ndnloaded_calib = 0 | | ndnloaded_lev1 = 0 | | nlev1list = 0 | | outdir = '' | | outpath = '' | | parampath = '' | | propflag = 1 | | query = '' | | status = '' | | tap = None
try:
os.mkdir('./outputN2')
except:
print(" Directory exists already", flush=True)
Koa.query_date ( 'nirc2', '2014-09-06', \
'./outputN2/nirc2_date.tbl', overwrite=True, format='ipac')
rec = Table.read ('./outputN2/nirc2_date.tbl',format='ipac')
print (rec)
submitting request... Result downloaded to file [./outputN2/nirc2_date.tbl] koaid instrume targname object ... slitmm slitname slsname ... mm ---------------------- -------- -------- ------ ... ------ -------- ------- N2.20140906.11394.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11451.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11508.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11564.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11621.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11677.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11734.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11790.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11847.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11903.fits NIRC2 unknown flat ... 0.0 none clear ... ... ... ... ... ... ... ... N2.20140906.36033.fits NIRC2 5087 5087 ... 0.0 none clear N2.20140906.36059.fits NIRC2 5087 5087 ... 0.0 none clear N2.20140906.36330.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36402.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36474.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36556.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36630.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36799.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36871.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36944.fits NIRC2 5123 5123 ... 0.0 none clear Length = 356 rows
Koa.query_date ('nirc2', \
'2014-09-05/2014-09-06', \
'./outputN2/nirc2_daterange.vot', overwrite=True, format='votable' )
submitting request... Result downloaded to file [./outputN2/nirc2_daterange.vot]
Koa.query_datetime ('nirc2', \
'2014-09-06 05:00:00/2014-09-06 06:00:00', \
'./outputN2/nirc2_datetime.csv', overwrite=True, format='csv' )
submitting request... Result downloaded to file [./outputN2/nirc2_datetime.csv]
Koa.query_date ('nirc2', \
'2014-09-06', \
'./outputN2/nirc2_date.tsv', overwrite=True, format='tsv' )
submitting request... Result downloaded to file [./outputN2/nirc2_date.tsv]
Koa.query_position ('nirc2', \
'circle 238.0 +27.6 .5', \
'./outputN2/position_search.tbl', overwrite=True )
rec = Table.read ('./outputN2/position_search.tbl', format='ascii.ipac' )
print (rec)
submitting request... Result downloaded to file [./outputN2/position_search.tbl] koaid instrume targname ... slitmm slitname slsname ... mm ---------------------- -------- ---------- ... ------ -------- ------- N2.20140906.18417.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18437.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18450.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18462.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18476.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18593.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18603.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18614.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18624.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18635.fits NIRC2 GRB140903A ... 0.0 none clear ... ... ... ... ... ... ... N2.20140906.20063.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.20074.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.20084.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.20095.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.20106.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.20127.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.20138.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.20149.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.20159.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.20170.fits NIRC2 GRB140903A ... 0.0 none clear Length = 130 rows
query = "select koaid from koa_nirc2 where \
(contains(point('J2000',ra ,dec), box('J2000', 238.0 +27.6, 0.5, 0.5))=1) "
Koa.query_adql (query, './outputN2/adql_radec.tbl',overwrite=True, \
format='ipac' )
rec = Table.read ('./outputN2/adql_radec.tbl', format='ascii.ipac')
print (rec)
submitting request... Result downloaded to file [./outputN2/adql_radec.tbl] koaid ---------------------- N2.20140906.18417.fits N2.20140906.18437.fits N2.20140906.18450.fits N2.20140906.18462.fits N2.20140906.18476.fits N2.20140906.18593.fits N2.20140906.18603.fits N2.20140906.18614.fits N2.20140906.18624.fits N2.20140906.18635.fits ... N2.20140906.20047.fits N2.20140906.20063.fits N2.20140906.20074.fits N2.20140906.20084.fits N2.20140906.20095.fits N2.20140906.20106.fits N2.20140906.20127.fits N2.20140906.20138.fits N2.20140906.20149.fits N2.20140906.20159.fits N2.20140906.20170.fits Length = 130 rows
query = "select koaid, filehand, ra, dec from koa_nirc2 \
where contains(point('icrs', ra, dec), \
polygon('icrs',237.5 27.1 238.5 27.1 238.5 28.1 237.5 28.1)) = 1"
Koa.query_adql(query, './outputN2/polygon_n2.tbl', overwrite=True, format='ipac' )
rec = Table.read ('./outputN2/polygon_n2.tbl', format='ascii.ipac')
print (rec)
submitting request... Result downloaded to file [./outputN2/polygon_n2.tbl] koaid ... dec ---------------------- ... -------- N2.20140906.18417.fits ... 27.60311 N2.20140906.18437.fits ... 27.60297 N2.20140906.18450.fits ... 27.60324 N2.20140906.18462.fits ... 27.60297 N2.20140906.18476.fits ... 27.60324 N2.20140906.18593.fits ... 27.60311 N2.20140906.18603.fits ... 27.60311 N2.20140906.18614.fits ... 27.60311 N2.20140906.18624.fits ... 27.60311 N2.20140906.18635.fits ... 27.60311 ... ... ... N2.20140906.20047.fits ... 27.60318 N2.20140906.20063.fits ... 27.60304 N2.20140906.20074.fits ... 27.60304 N2.20140906.20084.fits ... 27.60304 N2.20140906.20095.fits ... 27.60304 N2.20140906.20106.fits ... 27.60304 N2.20140906.20127.fits ... 27.60318 N2.20140906.20138.fits ... 27.60318 N2.20140906.20149.fits ... 27.60318 N2.20140906.20159.fits ... 27.60318 N2.20140906.20170.fits ... 27.60318 Length = 130 rows
Koa.query_object ('nirc2', \
'grb140903a', './outputN2/nirc2_object.tbl', overwrite=True, format='ipac')
rec = Table.read ('./outputN2/nirc2_object.tbl', format='ascii.ipac')
print (rec)
object name resolved: ra= 238.0135, dec=27.60302778 submitting request... Result downloaded to file [./outputN2/nirc2_object.tbl] koaid instrume targname ... slitmm slitname slsname ... mm ---------------------- -------- ---------- ... ------ -------- ------- N2.20140906.18417.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18437.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18450.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18462.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18476.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18593.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18603.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18614.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18624.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18635.fits NIRC2 GRB140903A ... 0.0 none clear ... ... ... ... ... ... ... N2.20140906.20063.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.20074.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.20084.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.20095.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.20106.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.20127.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.20138.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.20149.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.20159.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.20170.fits NIRC2 GRB140903A ... 0.0 none clear Length = 130 rows
query ="select koaid, filehand, progid from koa_nirc2 where (upper(progid) = 'N153N2') "
Koa.query_adql (query, \
'./outputN2/program_info.tbl', overwrite=True, format='ipac' )
rec = Table.read('./outputN2/program_info.tbl', format='ascii.ipac')
print (rec)
submitting request... Result downloaded to file [./outputN2/program_info.tbl] koaid ... progid ---------------------- ... ------ N2.20081009.37236.fits ... N153N2 N2.20081009.37250.fits ... N153N2 N2.20081009.37264.fits ... N153N2 N2.20081009.37278.fits ... N153N2 N2.20081009.37292.fits ... N153N2 N2.20081009.37305.fits ... N153N2 N2.20081009.37319.fits ... N153N2 N2.20081009.37332.fits ... N153N2 N2.20081009.37346.fits ... N153N2 N2.20081009.37360.fits ... N153N2 ... ... ... N2.20140906.36000.fits ... N153N2 N2.20140906.36033.fits ... N153N2 N2.20140906.36059.fits ... N153N2 N2.20140906.36330.fits ... N153N2 N2.20140906.36402.fits ... N153N2 N2.20140906.36474.fits ... N153N2 N2.20140906.36556.fits ... N153N2 N2.20140906.36630.fits ... N153N2 N2.20140906.36799.fits ... N153N2 N2.20140906.36871.fits ... N153N2 N2.20140906.36944.fits ... N153N2 Length = 1923 rows
param = dict()
param['instrument'] = 'nirc2'
param['datetime'] = '2014-09-06 05:10:00/2014-09-06 05:13:00'
param['target'] = 'GRB140903A'
Koa.query_criteria (param, \
'./outputN2/parameters.tbl', overwrite=True )
rec = Table.read('./outputN2/parameters.tbl', format='ipac')
print (rec)
submitting request... Result downloaded to file [./outputN2/parameters.tbl] koaid instrume targname ... slitmm slitname slsname ... mm ---------------------- -------- ---------- ... ------ -------- ------- N2.20140906.18603.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18614.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18624.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18635.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18648.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18659.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18670.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18681.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18692.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18711.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18721.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18732.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18743.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18753.fits NIRC2 GRB140903A ... 0.0 none clear N2.20140906.18766.fits NIRC2 GRB140903A ... 0.0 none clear
query = "select koaid, object, koaimtyp, frameno, ra, dec, \
to_char(date_obs,'YYYY-MM-DD') as date_obs, elaptime, \
waveblue, wavered, airmass, camname, detmode, filter, \
grsname, guidfwhm, slsname, \
progid, proginst, progpi, progtitl, semester, ofname, filehand \
from koa_nirc2 \
where (contains(point('J2000',ra ,dec), circle('J2000', 238.0 +27.6, 0.5))=1) \
order by utdatetime"
Koa.query_adql(query,'./outputN2/adql_cone.tbl', overwrite=True, format='ipac')
rec = Table.read ('./outputN2/adql_cone.tbl', format='ascii.ipac')
print (rec)
submitting request... Result downloaded to file [./outputN2/adql_cone.tbl] koaid ... filehand ... ---------------------- ... ----------------------------------------------------- N2.20140906.18417.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.18417.fits N2.20140906.18437.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.18437.fits N2.20140906.18450.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.18450.fits N2.20140906.18462.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.18462.fits N2.20140906.18476.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.18476.fits N2.20140906.18593.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.18593.fits N2.20140906.18603.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.18603.fits N2.20140906.18614.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.18614.fits N2.20140906.18624.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.18624.fits N2.20140906.18635.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.18635.fits ... ... ... N2.20140906.20063.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.20063.fits N2.20140906.20074.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.20074.fits N2.20140906.20084.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.20084.fits N2.20140906.20095.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.20095.fits N2.20140906.20106.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.20106.fits N2.20140906.20127.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.20127.fits N2.20140906.20138.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.20138.fits N2.20140906.20149.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.20149.fits N2.20140906.20159.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.20159.fits N2.20140906.20170.fits ... /koadata10/NIRC2/20140906/lev0/N2.20140906.20170.fits Length = 130 rows
query = "select top 10 koaid, ra ,dec, utdatetime from koa_nirc2 \
where (contains(point('J2000',ra ,dec), \
box('J2000', 238.0 +27.6, 0.5, 0.5))) =1) order by utdatetime desc "
Koa.query_adql (query, \
'./outputN2/adql_radec_top10.tbl',overwrite=True, \
format='ipac' )
rec = Table.read ('./outputN2/adql_radec_top10.tbl', format='ascii.ipac')
print (rec)
submitting request... Result downloaded to file [./outputN2/adql_radec_top10.tbl] koaid ra dec utdatetime ---------------------- --------- -------- -------------------------- N2.20140906.20170.fits 238.01203 27.60318 2014-09-06 05:36:10.510000 N2.20140906.20159.fits 238.01203 27.60318 2014-09-06 05:35:59.960000 N2.20140906.20149.fits 238.01203 27.60318 2014-09-06 05:35:49.110000 N2.20140906.19980.fits 238.01203 27.60304 2014-09-06 05:33:00.760000 N2.20140906.19970.fits 238.01203 27.60304 2014-09-06 05:32:50.210000 N2.20140906.19959.fits 238.01203 27.60304 2014-09-06 05:32:39.660000 N2.20140906.19944.fits 238.01203 27.60304 2014-09-06 05:32:24.760000 N2.20140906.19934.fits 238.01203 27.60304 2014-09-06 05:32:14.260000 N2.20140906.19921.fits 238.01211 27.60311 2014-09-06 05:32:01.710000 N2.20140906.19450.fits 238.01219 27.60304 2014-09-06 05:24:10.710000
query = "select count(koaid) from koa_nirc2 \
where (contains(point('J2000',ra,dec), box('J2000', 238.0 +27.6, 0.5, 0.5)))=1) "
Koa.query_adql (query, \
'./outputN2/adql_count.tbl',overwrite=True, \
format='ipac' )
rec = Table.read ('./outputN2/adql_count.tbl', format='ascii.ipac')
print (rec)
submitting request... Result downloaded to file [./outputN2/adql_count.tbl] count(koaid) ------------ 130
Koa.download ('./outputN2/parameters.tbl', \
'ipac', \
'./dnload_dir1', \
start_row=1, \
end_row=3 )
Start downloading 3 koaid data you requested; please check your outdir: ./dnload_dir1 for progress .... A total of 3 new lev0 FITS files downloaded.
Koa.download ('./outputN2/parameters.tbl', \
'ipac', \
'./dnload_dir1' )
Start downloading 15 koaid data you requested; please check your outdir: ./dnload_dir1 for progress .... A total of 12 new lev0 FITS files downloaded.
Koa.query_date ( 'nirc2', '2014-09-06', \
'./outputN2/nirc2_date.tbl', overwrite=True, format='ipac')
rec = Table.read ('./outputN2/nirc2_date.tbl',format='ipac')
print (rec)
submitting request... Result downloaded to file [./outputN2/nirc2_date.tbl] koaid instrume targname object ... slitmm slitname slsname ... mm ---------------------- -------- -------- ------ ... ------ -------- ------- N2.20140906.11394.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11451.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11508.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11564.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11621.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11677.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11734.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11790.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11847.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11903.fits NIRC2 unknown flat ... 0.0 none clear ... ... ... ... ... ... ... ... N2.20140906.36033.fits NIRC2 5087 5087 ... 0.0 none clear N2.20140906.36059.fits NIRC2 5087 5087 ... 0.0 none clear N2.20140906.36330.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36402.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36474.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36556.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36630.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36799.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36871.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36944.fits NIRC2 5123 5123 ... 0.0 none clear Length = 356 rows
Koa.download ('./outputN2/nirc2_date.tbl', \
'ipac', \
'dnload_dir_nirc2_calib1', \
start_row=80, \
end_row=85, \
lev1file=1 )
Start downloading 6 koaid data you requested; please check your outdir: dnload_dir_nirc2_calib1 for progress .... Failed to get level 1 file list for koaid: N2.20140906.19084.fits Failed to submit the request: HTTPSConnectionPool(host='koa.ipac.caltech.edu', port=443): Max retries exceeded with url: /cgi-bin/KoaAPI/nph-getL1list?instrument=NIRC2&koaid=N2.20140906.19084.fits&filehand=/koadata10/NIRC2/20140906/lev0/N2.20140906.19084.fits (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f7b51aee9d0>: Failed to establish a new connection: [Errno 60] Operation timed out')) Failed to get level 1 data list for koaid: N2.20140906.19084.fits No level 1 data found for koaid: [N2.20140906.19084.fits] A total of 6 new lev0 FITS files downloaded. 5 new lev1 list downloaded. 15 new lev1 files downloaded.
Koa.download ('./outputN2/nirc2_date.tbl', \
'ipac', \
'dnload_dir_nirc2_calib1', \
start_row=80, \
end_row=85, \
lev1file=1, \
calibfile=1, \
calibdir=1 )
Start downloading 6 koaid data you requested; please check your outdir: dnload_dir_nirc2_calib1 for progress .... A total of 0 new lev0 FITS files downloaded. 1 new lev1 list downloaded. 3 new lev1 files downloaded. 6 new calibration list downloaded. 7 new calibration FITS files downloaded.
Koa.download ('./outputN2/nirc2_date.tbl', \
'ipac', \
'dnload_dir_nirc2_calib0', \
start_row=80, \
end_row=85, \
lev1file=1, \
calibfile=1, \
calibdir=0 )
Start downloading 6 koaid data you requested; please check your outdir: dnload_dir_nirc2_calib0 for progress .... A total of 6 new lev0 FITS files downloaded. 6 new lev1 list downloaded. 18 new lev1 files downloaded. 6 new calibration list downloaded. 7 new calibration FITS files downloaded.
#### The JSON files can be read as Pandas data frames with the code below. The example formats the JSON file 'N2.20140906.19070.caliblist.json' in the 'dnload_dir_nirc2_calib1/calib' directory
import json
import pandas as pd
filepath = './dnload_dir_nirc2_calib1/calib/N2.20140906.19070.caliblist.json'
fp = None
jsondata = None
try:
with open (filepath) as fp:
jsondata = json.load (fp)
fp.close()
except Exception as e:
print (f'read input jsonfile error: {str(e):s}')
sys.exit()
status = ''
nrec = -1
tbldata = None
try:
status = jsondata['status']
except Exception as e:
print ('Exception extracting keyword "status"')
try:
nrec = int(jsondata['nrec'])
except Exception as e:
print ('Exception extracting keyword "nrec"')
try:
tbldata = jsondata['table']
except Exception as e:
print ('Exception extracting keyword "table"')
print (f'status= {status:s}')
print (f'nrec= {nrec:d}')
df = pd.json_normalize (tbldata)
print (df)
status= ok nrec= 7 koaid ofname instrument targname object koaimtyp \ 0 N2.20140906.11394.fits n0001.fits NIRC2 unknown flat flatlamp 1 N2.20140906.11451.fits n0002.fits NIRC2 unknown flat flatlamp 2 N2.20140906.11508.fits n0003.fits NIRC2 unknown flat flatlamp 3 N2.20140906.11564.fits n0004.fits NIRC2 unknown flat flatlamp 4 N2.20140906.11621.fits n0005.fits NIRC2 unknown flat flatlamp 5 N2.20140906.11677.fits n0006.fits NIRC2 unknown flat flatlamp 6 N2.20140906.11734.fits n0007.fits NIRC2 unknown flat flatlamp frameno ra dec date_obs ... grsname itime multisam \ 0 1 58.00000 45.00000 2014-09-06 ... clear 45.00000000 16 1 2 58.00000 45.00000 2014-09-06 ... clear 45.00000000 16 2 3 58.00000 45.00000 2014-09-06 ... clear 45.00000000 16 3 4 58.00000 45.00000 2014-09-06 ... clear 45.00000000 16 4 5 58.00000 45.00000 2014-09-06 ... clear 45.00000000 16 5 6 58.00000 45.00000 2014-09-06 ... clear 45.00000000 16 6 7 58.00000 45.00000 2014-09-06 ... clear 45.00000000 16 naxis1 naxis2 sampmode slitmm slitname slsname diff_date 0 1024 1024 3 0.00000000 none clear 0 1 1024 1024 3 0.00000000 none clear 0 2 1024 1024 3 0.00000000 none clear 0 3 1024 1024 3 0.00000000 none clear 0 4 1024 1024 3 0.00000000 none clear 0 5 1024 1024 3 0.00000000 none clear 0 6 1024 1024 3 0.00000000 none clear 0 [7 rows x 38 columns]
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')
Userid: tapdemo Password: ········ Successfully login as tapdemo
Include the cookiepath in your query to access your data, as in this example:
Koa.query_date ('nirc2', \
'2014-09-06', \
'./outputN2/nirc2_login.tbl', overwrite=True, format='ipac', \
cookiepath='./tapcookie.txt' )
rec = Table.read ('./outputN2/nirc2_login.tbl',format='ipac')
print (rec)
submitting request... Result downloaded to file [./outputN2/nirc2_login.tbl] koaid instrume targname object ... slitmm slitname slsname ... mm ---------------------- -------- -------- ------ ... ------ -------- ------- N2.20140906.11394.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11451.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11508.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11564.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11621.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11677.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11734.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11790.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11847.fits NIRC2 unknown flat ... 0.0 none clear N2.20140906.11903.fits NIRC2 unknown flat ... 0.0 none clear ... ... ... ... ... ... ... ... N2.20140906.36033.fits NIRC2 5087 5087 ... 0.0 none clear N2.20140906.36059.fits NIRC2 5087 5087 ... 0.0 none clear N2.20140906.36330.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36402.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36474.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36556.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36630.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36799.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36871.fits NIRC2 5123 5123 ... 0.0 none clear N2.20140906.36944.fits NIRC2 5123 5123 ... 0.0 none clear Length = 356 rows
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