;+ ; NAME: ; smei_shutterwrong ; PURPOSE: ; Detect frames that may have the shutter flag set wrong ; CALLING SEQUENCE: PRO smei_shutterwrong, trange, camera=camera, mode=mode, dbsource=dbsource ; INCLUDE: @compile_opt.pro ; CALLS: ; smei_get_file, smei_hdr_get, TimeGet, smei_coriolis ; smei_property, GetFileSpec, IsType ; MODIFICATION HISTORY: ; JAN-2006, Paul Hick (UCSD/CASS) ;- InitVar, camera, 3 InitVar, mode , ([2,2,1])[camera-1] usec = TimeUnit(/sec) ; Read time and shutter flag for frames in trange smei_hdr_get, trange, camera=camera, mode=mode, $ count=count, time=time, get='shutter', one=shutter, $ dbname=dbname, dbsource=dbsource i = -1 badcount = 0 WHILE i LT count-1 DO BEGIN ; Look for first frame with shutter closed j = where(shutter[i+1:*] EQ 0) IF j[0] EQ -1 THEN break ; No shutter closed found: done i += 1+j[0] ; Shutter closes here message, /info, 'shutter closes at '+TimeGet(time[i],/_ydoy,upto=usec) IF i LT count-1 THEN BEGIN j = where(shutter[i+1:*] EQ 1) ; Find frame where shutter opens again IF j[0] EQ -1 THEN break ; No shutter opening found: done i += 1+j[0] ; Shutter opens here message, /info, 'shutter opens at '+ $ TimeGet(time[i],/_ydoy,upto=usec)+' ('+strcompress(smei_coriolis(time[i],/double),/rem)+')' ; Frame i (with shutter flag open) could be a frame that with shutter flag ; that's wrong (the frame may be shutter closed). i1 = (i-5)>0 i2 = (i+5)<(count-1) shutter_ = shutter[i1:i2] ; 11 frames around 'shutter open' frame dbname_ = dbname [i1:i2] time_ = time [i1:i2] frm = smei_getfile(dbname_, /get_map, /exist, silent=2, hdr=hdr) ; Get the mean intensity over the region of interest n = n_elements(frm) d = fltarr(n) FOR j=0,n-1 DO d[j] = smei_property(*frm[j],/inroi,/average,/silent) ptr_free, frm ; d_mean: average of ROI means over frames with shutter open ; d_stdv: std dev of ROI means over frames with shutter open d_mean = mean (d[i+2-i1:*]) d_stdv = stddev(d[i+2-i1:*]) print print, 'Mean ROI intensity is', strcompress(d_mean), ' +/-',strcompress(d_stdv) IF d_stdv NE 0 THEN BEGIN ; ratio of ROI mean over average in units of std dev. ; If this number is very negative than probably the shutter is closed. d_ratio = (d-d_mean)/d_stdv print print, format='('+strcompress(n,/rem)+'I8 )', shutter_ print, format='('+strcompress(n,/rem)+'F8.2)', d_ratio print ;p = where( d_ratio LT -10 AND shutter_ EQ 1, n ) p = where( d_ratio LT -10, n ) IF n NE 0 THEN BEGIN IF badcount EQ 0 THEN BEGIN openw, /get_lun, iu, filepath(root=getenv('TUB'),'c'+strcompress(camera,/rem)+'_shutterwrong.txt'), /append name = GetFileSpec(dbname_[p[0]],part='name') printf, iu, format='(T'+strcompress(strlen(name),/rem)+',7X,A,3X,A,8X,A,5X,A,1X,A,5X,A)', $ 'mean','std dev','??','ratio','shutter','orbit' ENDIF ENDIF FOR j=0,n-1 DO BEGIN pj = p[j] name = GetFileSpec(dbname_[pj],part='name') message, /info, 'error? '+name+' ('+strcompress(pj,/rem)+')' hpj = hdr[pj] IF hpj.base_done AND hpj.base_ok AND hpj.shutter AND $ NOT hpj.just_bad AND hpj.n_saturated EQ 0 THEN $ printf, iu, format='(A,4F10.2,I8,F10.2)', name, d_mean, d_stdv, $ d[pj], d_ratio[pj], shutter_[pj], smei_coriolis(time_[pj],/double) ENDFOR badcount = badcount+n ENDIF ENDIF ENDWHILE IF IsType(iu,/defined) THEN free_lun, iu RETURN & END