;+ ; NAME: ; smei_frm_smoothdark ; PURPOSE: ; Add extra Fits keyword to frame header containing ; smoothed dark current (boxcar average in the time domain) ; CATEGORY: ; ucsd/camera/idl/frm ; CALLING SEQUENCE: PRO smei_frm_smoothdark, trange, $ dbsource = dbsource , $ test = test , $ silent = silent ; INPUTS: ; trange array[2]; type: string or time structure ; time range to be smoothed ; (internally the range is extended to include ; enough frames to get the averages near the ; beginning and end of the time range) ; OPTIONAL INPUT PARAMETERS: ; dbsource = dbsource ; scalar; type: string; default; SMEIDB? ; indicates location of frames (either SMEIDB? or SMEIDB?) ; passed to smei_hdr_update and smei_hdr_get ; /test if set, the SMEI frames are not updated ; (i.e. nothing is modified, just output is written ; to screen) ; OUTPUTS: ; (Keyword SDARK0 added to Fits header) ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, TimeSet, TimeUnit, TimeOp, smei_hdr_get ; GetFileSpec, BadValue ; PROCEDURE: ; TimeSet(['2006_004','2007_003'] ; Note that the frame names and dark currents are pulled out ; of the header database. This means that, after a period ; has been "based" using smei_base, the corresponding ; header files need to be updated first with ; href=smei_hdr_update= before this procedure is run to ; calculate the smoothed dark currents (which are than ; inserted into the frames). ; MODIFICATION HISTORY: ; AUG-2008, Paul Hick (UCSD/CASS) ; OCT-2008, Paul Hick (UCSD/CASS) ; Added call to smei_hdr_update to ensure that the ; header files are up-to-date before calculating ; smoothed dark currents ; JAN-2010, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Added silent=silent to smei_hdr_update call ;- InitVar, silent, 0 usec = TimeUnit(/sec) umin = TimeUnit(/minute) uday = TimeUnit(/day) ;InitVar, trange , TimeSet(['2006_004','2008_213']) InitVar, trange , TimeSet(['2006_004','2006_005']) IF IsType(trange,/string) THEN trange = TimeSet(trange) InitVar, dbsource, 'SMEIDB?' InitVar, test , 0 box_size = [10,3];,2,1] ; Smoothing window in integer minutes nbox = n_elements(box_size) box = [-0.5d0,0.5d0]#box_size; Smoothing box in days, centered on zero ; Largest first ; Extend the time range by half a box to make sure the edges ; are average correctly trange_ext = TimeOp(/add,trange,TimeSet(/diff,box[*,0],umin)) ; Check to make sure the header files are up-to-date ; Update, if necessary. message, /info, 'time range : '+strjoin(TimeGet(/_ydoy,trange ,upto=usec),' - ') message, /info, 'extended range: '+strjoin(TimeGet(/_ydoy,trange_ext,upto=usec),' - ') doy = TimeGet(trange_ext,uday,/bot) ; Beginning of day ndoy = TimeOp(/subtract,doy[1],doy[0],uday) ; Nr of days FOR idoy=0,ndoy DO $ smei_hdr_update, TimeOp(/add,doy[0],TimeSet(/diff,idoy,uday)), $ camera = 3 , $ source = dbsource , $ remote = 'soft@smei' , $ silent = silent smei_hdr_get, trange_ext, camera=3, mode=1, $ dbsource= dbsource , $ time = tt_all , $ dbname = db_all , $ count = nn_all , $ get = ['base_ok','dark_current'] , $ one = ok_all , $ two = dark_all , $ silent = silent IF nn_all EQ 0 THEN BEGIN message, /info, 'no c3m1 frames in '+strjoin(TimeGet(/_ydoy,trange_ext,usec),' - ') RETURN ENDIF ; Use center time as time origin t0 = TimeLimits(tt_all, /mid) ; All times in minutes since t0 tt_all = TimeOp(/subtract,tt_all,t0,umin) tt_range = TimeOp(/subtract,trange,t0,umin) ; Only update frames inside the limited time range ii_range = where( tt_range[0] LE tt_all AND tt_all LE tt_range[1], nn_all ) FOR nframe=0L,nn_all-1 DO BEGIN iframe = ii_range[nframe] sdark = replicate(-999.0,nbox) IF ok_all[iframe] THEN BEGIN ; If frame has good base ; 10-minute box centered on frame time dt = tt_all[iframe]+box[*,0] ; Find good frames inside 10-minute box ; Should contain at least the current frame iframe good = where(dt[0] LE tt_all AND tt_all LE dt[1] AND ok_all, ngood) IF ngood EQ 0 THEN message, 'oops 1' IF ngood GT 3 THEN BEGIN tt = tt_all [good]-tt_all[iframe] dark = dark_all[good] i0 = (where(tt EQ 0))[0] IF i0 EQ -1 THEN message, 'oops 2' ;whatis, tt, dark ff = poly_fit(tt,dark,3,yfit=yfit) dark -= yfit FOR i=0,nbox-1 DO BEGIN dt = box[*,i] good = where(dt[0] LE tt AND tt LE dt[1], ngood) sdark[i] = yfit[i0]+mean(dark[good]) ENDFOR ENDIF ENDIF CASE test OF 0: BEGIN IF silent LE 0 THEN message, /info, hide_env(db_all[iframe]) spawn, 'gunzip '+db_all[iframe] db_short = GetFileSpec(db_all[iframe],upto='name'); Strips off '.gz' FOR i=0,nbox-1 DO $ fxhmodify, db_short, 'SDARK'+string(box_size[i],format='(I3.3)'), sdark[i], $ ' Smoothed dark current ('+strcompress(box_size[i],/rem)+' min)' spawn, 'gzip '+db_short END 1: print, db_all[iframe] ENDCASE ENDFOR RETURN & END