;+ ; 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 ; INPUTS: ; trange ; OPTIONAL INPUT PARAMETERS: ; dbsource = dbsource ; /test if set, the SMEI frames are not update ; (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; pphick@ucsd.edu) ; Added call to smei_hdr_update to ensure that the ; header files are up-to-date before calculating ; smoothed dark currents ;- ;InitVar, trange , TimeSet(['2006_004','2008_213']) InitVar, trange , TimeSet(['2006_004','2006_005']) InitVar, dbsource, 'SMEIDB?' InitVar, test , 0 box_size = [10,3];,2,1] ; Smoothing window in integer minutes ; Largest first umin = TimeUnit(/minute) nbox = n_elements(box_size) ; Check to make sure the header files are up-to-date ; Update, if necessary. uday = TimeUnit(/day) doy = TimeGet(trange,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' ; Smoothing box in days, centered on zero box = [-0.5d0,0.5d0]#box_size smei_hdr_get, trange, 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 ; 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) FOR iframe=0L,nn_all-1 DO BEGIN 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 spawn, 'gunzip -v '+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 -v '+db_short END 1: print, db_all[iframe] ENDCASE ENDFOR RETURN & END