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

May, 2021 - pykoa v1.4.5

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.

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)
 |  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 (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 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',
 |          datetime = '2018-03-16/2018-03-18' 
 |      
 |      e.g. 
 |          instrument = 'hires',
 |          datetime = '2018-03-16/' 
 |      
 |      e.g. 
 |          instrument = 'hires',
 |          datetime = '/2018-03-18' 
 |      
 |      e.g. 
 |          instrument = 'hires',
 |          datetime = '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 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

Create output directory

In [3]:
try:
    os.mkdir('./outputNI')
except:
    print(" Directory exists already", flush=True)

Anonymous access

Query by date range

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

In [5]:
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)
submitting request...
Result downloaded to file [./outputNI/NIRES_date.tbl]
        koaid          instrume   targname   ...   semid    propint
                                             ...                   
---------------------- -------- ------------ ... ---------- -------
NR.20181218.00486.fits    NIRES     K2 Fills ...  2018b_eng      18
NR.20181218.00650.fits    NIRES           -- ...  2018b_eng      18
NI.20181218.00833.fits    NIRES           -- ...  2018b_eng      18
NI.20181218.00884.fits    NIRES           -- ...  2018b_eng      18
NI.20181218.00900.fits    NIRES           -- ...  2018b_eng      18
NI.20181218.00920.fits    NIRES      unknown ...  2018b_eng      18
NI.20181218.01053.fits    NIRES      unknown ...  2018b_eng      18
NR.20181218.02875.fits    NIRES      unknown ...  2018b_eng      18
NR.20181218.06688.fits    NIRES      unknown ... 2018b_y025      18
NI.20181218.06720.fits    NIRES      unknown ... 2018b_y025      18
                   ...      ...          ... ...        ...     ...
NR.20181218.58232.fits    NIRES        GD153 ... 2018b_y025      18
NR.20181218.58315.fits    NIRES        GD153 ... 2018b_y025      18
NR.20181218.58369.fits    NIRES        GD153 ... 2018b_y025      18
NR.20181218.58431.fits    NIRES        GD153 ... 2018b_y025      18
NR.20181218.58486.fits    NIRES        GD153 ... 2018b_y025      18
NR.20181218.59684.fits    NIRES HORIZON STOW ...  2018b_eng      18
NR.20181218.61034.fits    NIRES HORIZON STOW ...  2018b_eng      18
NR.20181218.61377.fits    NIRES HORIZON STOW ...  2018b_eng      18
NR.20181218.61713.fits    NIRES HORIZON STOW ...  2018b_eng      18
NR.20181218.62049.fits    NIRES HORIZON STOW ...  2018b_eng      18
Length = 142 rows

Query by date range; output in VOTable format

In [7]:
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)
submitting request...
Result downloaded to file [./outputNI/nires_daterange.vot]
        koaid          instrume   targname   ...   semid    propint
---------------------- -------- ------------ ... ---------- -------
NR.20181218.00486.fits    NIRES     K2 Fills ...  2018b_eng      18
NR.20181218.00650.fits    NIRES              ...  2018b_eng      18
NI.20181218.00833.fits    NIRES              ...  2018b_eng      18
NI.20181218.00884.fits    NIRES              ...  2018b_eng      18
NI.20181218.00900.fits    NIRES              ...  2018b_eng      18
NI.20181218.00920.fits    NIRES      unknown ...  2018b_eng      18
NI.20181218.01053.fits    NIRES      unknown ...  2018b_eng      18
NR.20181218.02875.fits    NIRES      unknown ...  2018b_eng      18
NR.20181218.06688.fits    NIRES      unknown ... 2018b_y025      18
NI.20181218.06720.fits    NIRES      unknown ... 2018b_y025      18
                   ...      ...          ... ...        ...     ...
