Keck Observatory Archive (KOA) Python Client - Tutorial: Access to KCWI 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 KCWI intrgral field spectrograph instrument 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 [2]:
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 [7]:
try:
    os.mkdir('./outputKC')
except:
    print(" Directory exists already", flush=True)
 Directory exists already

Anonymous access

Query by date range

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

In [15]:
Koa.query_date ( 'kcwi', '2019-05-09', \
    './outputKC/KCWI_date.tbl', overwrite=True, format='ipac' )

rec = Table.read ('./outputKC/KCWI_date.tbl',format='ipac')
print (rec)
submitting request...
Result downloaded to file [./outputKC/KCWI_date.tbl]
        koaid          instrume    targname   ...   semid    propint
---------------------- -------- ------------- ... ---------- -------
KB.20190509.07554.fits     KCWI    DOME PHLAT ... 2019a_c257      18
KF.20190509.07636.fits     KCWI    DOME PHLAT ... 2019a_c257      18
KB.20190509.08692.fits     KCWI    DOME PHLAT ... 2019a_c257      18
KB.20190509.08718.fits     KCWI    DOME PHLAT ... 2019a_c257      18
KB.20190509.08743.fits     KCWI    DOME PHLAT ... 2019a_c257      18
KB.20190509.08770.fits     KCWI    DOME PHLAT ... 2019a_c257      18
KB.20190509.08795.fits     KCWI    DOME PHLAT ... 2019a_c257      18
KB.20190509.08821.fits     KCWI    DOME PHLAT ... 2019a_c257      18
KB.20190509.08846.fits     KCWI    DOME PHLAT ... 2019a_c257      18
KB.20190509.08872.fits     KCWI    DOME PHLAT ... 2019a_c257      18
                   ...      ...           ... ...        ...     ...
KB.20190509.43726.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.44532.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.45547.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.46882.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.48252.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.49553.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.49694.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.49752.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.49811.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.49876.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.49934.fits     KCWI HS1700+6416_C ... 2019a_c257      18
Length = 96 rows

Query by date range; output in VOTable format

In [ ]:
Koa.query_date ('kcwi', \
    '2019-05-08/2019-05-12', \
    './outputKC/kcwi_daterange.vot', overwrite=True, format='votable')

rec = Table.read ('./outputKC/kcwi_daterange.vot',format='votable')
print (rec)

Query by date and time range; output in CSV format

In [17]:
Koa.query_datetime ('kcwi', \
    '2019-05-09 02:00:00/2019-05-09 08:00:00', \
    './outputKC/kcwi_datetime.csv', overwrite=True, format='csv' )


rec = Table.read ('./outputKC/kcwi_datetime.csv',format='csv')
print (rec)
submitting request...
Result downloaded to file [./outputKC/kcwi_datetime.csv]
        koaid          instrume     targname    ...   semid    propint
---------------------- -------- --------------- ... ---------- -------
KB.20190509.07554.fits     KCWI      DOME PHLAT ... 2019a_c257      18
KF.20190509.07636.fits     KCWI      DOME PHLAT ... 2019a_c257      18
KB.20190509.08692.fits     KCWI      DOME PHLAT ... 2019a_c257      18
KB.20190509.08718.fits     KCWI      DOME PHLAT ... 2019a_c257      18
KB.20190509.08743.fits     KCWI      DOME PHLAT ... 2019a_c257      18
KB.20190509.08770.fits     KCWI      DOME PHLAT ... 2019a_c257      18
KB.20190509.08795.fits     KCWI      DOME PHLAT ... 2019a_c257      18
KB.20190509.08821.fits     KCWI      DOME PHLAT ... 2019a_c257      18
KB.20190509.08846.fits     KCWI      DOME PHLAT ... 2019a_c257      18
KB.20190509.08872.fits     KCWI      DOME PHLAT ... 2019a_c257      18
                   ...      ...             ... ...        ...     ...
