Keck Observatory Archive (KOA) Python Client - Tutorial: Access to LRIS Raw Data

September, 2021

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 Low Resolution Imaging Spectrograph (LRIS) with the methods supported by PyKOA, and examples of how Keck PIs may access their protected data.

Installation

PyKOA can be installed from PyPI:

$ pip install --upgrade pykoa

Requirements

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.

Overview of this Tutorial

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:

  • Query by date or date range (with examples for each file format).
  • Query by position.
  • Query by object.
  • Query by program information.
  • Query by by combinations of the above search criteria.
  • Download raw science and associated calibration files, or a subset of data, corresponding to a collection of metadata.
  • General, complex metadata queries in the IVOA Astronomical Data Query Langage (ADQL).
  • 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.

In [1]:
import sys
import io
import os
from pykoa.koa import Koa 
from astropy.table import Table,Column

View the help file

In [2]:
help(Koa)
Help on Archive in module pykoa.koa.core object:

class Archive(builtins.object)
 |  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 (and/or) 
 |      associated calibration files shown in their metadata file.
 |      
 |      *** Requirement: To download files, the following three columns: 
 |          instrume, koaid, and filehand must be included in the input
 |          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      
 |      
 |      
 |      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;
 |      
 |      calibfile (integer): whether to download the associated calibration 
 |          files (0: do not download; 1: download);
 |          default is 0.
 |  
 |  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
 |  
 |  outdir = ''
 |  
 |  outpath = ''
 |  
 |  parampath = ''
 |  
 |  query = ''
 |  
 |  status = ''
 |  
 |  tap = None

Define instrument and search parameters

In [13]:
instrument = 'LRIS'

instr = 'lris'
koatable = 'koa_lris'    
outdir = './outputLR/'
date = '2015-01-23'
propdate = '2017-01-29' 
daterange = '2015-01-01/2015-03-01'
datetimerange = '2015-01-01 00:00:00/2015-03-01 23:59:59'
program = 'C305'
pos_target = 'Aldebaran'
targname = 'Feige110'
circle_pos = '174.27 29.8 1.0'
box_pos = '174.27 29.8 1 1'
polygon_pos = '173.27 28.8 173.27 30.8 176.27 29.8 '

query_keys = 'koaid, object, koaimtyp, frameno, ra, dec,  \
            to_char(date_obs,\'YYYY-MM-DD\') as date_obs, elaptime, \
            waveblue, wavered, airmass, blufilt, dichname, graname, grisname, redfilt, slitname, \
            progid, proginst,  progpi, progtitl, semester, ofname, filehand '

Create output directory

In [4]:
try:
    os.mkdir(outdir)
except:
    print(instrument + " Directory exists already", flush=True)

Anonymous access

Query by date and date range

Query by single date; output in IPAC ASCII format (default)

In [3]:
Koa.query_date ( instr, date, \
            outdir + instr + "_date.tbl", overwrite=True, format='ipac')
rec = Table.read (outdir + instrument + "_date.tbl",format='ipac')
print (rec)
submitting request...
Result downloaded to file [./outputLR/lris_date.tbl]
        koaid          instrume ...   semid    propint
                                ...                   
---------------------- -------- ... ---------- -------
LR.20150123.00166.fits     LRIS ... 2014b_none      18
LR.20150123.00300.fits     LRIS ... 2014b_none      18
LR.20150123.00538.fits     LRIS ... 2014b_none      18
LR.20150123.00792.fits     LRIS ... 2014b_none      18
LR.20150123.01035.fits     LRIS ... 2014b_none      18
LR.20150123.01289.fits     LRIS ... 2014b_none      18
LR.20150123.01603.fits     LRIS ... 2014b_none      18

Query by date range; output in VOTable format

In [4]:
Koa.query_date (instr, \
    daterange, \
    outdir + instr + "_daterange.vot", overwrite=True, format='votable' )
rec = Table.read (outdir + instr + "_daterange.vot",format='votable')
print (rec)
submitting request...
Result downloaded to file [./outputLR/lris_daterange.vot]
        koaid          instrume ...    semid     propint
                                ...                     
