#!/usr/bin/env python # coding: utf-8 # This notebook is a brief guide of downloading KPF raw (level 0) data # in a given period. It requires PI credentials to access proprietary # data. For more detail about PyKOA, please see: # http://koa.ipac.caltech.edu/UserGuide/PyKOA/notebooks/PyKOA_KPF_introduction.html # First, we need to install the KOA python client PyKOA. This line can # be removed if PyKOA is already installed. # In[1]: get_ipython().system('pip install pykoa') # The next steop is to import pre-requisite packages # In[2]: import sys import io import os from pykoa.koa import Koa from astropy.table import Table,Column # Then we need to assign directory that stores the query results: # In[3]: try: os.mkdir('./output') except: print(" Directory exists already", flush=True) # After that, we use a cookie for KOA log in. We can also spell out # the credentials, but for security purpose, it is better to enter the # userid and password interactively # In[4]: Koa.login ('./tapcookie.txt') #Koa.login ('./tapcookie.txt', userid='clee', password='salami') # We can then proceed to query KPF data taken in a given period. Note # the time period is specified in UT date. The output table will be # saved in the designated directory and in IPAC table format. # In[5]: Koa.query_datetime ('kpf', \ '2023-05-30 00:00:00/2023-05-30 23:59:59', \ './output/kpf_daterange.tbl', overwrite=True, format='ipac', \ cookiepath='./tapcookie.txt') rec = Table.read ('./output/kpf_daterange.tbl',format='ipac') print (rec) # Once we have the query result, we can download files to the # designated directory, in this case to dnload_dir_kpf/. If the # download function is called several times, it will check the # designated directory and only download new files. # In[7]: Koa.download ('./output/kpf_daterange.tbl', 'ipac', \ 'dnload_dir_kpf' )