NI.20181219.07628.fits    NIRES      unknown ...  2018b_eng      18
NI.20181219.07645.fits    NIRES      unknown ...  2018b_eng      18
NR.20181219.07661.fits    NIRES      unknown ...  2018b_eng      18
NI.20181219.07695.fits    NIRES      unknown ...  2018b_eng      18
NI.20181219.07748.fits    NIRES      unknown ...  2018b_eng      18
NI.20181219.68151.fits    NIRES zenith  lock ...  2018b_eng      18
NI.20181219.68203.fits    NIRES zenith  lock ...  2018b_eng      18
NI.20181219.68214.fits    NIRES zenith  lock ...  2018b_eng      18
NI.20181219.83343.fits    NIRES zenith  lock ...  2018b_eng      18
NI.20181219.83395.fits    NIRES zenith  lock ...  2018b_eng      18
NI.20181219.83449.fits    NIRES zenith  lock ...  2018b_eng      18
Length = 154 rows

Query by date and time range; output in CSV format

In [8]:
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)
submitting request...
Result downloaded to file [./outputNI/nires_datetime.csv]
        koaid          instrume    targname    ...   semid    propint
---------------------- -------- -------------- ... ---------- -------
NR.20181218.54083.fits    NIRES UVISTA76774_S1 ... 2018b_y025      18
NR.20181218.54417.fits    NIRES UVISTA76774_S1 ... 2018b_y025      18
NR.20181218.54752.fits    NIRES UVISTA76774_S1 ... 2018b_y025      18
NR.20181218.55088.fits    NIRES UVISTA76774_S1 ... 2018b_y025      18
NI.20181218.55591.fits    NIRES        HP37074 ... 2018b_y025      18
NI.20181218.55629.fits    NIRES        HP37074 ... 2018b_y025      18
NI.20181218.55659.fits    NIRES        HP37074 ... 2018b_y025      18

Query by date range; output in TSV format

In [9]:
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)
submitting request...
Result downloaded to file [./outputNI/nires_date.tsv]
        koaid          instrume   targname   ...   semid   propint
---------------------- -------- ------------ ... --------- -------
NI.20181219.01294.fits    NIRES     K2 Fills ... 2018b_eng      18
NI.20181219.07628.fits    NIRES      unknown ... 2018b_eng      18
NI.20181219.07645.fits    NIRES      unknown ... 2018b_eng      18
NR.20181219.07661.fits    NIRES      unknown ... 2018b_eng      18
NI.20181219.07695.fits    NIRES      unknown ... 2018b_eng      18
NI.20181219.07748.fits    NIRES      unknown ... 2018b_eng      18
NI.20181219.68151.fits    NIRES zenith  lock ... 2018b_eng      18
NI.20181219.68203.fits    NIRES zenith  lock ... 2018b_eng      18
NI.20181219.68214.fits    NIRES zenith  lock ... 2018b_eng      18
NI.20181219.83343.fits    NIRES zenith  lock ... 2018b_eng      18
NI.20181219.83395.fits    NIRES zenith  lock ... 2018b_eng      18
NI.20181219.83449.fits    NIRES zenith  lock ... 2018b_eng      18

Query by position

In [11]:
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)
submitting request...
Result downloaded to file [./outputNI/position_search.tbl]
        koaid          instrume targname ...   semid    propint
                                         ...                   
---------------------- -------- -------- ... ---------- -------
NI.20180131.55969.fits    NIRES    GD153 ...  2017b_eng      18
NI.20180131.55991.fits    NIRES    GD153 ...  2017b_eng      18
NI.20180131.56045.fits    NIRES    GD153 ...  2017b_eng      18
NI.20180131.56327.fits    NIRES    GD153 ...  2017b_eng      18
NR.20180131.56391.fits    NIRES    GD153 ...  2017b_eng      18
NI.20180131.56391.fits    NIRES    GD153 ...  2017b_eng      18
NR.20180131.56724.fits    NIRES    GD153 ...  2017b_eng      18
NI.20180131.56724.fits    NIRES    GD153 ...  2017b_eng      18
NI.20180131.57056.fits    NIRES    GD153 ...  2017b_eng      18
NR.20180131.57056.fits    NIRES    GD153 ...  2017b_eng      18
                   ...      ...      ... ...        ...     ...