---------------------- -------- ... ------------ -------
LB.20150119.72427.fits LRISBLUE ...    2014b_eng      18
LR.20150119.72440.fits     LRIS ...    2014b_eng      18
LB.20150119.72771.fits LRISBLUE ...    2014b_eng      18
LR.20150119.72779.fits     LRIS ...    2014b_eng      18
LR.20150119.73014.fits     LRIS ...    2014b_eng      18
LB.20150119.78800.fits LRISBLUE ...    2014b_eng      18
LR.20150119.78819.fits     LRIS ...    2014b_eng      18
LB.20150120.02709.fits LRISBLUE ... 2014b_u090la      18
LR.20150120.02728.fits     LRIS ... 2014b_u090la      18
LB.20150120.03172.fits LRISBLUE ... 2014b_u090la      18
                   ...      ... ...          ...     ...
LB.20150225.07893.fits LRISBLUE ...   2015a_none      18
LB.20150225.08018.fits LRISBLUE ...   2015a_none      18
LB.20150225.08106.fits LRISBLUE ...   2015a_none      18
LB.20150225.08195.fits LRISBLUE ...   2015a_none      18
LB.20150225.08284.fits LRISBLUE ...   2015a_none      18
LB.20150225.08372.fits LRISBLUE ...   2015a_none      18
LB.20150225.08461.fits LRISBLUE ...   2015a_none      18
LB.20150225.08550.fits LRISBLUE ...   2015a_none      18
LB.20150225.08638.fits LRISBLUE ...   2015a_none      18
LB.20150225.08727.fits LRISBLUE ...   2015a_none      18
Length = 2454 rows

Query by date and time range; output in CSV format

In [5]:
Koa.query_datetime (instr, \
    datetimerange, \
    outdir + instr + "_datetime.csv", overwrite=True, format='csv' )
rec = Table.read (outdir + instr + "_datetime.csv",format='csv')
print (rec)
submitting request...
Result downloaded to file [./outputLR/lris_datetime.csv]
        koaid          instrume ...    semid     propint
---------------------- -------- ... ------------ -------
LB.20150119.72427.fits LRISBLUE ...    2014b_eng      18
LR.20150119.72440.fits     LRIS ...    2014b_eng      18
LB.20150119.72771.fits LRISBLUE ...    2014b_eng      18
LR.20150119.72779.fits     LRIS ...    2014b_eng      18
LR.20150119.73014.fits     LRIS ...    2014b_eng      18
LB.20150119.78800.fits LRISBLUE ...    2014b_eng      18
LR.20150119.78819.fits     LRIS ...    2014b_eng      18
LB.20150120.02709.fits LRISBLUE ... 2014b_u090la      18
LR.20150120.02728.fits     LRIS ... 2014b_u090la      18
LB.20150120.03172.fits LRISBLUE ... 2014b_u090la      18
                   ...      ... ...          ...     ...
LB.20150225.07805.fits LRISBLUE ...   2015a_none      18
LB.20150225.07893.fits LRISBLUE ...   2015a_none      18
LB.20150225.08018.fits LRISBLUE ...   2015a_none      18
LB.20150225.08106.fits LRISBLUE ...   2015a_none      18
LB.20150225.08195.fits LRISBLUE ...   2015a_none      18
LB.20150225.08284.fits LRISBLUE ...   2015a_none      18
LB.20150225.08372.fits LRISBLUE ...   2015a_none      18
LB.20150225.08461.fits LRISBLUE ...   2015a_none      18
LB.20150225.08550.fits LRISBLUE ...   2015a_none      18
LB.20150225.08638.fits LRISBLUE ...   2015a_none      18
LB.20150225.08727.fits LRISBLUE ...   2015a_none      18
Length = 2454 rows

Query by date range; output in TSV format

In [6]:
Koa.query_date (instr, \
    date, \
    outdir + instr + "_date.tsv", overwrite=True, format='tsv' )
rec = Table.read (outdir + instr + "_date.tsv",format='ascii.fast_tab')
print (rec)
submitting request...
Result downloaded to file [./outputLR/lris_date.tsv]
        koaid          instrume ...   semid    propint
---------------------- -------- ... ---------- -------
LR.20150123.00166.fits     LRIS ... 2014b_none      18
LR.20150123.00300.fits     LRIS ... 2014b_none      18
LR.20150123.00538.fits     LRIS ... 2014b_none      18
LR.20150123.00792.fits     LRIS ... 2014b_none      18
LR.20150123.01035.fits     LRIS ... 2014b_none      18
LR.20150123.01289.fits     LRIS ... 2014b_none      18
LR.20150123.01603.fits     LRIS ... 2014b_none      18

Query by position