KB.20190509.19815.fits     KCWI         Feige34 ... 2019a_c257      18
KB.20190509.19898.fits     KCWI         Feige34 ... 2019a_c257      18
KB.20190509.19959.fits     KCWI         Feige34 ... 2019a_c257      18
KB.20190509.21608.fits     KCWI SDSS1112+1521_A ... 2019a_c257      18
KB.20190509.22869.fits     KCWI SDSS1112+1521_A ... 2019a_c257      18
KB.20190509.24293.fits     KCWI SDSS1112+1521_A ... 2019a_c257      18
KB.20190509.24949.fits     KCWI SDSS1112+1521_A ... 2019a_c257      18
KF.20190509.25327.fits     KCWI       122784302 ... 2019a_c257      18
KF.20190509.25416.fits     KCWI       122784302 ... 2019a_c257      18
KB.20190509.26811.fits     KCWI SDSS1112+1521_B ... 2019a_c257      18
KB.20190509.28148.fits     KCWI SDSS1112+1521_B ... 2019a_c257      18
Length = 69 rows

Query by date range; output in TSV format

In [19]:
Koa.query_date ('kcwi', \
    '2019-05-09', \
    './outputKC/kcwi_date.tsv', overwrite=True, format='tsv' )

rec = Table.read ('./outputKC/kcwi_date.tsv',format='ascii.fast_tab')
print (rec)
submitting request...
Result downloaded to file [./outputKC/kcwi_date.tsv]
        koaid          instrume    targname   ...   semid    propint
---------------------- -------- ------------- ... ---------- -------
KB.20190509.07554.fits     KCWI    DOME PHLAT ... 2019a_c257      18
KF.20190509.07636.fits     KCWI    DOME PHLAT ... 2019a_c257      18
KB.20190509.08692.fits     KCWI    DOME PHLAT ... 2019a_c257      18
KB.20190509.08718.fits     KCWI    DOME PHLAT ... 2019a_c257      18
KB.20190509.08743.fits     KCWI    DOME PHLAT ... 2019a_c257      18
KB.20190509.08770.fits     KCWI    DOME PHLAT ... 2019a_c257      18
KB.20190509.08795.fits     KCWI    DOME PHLAT ... 2019a_c257      18
KB.20190509.08821.fits     KCWI    DOME PHLAT ... 2019a_c257      18
KB.20190509.08846.fits     KCWI    DOME PHLAT ... 2019a_c257      18
KB.20190509.08872.fits     KCWI    DOME PHLAT ... 2019a_c257      18
                   ...      ...           ... ...        ...     ...
KB.20190509.43726.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.44532.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.45547.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.46882.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.48252.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.49553.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.49694.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.49752.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.49811.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.49876.fits     KCWI HS1700+6416_C ... 2019a_c257      18
KB.20190509.49934.fits     KCWI HS1700+6416_C ... 2019a_c257      18
Length = 96 rows

Query by position

In [20]:
Koa.query_position ('kcwi', \
                  'circle 159.90296, 43.10281 0.5', \
                  './outputKC/position_search.tbl', overwrite=True )

rec = Table.read ('./outputKC/position_search.tbl', format='ascii.ipac')
print (rec)
submitting request...
Result downloaded to file [./outputKC/position_search.tbl]
        koaid          instrume targname ...   semid    propint
---------------------- -------- -------- ... ---------- -------
KB.20171123.56727.fits     KCWI  feige34 ... 2017b_u095      18
KB.20171123.57000.fits     KCWI  feige34 ... 2017b_u095      18
KB.20171124.57171.fits     KCWI  feige34 ... 2017b_u095      18
KB.20171124.57380.fits     KCWI  feige34 ... 2017b_u095      18
KB.20171124.57601.fits     KCWI  feige34 ... 2017b_u095      18
KB.20171225.45861.fits     KCWI feige 34 ... 2017b_u155      18
KB.20171225.46079.fits     KCWI feige 34 ... 2017b_u155      18
KB.20171225.46485.fits     KCWI feige 34 ... 2017b_u155      18
KB.20171225.46542.fits     KCWI feige 34 ... 2017b_u155      18
KB.20171225.46600.fits     KCWI feige 34 ... 2017b_u155      18
                   ...      ...      ... ...        ...     ...
KB.20191029.55801.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191029.56006.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191029.56158.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191029.56352.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191029.56555.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191029.56753.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191029.56946.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191029.57200.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191029.57395.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191031.55873.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191031.55947.fits     KCWI  Feige34 ... 2019b_u216      18
Length = 141 rows

Query by object