NR.20190519.17849.fits    NIRES    GD153 ... 2019a_u137      18
NR.20190519.17955.fits    NIRES    GD153 ... 2019a_u137      18
NR.20190519.17972.fits    NIRES    GD153 ... 2019a_u137      18
NI.20190519.31022.fits    NIRES    GD153 ... 2019a_u137      18
NR.20190519.31091.fits    NIRES    GD153 ... 2019a_u137      18
NI.20190519.31141.fits    NIRES    GD153 ... 2019a_u137      18
NR.20190519.31329.fits    NIRES    GD153 ... 2019a_u137      18
NR.20190519.31562.fits    NIRES    GD153 ... 2019a_u137      18
NR.20190519.31798.fits    NIRES    GD153 ... 2019a_u137      18
NI.20190519.32059.fits    NIRES    GD153 ... 2019a_u137      18
Length = 117 rows

Query by object

In [12]:
Koa.query_object ('nires', \
                  'GD153', './outputNI/GD153.tbl', overwrite=True, format='ipac')

rec = Table.read ('./outputNI/GD153.tbl', format='ascii.ipac')
print (rec)
object name resolved: ra2000= 194.25967703, dec2000=22.03128733
submitting request...
Result downloaded to file [./outputNI/GD153.tbl]
        koaid          instrume targname ...   semid    propint
                                         ...                   
---------------------- -------- -------- ... ---------- -------
NI.20180131.55969.fits    NIRES    GD153 ...  2017b_eng      18
NI.20180131.55991.fits    NIRES    GD153 ...  2017b_eng      18
NI.20180131.56045.fits    NIRES    GD153 ...  2017b_eng      18
NI.20180131.56327.fits    NIRES    GD153 ...  2017b_eng      18
NR.20180131.56391.fits    NIRES    GD153 ...  2017b_eng      18
NI.20180131.56391.fits    NIRES    GD153 ...  2017b_eng      18
NR.20180131.56724.fits    NIRES    GD153 ...  2017b_eng      18
NI.20180131.56724.fits    NIRES    GD153 ...  2017b_eng      18
NI.20180131.57056.fits    NIRES    GD153 ...  2017b_eng      18
NR.20180131.57056.fits    NIRES    GD153 ...  2017b_eng      18
                   ...      ...      ... ...        ...     ...
NR.20190519.17849.fits    NIRES    GD153 ... 2019a_u137      18
NR.20190519.17955.fits    NIRES    GD153 ... 2019a_u137      18
NR.20190519.17972.fits    NIRES    GD153 ... 2019a_u137      18
NI.20190519.31022.fits    NIRES    GD153 ... 2019a_u137      18
NR.20190519.31091.fits    NIRES    GD153 ... 2019a_u137      18
NI.20190519.31141.fits    NIRES    GD153 ... 2019a_u137      18
NR.20190519.31329.fits    NIRES    GD153 ... 2019a_u137      18
NR.20190519.31562.fits    NIRES    GD153 ... 2019a_u137      18
NR.20190519.31798.fits    NIRES    GD153 ... 2019a_u137      18
NI.20190519.32059.fits    NIRES    GD153 ... 2019a_u137      18
Length = 117 rows

Query for program information

In [13]:
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)
submitting request...
Result downloaded to file [./outputNI/program_info.tbl]
        koaid          ... progid
---------------------- ... ------
NI.20181218.06720.fits ...   Y025
NI.20181218.38030.fits ...   Y025
NI.20181218.38072.fits ...   Y025
NI.20181218.38931.fits ...   Y025
NI.20181218.41511.fits ...   Y025
NI.20181218.41553.fits ...   Y025
NI.20181218.41699.fits ...   Y025
NI.20181218.41782.fits ...   Y025
NI.20181218.43651.fits ...   Y025
NI.20181218.45361.fits ...   Y025
                   ... ...    ...
NR.20181229.59273.fits ...   Y025
NR.20181229.59496.fits ...   Y025
NR.20181229.59633.fits ...   Y025
NR.20181229.59769.fits ...   Y025
NR.20181230.38256.fits ...   Y025
NR.20181230.38374.fits ...   Y025
NR.20181230.38492.fits ...   Y025
NR.20181230.38610.fits ...   Y025
NR.20181230.38727.fits ...   Y025
NR.20181230.38946.fits ...   Y025
NR.20181230.39082.fits ...   Y025
Length = 545 rows