In [7]:
Koa.query_position (instr , \
    "circle " + circle_pos , \
    outdir + instr + "_position_search.tbl", overwrite=True )
rec = Table.read (outdir + instr + "_position_search.tbl", format='ascii.ipac' )
print (rec)
submitting request...
Result downloaded to file [./outputLR/lris_position_search.tbl]
        koaid          instrume       object       ...   semid    propint
                                                   ...                   
---------------------- -------- ------------------ ... ---------- -------
LR.19980415.20592.fits     LRIS        bd1137+3000 ... 1998a_u29l      18
LR.19980415.22527.fits     LRIS        bd1137+3000 ... 1998a_u29l      18
LR.19981211.56071.fits     LRIS             gd 140 ... 1998b_u58l      18
LR.19981211.56259.fits     LRIS             gd 140 ... 1998b_u58l      18
LR.19981223.57984.fits     LRIS             GD 140 ...  1998b_u4l      18
LR.19981223.58152.fits     LRIS             GD 140 ...  1998b_u4l      18
LR.19981223.58380.fits     LRIS                arc ...  1998b_u4l      18
LR.20000106.49902.fits     LRIS             gd 140 ... 1999b_u25l      18
LR.20000106.49958.fits     LRIS             gd 140 ... 1999b_u25l      18
LR.20000106.50061.fits     LRIS             gd 140 ... 1999b_u25l      18
                   ...      ...                ... ...        ...     ...
LB.20180512.20848.fits LRISBLUE dome flat long_1.0 ... 2018a_c305      18
LR.20180512.20857.fits     LRIS dome flat long_1.0 ... 2018a_c305      18
LB.20180512.21032.fits LRISBLUE dome flat long_1.0 ... 2018a_c305      18
LR.20180512.21080.fits     LRIS dome flat long_1.0 ... 2018a_c305      18
LB.20181229.56411.fits LRISBLUE     MIRA PMFM -350 ... 2018b_c306      18
LR.20181229.56431.fits     LRIS     MIRA PMFM -350 ... 2018b_c306      18
LB.20181229.56478.fits LRISBLUE     MIRA PMFM -350 ... 2018b_c306      18
LR.20181229.56539.fits     LRIS     MIRA PMFM -350 ... 2018b_c306      18
LB.20190304.33117.fits LRISBLUE       ZTF18acepcws ... 2019a_c281      18
LR.20190304.33130.fits     LRIS       ZTF18acepcws ... 2019a_c281      18
Length = 101 rows

Query by object

In [8]:
Koa.query_object (instr, \
    pos_target, outdir + instr + "_object.tbl", radius=1.0, overwrite=True, format='ipac')
rec = Table.read (outdir + instr + "_object.tbl", format='ascii.ipac')
object name resolved: ra= 68.980174, dec=+16.509201
submitting request...
Result downloaded to file [./outputLR/lris_object.tbl]

Query for program information

In [9]:
query ="select koaid, filehand, progid from " + koatable + " where (upper(progid) = '" + program + "')" 
Koa.query_adql (query, outdir + instr + "_program_info.tbl", overwrite=True, format='ipac' )
rec = Table.read(outdir + instr + "_program_info.tbl", format='ascii.ipac')
print (rec)
    
submitting request...
Result downloaded to file [./outputLR/lris_program_info.tbl]
        koaid          ... progid
---------------------- ... ------
LB.20180512.01660.fits ...   C305
LB.20180512.03116.fits ...   C305
LB.20180512.03186.fits ...   C305
LB.20180512.03390.fits ...   C305
LB.20180512.03473.fits ...   C305
LB.20180512.04976.fits ...   C305
LB.20180512.05041.fits ...   C305
LB.20180512.05101.fits ...   C305
LB.20180512.05161.fits ...   C305
LB.20180512.05221.fits ...   C305
                   ... ...    ...
LR.20180512.38834.fits ...   C305
LR.20180512.40161.fits ...   C305
LR.20180512.41491.fits ...   C305
LR.20180512.42818.fits ...   C305
LR.20180512.44145.fits ...   C305
LR.20180512.45472.fits ...   C305
LR.20180512.46800.fits ...   C305
LR.20180512.48127.fits ...   C305
LR.20180512.49454.fits ...   C305
LR.20180512.50781.fits ...   C305
LR.20180512.52109.fits ...   C305
Length = 140 rows

Query by instrument, date, and target