In [21]:
Koa.query_object ('kcwi', \
                  'feige34', './outputKC/feige34.tbl', overwrite=True, format='ipac' )

rec = Table.read ('./outputKC/feige34.tbl', format='ascii.ipac')
print (rec)
object name resolved: ra2000= 159.90307379, dec2000=43.10255826
submitting request...
Result downloaded to file [./outputKC/feige34.tbl]
        koaid          instrume targname ...   semid    propint
---------------------- -------- -------- ... ---------- -------
KB.20171123.56727.fits     KCWI  feige34 ... 2017b_u095      18
KB.20171123.57000.fits     KCWI  feige34 ... 2017b_u095      18
KB.20171124.57171.fits     KCWI  feige34 ... 2017b_u095      18
KB.20171124.57380.fits     KCWI  feige34 ... 2017b_u095      18
KB.20171124.57601.fits     KCWI  feige34 ... 2017b_u095      18
KB.20171225.45861.fits     KCWI feige 34 ... 2017b_u155      18
KB.20171225.46079.fits     KCWI feige 34 ... 2017b_u155      18
KB.20171225.46485.fits     KCWI feige 34 ... 2017b_u155      18
KB.20171225.46542.fits     KCWI feige 34 ... 2017b_u155      18
KB.20171225.46600.fits     KCWI feige 34 ... 2017b_u155      18
                   ...      ...      ... ...        ...     ...
KB.20191029.55801.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191029.56006.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191029.56158.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191029.56352.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191029.56555.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191029.56753.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191029.56946.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191029.57200.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191029.57395.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191031.55873.fits     KCWI  Feige34 ... 2019b_u216      18
KB.20191031.55947.fits     KCWI  Feige34 ... 2019b_u216      18
Length = 141 rows

Query for program information

In [22]:
query ="select koaid, filehand, progid from koa_kcwi where (progid = 'U216') " 

Koa.query_adql (query, \
    './outputKC/program_info.tbl', overwrite=True, format='ipac')

rec = Table.read('./outputKC/program_info.tbl', format='ascii.ipac')
print (rec)
submitting request...
Result downloaded to file [./outputKC/program_info.tbl]
        koaid          ... progid
---------------------- ... ------
KB.20191029.02565.fits ...   U216
KB.20191029.02592.fits ...   U216
KB.20191029.02621.fits ...   U216
KB.20191029.02648.fits ...   U216
KB.20191029.02676.fits ...   U216
KB.20191029.02704.fits ...   U216
KB.20191029.02732.fits ...   U216
KB.20191029.02761.fits ...   U216
KB.20191029.02789.fits ...   U216
KB.20191029.04150.fits ...   U216
                   ... ...    ...
KB.20191101.46716.fits ...   U216
KB.20191101.47975.fits ...   U216
KB.20191101.49236.fits ...   U216
KB.20191101.50496.fits ...   U216
KB.20191101.51753.fits ...   U216
KB.20191101.53021.fits ...   U216
KF.20191029.01516.fits ...   U216
KF.20191029.16281.fits ...   U216
KF.20191029.16402.fits ...   U216
KF.20191029.79371.fits ...   U216
KF.20191030.83125.fits ...   U216
Length = 357 rows

Query by instrument, date, and position

In [23]:
param = dict()
param['instrument'] = 'kcwi'
param['date'] = '2019-05-09'
param['target'] = 'Feige34'

Koa.query_criteria (param, \
                  './outputKC/parameters.tbl', overwrite=True )

rec = Table.read('./outputKC/parameters.tbl', format='ipac')
print (rec)
submitting request...
Result downloaded to file [./outputKC/parameters.tbl]
        koaid          instrume  targname ...   semid    propint
---------------------- -------- --------- ... ---------- -------
KF.20190509.18675.fits     KCWI 156752043 ... 2019a_c257      18
KF.20190509.18849.fits     KCWI 156752043 ... 2019a_c257      18
KF.20190509.18929.fits     KCWI 156752043 ... 2019a_c257      18
KB.20190509.19738.fits     KCWI   Feige34 ... 2019a_c257      18
KB.20190509.19815.fits     KCWI   Feige34 ... 2019a_c257      18
KB.20190509.19898.fits     KCWI   Feige34 ... 2019a_c257      18
KB.20190509.19959.fits     KCWI   Feige34 ... 2019a_c257      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 [24]:
query =  "select koaid, object, koaimtyp, frameno, ra, dec,  \
            to_char(date_obs,'YYYY-MM-DD') as date_obs, elaptime, \
            waveblue, wavered, camera, bgratnam, bfiltnam, ifunam, stateid, statenam, \
            progid, proginst,  progpi, progtitl, semester, ofname, filehand \
            from koa_kcwi \
            where (contains(point('J2000',ra ,dec), circle('J2000', 23.48 ,30.60, 2))=1) \
            order by utdatetime"


