PRO PRINT_CMD, olun, url, cadence_str, k2id, campaign, cmdtype ;; Print a data download command to an opened file (LUN) given a K2 ID and campaign. this_filename = "ktwo" + k2id + '-c' + STRTRIM(STRING(campaign,F='(I02)'),2) + cadence_str ;; If 'cmdtype' is curl then there needs to be an added option. IF cmdtype eq "curl" THEN BEGIN cmd_str_to_add = " -f -R -o " + this_filename + " " ENDIF ELSE BEGIN cmd_str_to_add = " " ENDELSE this_cmd = cmdtype + cmd_str_to_add + url + 'c'+STRTRIM(STRING(campaign,F='(I)'),2) + '/' +$ STRMID(k2id,0,4) + '00000/' + STRMID(k2id,4,2) + '000/' + this_filename PRINTF, olun, this_cmd END PRO GET_K2, k2ids, cadence=cadence, data_type=data_type, ofile=ofile, campaigns=campaigns,$ cmdtype=cmdtype ;; ----- ;; DESCRIPTION ;; ----- ;; Script to generate download commands given one or more K2 IDs. ;; ----- ;; ----- ;; INPUT ;; ----- ;; k2ids = Scalar string or array of strings containing a K2 ID(s). ;; cadence = The desired cadence ("long" or "short"). Default is "long". ;; data_type = The desired data products ("lightcurve" or "target_pixel_file"). Default is ;; "lightcurve", although note K2 lightcurves were not available at first. ;; campaigns = Scalar string or array of strings corresponding to the campaigns to retrieve. ;; Note that most K2 targets are only observed in a single Campaign. ;; ofile = String containing the name of the script to print the wget commands. Default is to ;; make a file called 'get_k2.sh'. Output files will be overwritten. ;; cmdtype = Specify whether to use wget or curl. Default is to use curl. ;; ----- ;; ----- ;; EXAMPLES ;; ----- ;; Give me all available long-cadence lightcurve files for this K2 ID. ;; get_k2, '204367016' ;; Give me all available long-cadence target pixel files for this K2 ID. ;; get_k2, '204367016', data_type="target_pixel_file" ;; Give me all Campaign 2 short-cadence target_pixel_files files for these K2 IDs. ;; get_k2, ['202717132','204313397','204399980'], data_type="target_pixel_file", $ ;; cadence="short", campaigns=2 ;; ----- ;; This is the base URL to use when requesting K2 files. lc_base_url = "http://archive.stsci.edu/missions/k2/lightcurves/" tp_base_url = "http://archive.stsci.edu/missions/k2/target_pixel_files/" ;; If 'cadence' is specified, make sure it's either "short" or "long". If not specified then make ;; it "long" by default. IF KEYWORD_SET(cadence) THEN BEGIN cadence = STRLOWCASE(STRTRIM(cadence,2)) IF cadence ne "short" AND cadence ne "long" THEN BEGIN PRINT, "*** ERROR in GET_K2: Cadence must be either 'long' or 'short'." RETURN ENDIF ENDIF ELSE BEGIN cadence = "long" ENDELSE ;; If 'cmdtype' is specified it must be either wget or curl. If not specified, set it to curl. IF KEYWORD_SET(cmdtype) THEN BEGIN cmdtype = STRLOWCASE(STRTRIM(cmdtype,2)) IF cmdtype ne "curl" AND cmdtype ne "wget" THEN BEGIN PRINT, "*** ERROR in GET_KEPLER: CMDTYPE must be either 'curl' or 'wget'." RETURN ENDIF ENDIF ELSE BEGIN cmdtype = "curl" ENDELSE ;; If 'data_type' is specified, make sure it's either "lightcurve" or "target_pixel_file". If ;; not specified, then make it "lightcurve". IF KEYWORD_SET(data_type) THEN BEGIN data_type = STRLOWCASE(STRTRIM(data_type,2)) IF data_type ne "lightcurve" AND data_type ne "target_pixel_file" THEN BEGIN PRINT, "*** ERROR in GET_K2: Data type must be either 'lightcurve' or" + $ " 'target_pixel_file'." RETURN ENDIF ENDIF ELSE BEGIN data_type = "lightcurve" ENDELSE ;; Identify which base URL to use based on the requested data_type keyword. IF data_type eq "lightcurve" THEN base_url = lc_base_url ELSE base_url = tp_base_url ;; Define the cadence string to use in file names. IF data_type eq "lightcurve" THEN BEGIN IF cadence eq "long" THEN cadence_str = "_llc.fits" ELSE cadence_str = "_slc.fits" ENDIF ELSE BEGIN IF cadence eq "long" THEN cadence_str = "_lpd-targ.fits.gz" ELSE $ cadence_str = "_spd-targ.fits.gz" ENDELSE ;; If 'campaigns' is not specified, then just use all campaigns. IF ~KEYWORD_SET(campaigns) THEN campaigns = STRTRIM(STRING(INDGEN(26), F='(I)'),2) ;; If 'ofile' is not specified, default it to "get_k2.sh". IF ~KEYWORD_SET(ofile) THEN ofile = "get_k2.sh" ;; If a scalar, put 'k2ids', 'epochs', and 'campaigns' into a one-element arrays. IF SIZE(k2ids,/DIMENSIONS) eq 0 THEN k2ids = [k2ids] IF KEYWORD_SET(campaigns) THEN BEGIN IF SIZE(campaigns,/DIMENSIONS) eq 0 THEN campaigns = [campaigns] ENDIF ;; Make sure K2 IDs are zero-padded. k2ids = STRTRIM(STRING(k2ids,F='(I09)'),2) ;; Open output file for writing. OPENW, olun, ofile, /GET_LUN ;; Print the generic shell script as the first line. PRINTF, olun, "#!/bin/sh" FOR k=0, N_ELEMENTS(k2ids)-1 DO BEGIN ;; Get the current K2 ID. this_k2id = k2ids[k] ;; Generate a command for the specified campaign (or try each campaign if none specified). FOR c=0, N_ELEMENTS(campaigns)-1 DO BEGIN this_campaign = campaigns[c] PRINT_CMD, olun, base_url, cadence_str, this_k2id, this_campaign, cmdtype ENDFOR ENDFOR ;; Print a warning message to let users know there will sometimes be Error 404's. PRINTF, olun, "echo" PRINTF, olun, 'echo Script completed. Note: Some \"Error 404\" messages are expected,' +$ ' depending on your parameters. It is always recommended to confirm the expected' +$ ' number of files are successfully downloaded.' ;; Close output file. FREE_LUN, olun ;; Make sure the output file is at least executable by the user. FILE_CHMOD, ofile, /U_EXECUTE END