In [10]:
param = dict()
param['instrument'] = instr
param['datetime'] = datetimerange
param['target'] = targname
Koa.query_criteria (param, \
    outdir + instr + "_parameters.tbl", overwrite=True )
rec = Table.read(outdir + instr + "_parameters.tbl", format='ipac')
print (rec)
submitting request...
Result downloaded to file [./outputLR/lris_parameters.tbl]
        koaid          instrume ...    semid     propint
                                ...                     
---------------------- -------- ... ------------ -------
LB.20150120.17110.fits LRISBLUE ... 2014b_u090la      18
LR.20150120.17130.fits     LRIS ... 2014b_u090la      18
LB.20150120.17653.fits LRISBLUE ... 2014b_u090la      18
LR.20150120.17672.fits     LRIS ... 2014b_u090la      18
LB.20150120.17852.fits LRISBLUE ... 2014b_u090la      18
LR.20150120.17871.fits     LRIS ... 2014b_u090la      18
LB.20150120.18155.fits LRISBLUE ... 2014b_u090la      18
LR.20150120.18179.fits     LRIS ... 2014b_u090la      18
LB.20150120.18354.fits LRISBLUE ... 2014b_u090la      18

General Metadata Queries With the Astronomical Data Query Langage (ADQL) Method.

A TAP query made with the ADQL method enables you to make general and complex queries against the archive. If you wish to download data discovered via the ADQL query made against KOA, you must include explicitly include the koaid, instrument , and filehandle in the query.


Spatial cone search query with column selection; order by UT Time.

In [14]:
query =  "select " + query_keys + " from " + koatable + \
    " where (contains(point('J2000',ra ,dec), circle('J2000', " + circle_pos + "))=1) order by utdatetime"
Koa.query_adql(query, outdir + instr + "_adql_cone.tbl", overwrite=True, format='ipac')
rec = Table.read (outdir + instr + "_adql_cone.tbl", format='ascii.ipac')
print(rec)
submitting request...
Result downloaded to file [./outputLR/lris_adql_cone.tbl]
        koaid          ...                       filehand                      
                       ...                                                     
---------------------- ... ----------------------------------------------------
LR.19980415.20592.fits ... /koadata26/LRIS/19980415/lev0/LR.19980415.20592.fits
LR.19980415.22527.fits ... /koadata26/LRIS/19980415/lev0/LR.19980415.22527.fits
LR.19981211.56071.fits ... /koadata26/LRIS/19981211/lev0/LR.19981211.56071.fits
LR.19981211.56259.fits ... /koadata26/LRIS/19981211/lev0/LR.19981211.56259.fits
LR.19981223.57984.fits ... /koadata26/LRIS/19981223/lev0/LR.19981223.57984.fits
LR.19981223.58152.fits ... /koadata26/LRIS/19981223/lev0/LR.19981223.58152.fits
LR.19981223.58380.fits ... /koadata26/LRIS/19981223/lev0/LR.19981223.58380.fits
LR.20000106.49902.fits ... /koadata26/LRIS/20000106/lev0/LR.20000106.49902.fits
LR.20000106.49958.fits ... /koadata26/LRIS/20000106/lev0/LR.20000106.49958.fits
LR.20000106.50061.fits ... /koadata26/LRIS/20000106/lev0/LR.20000106.50061.fits
                   ... ...                                                  ...
LB.20180512.20848.fits ... /koadata27/LRIS/20180512/lev0/LB.20180512.20848.fits
LR.20180512.20857.fits ... /koadata27/LRIS/20180512/lev0/LR.20180512.20857.fits
LB.20180512.21032.fits ... /koadata27/LRIS/20180512/lev0/LB.20180512.21032.fits
LR.20180512.21080.fits ... /koadata27/LRIS/20180512/lev0/LR.20180512.21080.fits
LB.20181229.56411.fits ... /koadata27/LRIS/20181229/lev0/LB.20181229.56411.fits
LR.20181229.56431.fits ... /koadata27/LRIS/20181229/lev0/LR.20181229.56431.fits
LB.20181229.56478.fits ... /koadata27/LRIS/20181229/lev0/LB.20181229.56478.fits
LR.20181229.56539.fits ... /koadata27/LRIS/20181229/lev0/LR.20181229.56539.fits
LB.20190304.33117.fits ... /koadata27/LRIS/20190304/lev0/LB.20190304.33117.fits
LR.20190304.33130.fits ... /koadata27/LRIS/20190304/lev0/LR.20190304.33130.fits
Length = 101 rows
In [15]:
query = "select koaid from " + koatable + " where (contains(point('J2000', ra, dec), box ('J2000'," + box_pos + "))=1)"
Koa.query_adql(query, outdir + instr + "_adql_radec.tbl", overwrite=True, format = 'ipac')
rec = Table.read(outdir + instr + "_adql_radec.tbl", format='ascii.ipac')
print(rec)
submitting request...
Result downloaded to file [./outputLR/lris_adql_radec.tbl]
        koaid         