Koa.query_adql(query,'./outputKC/adql_cone.tbl', overwrite=True, format='ipac')

rec = Table.read ('./outputKC/adql_cone.tbl', format='ascii.ipac')
print (rec)
submitting request...
Result downloaded to file [./outputKC/adql_cone.tbl]
        koaid          ...                       filehand                      
                       ...                                                     
---------------------- ... ----------------------------------------------------
KB.20191007.19853.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.19853.fits
KB.20191007.20637.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.20637.fits
KB.20191007.21303.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.21303.fits
KB.20191007.22362.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.22362.fits
KB.20191007.23112.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.23112.fits
KB.20191007.23772.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.23772.fits
KB.20191007.24613.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.24613.fits
KB.20191007.25504.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.25504.fits
KB.20191007.26159.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.26159.fits
KB.20191007.26883.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.26883.fits
                   ... ...                                                  ...
KB.20191007.47014.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.47014.fits
KB.20191007.47783.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.47783.fits
KB.20191007.48477.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.48477.fits
KB.20191007.49134.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.49134.fits
KB.20191007.49836.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.49836.fits
KB.20191007.50501.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.50501.fits
KB.20191007.51157.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.51157.fits
KB.20191007.51815.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.51815.fits
KB.20191007.52473.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.52473.fits
KB.20191007.53013.fits ... /koadata28/KCWI/20191007/lev0/KB.20191007.53013.fits
Length = 46 rows
In [25]:
query =  "select koaid from koa_kcwi where \
           (contains(point('J2000',ra ,dec), box('J2000', 23.48 ,30.60, 2, 2))=1) "

Koa.query_adql (query, './outputKC/adql_radec.tbl',overwrite=True, \
    format='ipac' )

    
rec = Table.read ('./outputKC/adql_radec.tbl', format='ascii.ipac')
print (rec)
submitting request...
Result downloaded to file [./outputKC/adql_radec.tbl]
        koaid         
----------------------
KB.20191007.19853.fits
KB.20191007.20637.fits
KB.20191007.21303.fits
KB.20191007.22362.fits
KB.20191007.23112.fits
KB.20191007.23772.fits
KB.20191007.24613.fits
KB.20191007.25504.fits
KB.20191007.26159.fits
KB.20191007.26883.fits
                   ...
KB.20191007.46353.fits
KB.20191007.47014.fits
KB.20191007.47783.fits
KB.20191007.48477.fits
KB.20191007.49134.fits
KB.20191007.49836.fits
KB.20191007.50501.fits
KB.20191007.51157.fits
KB.20191007.51815.fits
KB.20191007.52473.fits
KB.20191007.53013.fits
Length = 46 rows

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

In [26]:
query =  "select top 10 koaid, ra ,dec, utdatetime from koa_kcwi \
           where (contains(point('J2000',ra ,dec),  \
           box('J2000', 23.48 ,30.60, 2, 2))) =1) order by utdatetime desc "
Koa.query_adql (query, \
    './outputKC/adql_radec.tbl',overwrite=True, \
    format='ipac')

rec = Table.read ('./outputKC/adql_radec.tbl', format='ascii.ipac')
print (rec)
submitting request...
Result downloaded to file [./outputKC/adql_radec.tbl]
        koaid             ra      dec            utdatetime        