Query by instrument, date, and position

In [14]:
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)
submitting request...
Result downloaded to file [./outputNI/parameters.tbl]
        koaid          instrume targname ...   semid    propint
                                         ...                   
---------------------- -------- -------- ... ---------- -------
NI.20181218.55591.fits    NIRES  HP37074 ... 2018b_y025      18
NI.20181218.55629.fits    NIRES  HP37074 ... 2018b_y025      18
NI.20181218.55659.fits    NIRES  HP37074 ... 2018b_y025      18
NI.20181218.55879.fits    NIRES  HP37074 ... 2018b_y025      18
NI.20181218.55920.fits    NIRES  HP37074 ... 2018b_y025      18
NI.20181218.55955.fits    NIRES  HP37074 ... 2018b_y025      18
NI.20181218.56004.fits    NIRES  HP37074 ... 2018b_y025      18
NI.20181218.56119.fits    NIRES  HP37074 ... 2018b_y025      18
NR.20181218.56226.fits    NIRES  HP37074 ... 2018b_y025      18
NR.20181218.56245.fits    NIRES  HP37074 ... 2018b_y025      18
NR.20181218.56264.fits    NIRES  HP37074 ... 2018b_y025      18
NR.20181218.56283.fits    NIRES  HP37074 ... 2018b_y025      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 [15]:
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)
submitting request...
Result downloaded to file [./outputNI/adql_cone.tbl]
        koaid          ...                        filehand                      
                       ...                                                      
---------------------- ... -----------------------------------------------------
NI.20180131.55969.fits ... /koadata32/NIRES/20180131/lev0/NI.20180131.55969.fits
NI.20180131.55991.fits ... /koadata32/NIRES/20180131/lev0/NI.20180131.55991.fits
NI.20180131.56045.fits ... /koadata32/NIRES/20180131/lev0/NI.20180131.56045.fits
NI.20180131.56327.fits ... /koadata32/NIRES/20180131/lev0/NI.20180131.56327.fits
NR.20180131.56391.fits ... /koadata32/NIRES/20180131/lev0/NR.20180131.56391.fits
NI.20180131.56391.fits ... /koadata32/NIRES/20180131/lev0/NI.20180131.56391.fits
NR.20180131.56724.fits ... /koadata32/NIRES/20180131/lev0/NR.20180131.56724.fits
NI.20180131.56724.fits ... /koadata32/NIRES/20180131/lev0/NI.20180131.56724.fits
NI.20180131.57056.fits ... /koadata32/NIRES/20180131/lev0/NI.20180131.57056.fits
NR.20180131.57056.fits ... /koadata32/NIRES/20180131/lev0/NR.20180131.57056.fits
                   ... ...                                                   ...
NR.20190519.17849.fits ... /koadata32/NIRES/20190519/lev0/NR.20190519.17849.fits
NR.20190519.17955.fits ... /koadata32/NIRES/20190519/lev0/NR.20190519.17955.fits
NR.20190519.17972.fits ... /koadata32/NIRES/20190519/lev0/NR.20190519.17972.fits
NI.20190519.31022.fits ... /koadata32/NIRES/20190519/lev0/NI.20190519.31022.fits
NR.20190519.31091.fits ... /koadata32/NIRES/20190519/lev0/NR.20190519.31091.fits
NI.20190519.31141.fits ... /koadata32/NIRES/20190519/lev0/NI.20190519.31141.fits
NR.20190519.31329.fits ... /koadata32/NIRES/20190519/lev0/NR.20190519.31329.fits
NR.20190519.31562.fits ... /koadata32/NIRES/20190519/lev0/NR.20190519.31562.fits
NR.20190519.31798.fits ... /koadata32/NIRES/20190519/lev0/NR.20190519.31798.fits
NI.20190519.32059.fits ... /koadata32/NIRES/20190519/lev0/NI.20190519.32059.fits
Length = 117 rows
In [16]:
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)
submitting request...
Result downloaded to file [./outputNI/adql_radec.tbl]
        koaid         