----------------------
LB.20010529.20873.fits
LB.20010529.21063.fits
LB.20010529.21331.fits
LB.20010529.21738.fits
LB.20010529.21996.fits
LB.20010529.22312.fits
LB.20010529.23664.fits
LB.20010529.25022.fits
LB.20011211.57154.fits
LB.20020109.59153.fits
                   ...
LR.20100121.57297.fits
LR.20100121.57605.fits
LR.20120428.22909.fits
LR.20120428.23105.fits
LR.20180512.20205.fits
LR.20180512.20631.fits
LR.20180512.20857.fits
LR.20180512.21080.fits
LR.20181229.56431.fits
LR.20181229.56539.fits
LR.20190304.33130.fits
Length = 95 rows

Select top 10 records in a spatial box search with column selection; order results in descending UT time.

In [16]:
query =  "select top 10 koaid, ra ,dec, utdatetime from " + koatable + " where (contains(point('J2000',ra ,dec), box ('J2000', " + box_pos + "))) =1) order by utdatetime desc "
Koa.query_adql (query, \
    outdir + instr + "_adql_radec_top10.tbl",overwrite=True, format='ipac') 
rec = Table.read (outdir + instr + "_adql_radec_top10.tbl", format='ascii.ipac')
print (rec)
submitting request...
Result downloaded to file [./outputLR/lris_adql_radec_top10.tbl]
        koaid              ra      dec            utdatetime        
---------------------- --------- -------- --------------------------
LR.20011211.57151.fits 174.27205 29.79737 2001-12-11 15:52:31.920000
LR.20000106.50200.fits 174.27058 29.79872 2000-01-06 13:56:40.800000
LR.20000106.50061.fits 174.27058 29.79872 2000-01-06 13:54:21.660000
LR.20000106.49958.fits 174.27125 29.79944 2000-01-06 13:52:38.760000
LR.20000106.49902.fits 174.27125 29.79944 2000-01-06 13:51:42.660000
LR.19981223.58380.fits 174.27093 29.80023 1998-12-23 16:13:00.810000
LR.19981223.58152.fits 174.27093  29.8002 1998-12-23 16:09:12.210000
LR.19981223.57984.fits 174.27126 29.79706 1998-12-23 16:06:24.300000
LR.19981211.56259.fits 174.27472 29.80587 1998-12-11 15:37:39.240000
LR.19981211.56071.fits 174.27463 29.80587 1998-12-11 15:34:31.700000
In [17]:
query =  "select count(koaid) from " + koatable + " where (contains(point('J2000',ra ,dec), box ('J2000', " + box_pos + "))) =1)"
Koa.query_adql (query, outdir + instr + "_adql_count.tbl",overwrite=True, format='ipac') 
rec = Table.read (outdir + instr + "_adql_count.tbl", format='ascii.ipac')
print (rec)
submitting request...
Result downloaded to file [./outputLR/lris_adql_count.tbl]
count(koaid)
------------
          95
In [18]:
query = "select koaid, filehand, ra, dec from " + koatable + " where contains(point('icrs', ra, dec), polygon('icrs'," + polygon_pos + ")) = 1"
Koa.query_adql(query, outdir + instr + "_polygon.tbl", overwrite=True, format='ipac' )
rec = Table.read (outdir + instr + "_polygon.tbl", format='ascii.ipac')
print (rec)
submitting request...
Result downloaded to file [./outputLR/lris_polygon.tbl]
        koaid          ...   dec   
---------------------- ... --------
LB.20010529.20873.fits ... 30.00314
LB.20010529.21063.fits ... 30.00314
LB.20010529.21331.fits ... 29.99631
LB.20010529.21738.fits ...   29.996
LB.20010529.21996.fits ... 29.99589
LB.20010529.22312.fits ... 29.99603
LB.20010529.23664.fits ... 29.99608
LB.20010529.25022.fits ...   29.996
LB.20011211.57154.fits ... 29.79737
LB.20020109.59153.fits ... 29.80264
                   ... ...      ...
