; docformat = 'rst' ; ; NAME: ; K2Timing ; PURPOSE: ; Extract the EPIC timings of a K2 Campaign ; ;+ ; :Description: ; Extract the EPIC timings of a K2 Campaign ; ; :Categories: ; K2 ; ; :Params: ; campaign: in, required, type=float/string ; The K2 Campaign number (e.g., 0, 1, 2, '9a', '9b', 10...) ; ; :Keywords: ; init: in, optional, type=string, default='~/.idl/k2/ini' ; Path to the K2 configuration file ; LC: in, optional, type=boolean, default=1 ; Set processing of long cadence stamps ; SC: in, optional, type=boolean, default=0 ; Set processing of short cadence stamps ; verbose: in, optional, type=boolean, default=0 ; Verbose progression to stdout ; ; :Examples: ; Extract box coordinates of all short cadence stamps from Campaign 4:: ; IDL> K2Timing, 4, /LC ; ; :Uses: ; K2Init ; ; :Author: ; B.Carry (OCA) ; ; :History: ; Change History:: ; Created in July 2016 by B. Carry (OCA) ;- pro K2Timing, campaign, LC=LC, SC=SC ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- I -- Initialization And Input Verification -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; COMPILE_OPT hidden, idl2 ;--I.1-- Input checks ------------------------------------------------------------------------ if not keyword_set(campaign) and n_elements(campaign) eq 0 then return if not keyword_set(LC) and not keyword_set(SC) then LC=1 if keyword_set(LC) and keyword_set(SC) then SC=0 if keyword_set(LC) then cad='lpd' else cad='spd' if keyword_set(init) then conf=K2Init(init) else conf=K2Init() ;--I.2-- Campaign Labels --------------------------------------------------------------------- dimC = size(campaign) if dimC[dimC[0]+1] eq 2 then begin campLoLab1 = 'c'+strTrim(string(campaign,format='(I)'),2) campUpLab1 = 'C'+strTrim(string(campaign,format='(I)'),2) campLoLab2 = 'c'+strTrim(string(campaign,format='(I02)'),2) campUpLab2 = 'C'+strTrim(string(campaign,format='(I02)'),2) endif else begin campLoLab1 = 'c'+strTrim(campaign,2) campUpLab1 = 'C'+strTrim(campaign,2) campLoLab2 = 'c'+strTrim(campaign,2) campUpLab2 = 'C'+strTrim(campaign,2) endelse ;--I.3-- Directories ------------------------------------------------------------------------- dirFITS = conf.path.root+conf.path.target+campUpLab1+'/' dirBox = conf.path.root+conf.path.box+'/' if not file_test(dirFITS,/Directory) then file_mkdir, dirFITS if not file_test(dirBox,/Directory) then file_mkdir, dirBox ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- II -- List and Decompress EPICs -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--II.1-- Get List of EPIC Parameters (boxCoordinates) --------------------------------------- if keyword_set(LC) then nameBox = 'BoxCoordinates-LC-'+campUpLab1+'.csv' $ else nameBox = 'BoxCoordinates-SC-'+campUpLab1+'.csv' ; box = K2ReadBox( dirBox+nameBox ) box = K2ReadBox( dirBox+'Box_coordinates_C0.txt' ) ;--II.2-- Select a SubList of EPIC ----------------------------------------------------------- uChan = uniq( box.chan, sort(box.chan) ) nbChan= n_elements(uChan) ;--II.3-- Decompress Target Pixel Data Files if Needed --------------------------------------- for kC=0, nbChan-1 do begin ;--II.3.1-- Retrieve First EPIC from the Channel cur = where( box.chan eq box[uChan[kC]].chan ) epicStr = strTrim(string(box[cur[0]].epic,format='(I)'),2) nameEpic = 'ktwo'+epicStr+'-'+campLoLab2+'_'+cad+'-targ.fits' if not file_test(dirFITS+nameEpic,/read) then $ spawn, 'cd '+dirFITS+' && gunzip '+nameEpic+'.gz' ;--II.3.2-- Read First of all EPIC for Number of Epoch if kC eq 0 then begin fxbOpen, idLC, dirFITS+nameEpic, 1, head fxbRead, idLC, kBJD, 'TIME' fxbClose, idLC nbEp = n_elements(kBJD) endif endfor ;--II.4-- BJD Array -------------------------------------------------------------------------- bjdArr = dblarr(nbChan,nbEp) ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- III -- Read EPICs and Get Timings -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; for kC=0, nbChan-1 do begin ;--III.1-- First EPIC from the Channel ----------------------------------------------------- cur = where( box.chan eq box[uChan[kC]].chan ) epicStr = strTrim(string(box[cur[0]].epic,format='(I)'),2) nameEpic = 'ktwo'+epicStr+'-'+campLoLab2+'_'+cad+'-targ.fits' ;--III.2-- Open Timing Array --------------------------------------------------------------- fxbOpen, idLC, dirFITS+nameEpic, 1, head fxbRead, idLC, kBJD, 'TIME' fxbClose, idLC ;--III.3-- Store in Global Array ----------------------------------------------------------- bjdArr[kC,*] = kBJD + conf.mjd endfor help, box print, box[uChan].chan help, bjdarr stop ; ; ; ;--II.1-- Decompress EPIC -------------------------------------------------------------------- ; if keyword_set(GZ) then begin ; ;--II.1.1-- List of Epic To Decompress ----------------------------------------------------- ; spawn, 'cd '+dirFITS+' && ls ktwo*'+cad+'*gz -1', listGZ ; nbGZ = n_elements(listGZ) ; ; ;--II.1.2-- Decompress Epic Files ---------------------------------------------------------- ; for kGZ=0, nbGZ-1 do spawn, 'gunzip '+dirFITS+listGZ[kGZ] ; endif ; ; ;--II.2-- List of Epic To Analyze ------------------------------------------------------------ ; spawn, 'cd '+dirFITS+' && ls ktwo*'+cad+'*fits -1', listEpic ; nbEpic = n_elements(listEpic) ; ; ;--II.3-- Prepare Output Arrays -------------------------------------------------------------- ; empty={epic:0.d, n1:0, n2:0, pix1:0.d, pix2:0.d, val1:0.d, val2:0.d, $ ; cd1:0.d, cd2:0.d, pc11:0., pc12:0., pc21:0., pc22:0., chan:0} ; box=replicate(empty,nbEpic) ; ;;-----------------------------------------------------------------------------------------------; ;;-----------------------------------------------------------------------------------------------; ;;--- TAG --- III -- Compute Coordinates -----------------------; ;;-----------------------------------------------------------------------------------------------; ;;-----------------------------------------------------------------------------------------------; ; for kE=0, nbEpic-1 do begin ; ; ;--III.1-- Open EPIC File Header ----------------------------------------------------------- ; head = headFits( listEPIC[kE], exten=2 ) ; ; ;--III.2-- Store Information in Structure -------------------------------------------------- ; box[kE].epic = sxpar(head,'KEPLERID') ; box[kE].n1 = sxpar(head,'NAXIS1') ; box[kE].n2 = sxpar(head,'NAXIS2') ; box[kE].pix1 = sxpar(head,'CRPIX1') ; box[kE].pix2 = sxpar(head,'CRPIX2') ; box[kE].val1 = sxpar(head,'CRVAL1') ; box[kE].val2 = sxpar(head,'CRVAL2') ; box[kE].cd1 = sxpar(head,'CDELT1') ; box[kE].cd2 = sxpar(head,'CDELT2') ; box[kE].pc11 = sxpar(head,'PC1_1') ; box[kE].pc12 = sxpar(head,'PC1_2') ; box[kE].pc21 = sxpar(head,'PC2_1') ; box[kE].pc22 = sxpar(head,'PC2_2') ; box[kE].chan = sxpar(head,'CHANNEL') ; ; endfor ;--III-- End of loop over EPICs ; ; ; ;--III.3-- Output Information on Disk ------------------------------------------------------ ; forprint, box.epic, box.n1, box.n2,box.pix1, box.pix2, box.val1, box.val2, $ ; box.cd1, box.cd2, box.pc11, box.pc12, box.pc21, box.pc22, box.chan, $ ; comment='EPIC, NAXIS1, NAXIS2, CRPIX1, CRPIX2, CRVAL1, CRVAL2, CDELT1, CDELT2, PC1_1, PC1_2, PC2_1, PC2_2, CHANNEL', $ ; format='(I9,", ",I4,", ",I4,", ",D,", ",D,", ",D,", ",D,", ",'+$ ; 'D,", ",D,", ",D,", ",D,", ",D,", ",D,", ",I3)', $ ; textOut=dirBox+'BoxCoordinates-'+campUpLab1+'.csv', /Silent end