----------------------
NI.20180131.55969.fits
NI.20180131.55991.fits
NI.20180131.56045.fits
NI.20180131.56327.fits
NI.20180131.56391.fits
NI.20180131.56724.fits
NI.20180131.57056.fits
NI.20180131.57390.fits
NI.20181218.56718.fits
NI.20181218.56785.fits
                   ...
NR.20190519.17611.fits
NR.20190519.17731.fits
NR.20190519.17757.fits
NR.20190519.17822.fits
NR.20190519.17849.fits
NR.20190519.17955.fits
NR.20190519.17972.fits
NR.20190519.31091.fits
NR.20190519.31329.fits
NR.20190519.31562.fits
NR.20190519.31798.fits
Length = 117 rows

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

In [17]:
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)
submitting request...
Result downloaded to file [./outputNI/adql_radec.tbl]
        koaid              ra      dec            utdatetime        
---------------------- --------- -------- --------------------------
NI.20190416.25682.fits 194.26004 22.03027 2019-04-16 07:08:02.500000
NI.20190416.25654.fits 194.26004 22.03027 2019-04-16 07:07:34.960000
NI.20190416.25486.fits 194.26009 22.03305 2019-04-16 07:04:46.150000
NI.20190416.25135.fits 194.26009 22.03305 2019-04-16 06:58:55.270000
NI.20190416.24504.fits 194.26007 22.03166 2019-04-16 06:48:24.400000
NI.20190416.24438.fits 194.25919 22.03168 2019-04-16 06:47:18.610000
NI.20190416.24366.fits 194.26308 22.03444 2019-04-16 06:46:06.700000
NI.20190416.24345.fits 194.26009 22.03167 2019-04-16 06:45:45.280000
NI.20190416.24301.fits 194.26009 22.03167 2019-04-16 06:45:01.930000
NI.20190416.24263.fits 194.25975 22.03131 2019-04-16 06:44:23.680000
In [18]:
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)
submitting request...
Result downloaded to file [./outputNI/adql_count.tbl]
count(koaid)
------------
         117
In [20]:
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)
submitting request...
Result downloaded to file [./outputNI/polygon_os.tbl]
        koaid          ...   dec   
---------------------- ... --------
NI.20180131.55969.fits ... 22.03131
NI.20180131.55991.fits ... 22.03131
NI.20180131.56045.fits ... 22.03038
NI.20180131.56327.fits ... 22.03038
NI.20180131.56391.fits ...  22.0304
NI.20180131.56724.fits ... 22.03036
NI.20180131.57056.fits ... 22.03036
NI.20180131.57390.fits ...  22.0304
NI.20181218.56718.fits ... 22.03128
NI.20181218.56785.fits ... 22.03233
                   ... ...      ...
NR.20190519.17611.fits ... 22.03126
NR.20190519.17731.fits ... 22.03136
NR.20190519.17757.fits ... 22.03126
NR.20190519.17822.fits ... 22.03135
NR.20190519.17849.fits ... 22.03126
NR.20190519.17955.fits ... 22.03135
NR.20190519.17972.fits ... 22.03126
NR.20190519.31091.fits ... 22.03135
NR.20190519.31329.fits ... 22.03133
NR.20190519.31562.fits ... 22.03133
NR.20190519.31798.fits ... 22.03135
Length = 117 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 [21]:
Koa.download ('./outputNI/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 [22]:
Koa.download ('./outputNI/parameters.tbl', \
               'ipac', \
               './dnload_dir2')                   
Start downloading 12 FITS data you requested;
please check your outdir: ./dnload_dir2 for  progress.
A total of new 12 FITS files downloaded.

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

In [21]:
Koa.download ('./outputNI/parameters.tbl',  
    'ipac', \
    './dnload_dir3',
     calibfile=1)
 
Start downloading 12 FITS data you requested;
please check your outdir: ./dnload_dir3 for  progress.
A total of new 12 FITS files downloaded.
12 new calibration list downloaded.
20 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 [ ]:
Koa.login ('./tapcookie.txt')

Include the cookiepath in your query to access your data, as in this example:

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

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