LR.20100121.57297.fits ... 29.79419
LR.20100121.57605.fits ... 29.78861
LR.20120428.22909.fits ... 29.79953
LR.20120428.23105.fits ... 29.79953
LR.20180512.20205.fits ... 29.79947
LR.20180512.20631.fits ... 29.79947
LR.20180512.20857.fits ... 29.79947
LR.20180512.21080.fits ... 29.79947
LR.20181229.56431.fits ... 29.79942
LR.20181229.56539.fits ... 29.79942
LR.20190304.33130.fits ... 29.94239
Length = 101 rows

Download Data

Download a subset of results from the "query by multiple parameters: instrument, date, and position" example above

Please note that if a file is already stored in your directory, it won't be overwritten

In [19]:
Koa.download (outdir + instr + "_parameters.tbl", \
    'ipac', \
    './dnload_dir1', \
    start_row=1, \
    end_row=3 )
Start downloading 3 FITS data you requested;
please check your outdir: ./dnload_dir1 for  progress.
A total of new 3 FITS files downloaded.

Download the full data set from the "query by multiple parameters: instrument, date, and position" example above

In [20]:
Koa.download (outdir + instr + "_parameters.tbl", \
    'ipac', \
    './dnload_dir2' )
Start downloading 9 FITS data you requested;
please check your outdir: ./dnload_dir2 for  progress.
A total of new 9 FITS files downloaded.

Download the science FITS files and any associated calibration files and calibration file lists from the "parameters.tbl" query

In [21]:
Koa.download (outdir + instr + "_parameters.tbl", \
    'ipac', \
    './dnload_dir3', \
    calibfile=1 )
 
Start downloading 9 FITS data you requested;
please check your outdir: ./dnload_dir3 for  progress.
A total of new 9 FITS files downloaded.
9 new calibration list downloaded.
30 new calibration FITS files downloaded.

Login access

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.

Note: if files have been downloaded already, they will not be downloaded again and overwritten.

In [22]:
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:

In [23]:
Koa.query_date (instr, \
    propdate, \
    outdir + instr + "_login.tbl", overwrite=True, format='ipac', \
    cookiepath='./tapcookie.txt' )
rec = Table.read (outdir + instr + "_login.tbl",format='ipac')
print (rec)

                    
submitting request...
Result downloaded to file [./outputLR/lris_login.tbl]
        koaid          instrume ...    semid     propint
                                ...                     
---------------------- -------- ... ------------ -------
LB.20170129.00309.fits LRISBLUE ... 2016b_u139la      18
LB.20170129.00379.fits LRISBLUE ... 2016b_u139la      18
LB.20170129.00451.fits LRISBLUE ... 2016b_u139la      18
LB.20170129.00521.fits LRISBLUE ... 2016b_u139la      18
LB.20170129.00591.fits LRISBLUE ... 2016b_u139la      18
LB.20170129.00661.fits LRISBLUE ... 2016b_u139la      18
LR.20170129.02305.fits     LRIS ... 2016b_u139la      18
LR.20170129.02469.fits     LRIS ... 2016b_u139la      18
LR.20170129.02558.fits     LRIS ... 2016b_u139la      18
LR.20170129.02648.fits     LRIS ... 2016b_u139la      18
                   ...      ... ...          ...     ...
LB.20170129.58687.fits LRISBLUE ... 2016b_u139la      18
LB.20170129.58857.fits LRISBLUE ... 2016b_u139la      18
LB.20170129.59025.fits LRISBLUE ... 2016b_u139la      18
LB.20170129.59201.fits LRISBLUE ... 2016b_u139la      18
LB.20170129.59340.fits LRISBLUE ... 2016b_u139la      18
LB.20170129.59445.fits LRISBLUE ... 2016b_u139la      18
LB.20170129.59525.fits LRISBLUE ... 2016b_u139la      18
LB.20170129.59593.fits LRISBLUE ... 2016b_u139la      18
LB.20170129.77314.fits LRISBLUE ...    2016b_eng      18
LR.20170129.77332.fits     LRIS ...    2016b_eng      18
Length = 247 rows

Visit KOA at https://koa.ipac.caltech.edu

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:

KOA Help Desk

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