---------------------- -------- -------- --------------------------
KB.20191007.31826.fits 23.45175  30.6635 2019-10-07 08:50:26.580000
KB.20191007.30307.fits 23.39008 30.69117 2019-10-07 08:25:07.800000
KB.20191007.27761.fits 23.39079 30.68828 2019-10-07 07:42:41.880000
KB.20191007.26883.fits 23.39471 30.69333 2019-10-07 07:28:03.660000
KB.20191007.25504.fits 23.39008 30.69117 2019-10-07 07:05:04.620000
KB.20191007.24613.fits 23.38512 30.69108 2019-10-07 06:50:13.140000
KB.20191007.23112.fits 23.38592 30.69642 2019-10-07 06:25:12.720000
KB.20191007.22362.fits 23.39008 30.69642        2019-10-07 06:12:42
KB.20191007.20637.fits 23.39471 30.69856 2019-10-07 05:43:57.060000
KB.20191007.19853.fits 23.39058 30.70153 2019-10-07 05:30:53.820000
In [27]:
query =  "select count(koaid) from koa_kcwi \
    where (contains(point('J2000',ra,dec), box('J2000', 23.48 ,30.60, 2, 2)))=1) "

Koa.query_adql (query, \
    './outputKC/adql_count.tbl',overwrite=True, \
    format='ipac')

rec = Table.read ('./outputKC/adql_count.tbl', format='ascii.ipac')
print (rec)
submitting request...
Result downloaded to file [./outputKC/adql_count.tbl]
count(koaid)
------------
          46
In [28]:
query = "select koaid, filehand, ra, dec from koa_kcwi\
        where contains(point('icrs', ra, dec), \
        polygon('icrs',160.0, 43.2, 160.0, 43.0, 159.8, 43.0, 159.8, 43.2)) = 1"

Koa.query_adql(query, './outputKC/polygon_os.tbl', overwrite=True, format='ipac' )

rec = Table.read ('./outputKC/polygon_os.tbl', format='ascii.ipac')
print (rec)
submitting request...
Result downloaded to file [./outputKC/polygon_os.tbl]
        koaid          ...   dec   
---------------------- ... --------
KB.20171123.56727.fits ... 43.10178
KB.20171123.57000.fits ... 43.10297
KB.20171124.57171.fits ... 43.10244
KB.20171124.57380.fits ... 43.10244
KB.20171124.57601.fits ... 43.10244
KB.20171225.45861.fits ... 43.10192
KB.20171225.46079.fits ... 43.10192
KB.20171225.46485.fits ... 43.10192
KB.20171225.46542.fits ... 43.10192
KB.20171225.46600.fits ... 43.10192
                   ... ...      ...
KB.20191029.55801.fits ... 43.10281
KB.20191029.56006.fits ... 43.11114
KB.20191029.56158.fits ... 43.11114
KB.20191029.56352.fits ... 43.11114
KB.20191029.56555.fits ... 43.11114
KB.20191029.56753.fits ... 43.11114
KB.20191029.56946.fits ... 43.11114
KB.20191029.57200.fits ... 43.11114
KB.20191029.57395.fits ... 43.11114
KB.20191031.55873.fits ... 43.10281
KB.20191031.55947.fits ... 43.10281
Length = 138 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 [29]:
Koa.download ('./outputKC/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 [30]:
Koa.download ('./outputKC/parameters.tbl', \
               'ipac', \
               './dnload_dir2')                   
Start downloading 7 FITS data you requested;
please check your outdir: ./dnload_dir2 for  progress.
A total of new 7 FITS files downloaded.

Download three science FITS files from Query by instrument, date, and position

In [31]:
Koa.download ('./outputKC/parameters.tbl',  
    'ipac', \
    'dnload_dir3',  \
   start_row=0, \
    end_row=2)
Start downloading 3 FITS data you requested;
please check your outdir: dnload_dir3 for  progress.
A total of new 3 FITS files downloaded.

Download four science FITS files (rows 3 and up from parameters.tbl) and all associated calibration files and calibration file lists from the "parameters.tbl" query

In [32]:
Koa.download ('./outputKC/parameters.tbl',  
    'ipac', \
    'dnload_dir4',  \
     start_row=3, \
     calibfile=1)
 
Start downloading 4 FITS data you requested;
please check your outdir: dnload_dir4 for  progress.
A total of new 4 FITS files downloaded.
4 new calibration list downloaded.
89 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 ('kcwi', \
    '2019-05-09', \
    './outputKC/kcwi_login.tbl', overwrite=True, format='ipac', \
    cookiepath='./tapcookie.txt' )

rec = Table.read ('./outputKC/kcwi_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