; parse_waveform, 'test2_sc_sh_log.txt' ;pro parse_waveform, filename BSPACE = (byte(' '))[0] BZERO = (byte('0'))[0] BCOMMA = (byte(','))[0] ;path = '../../data/' ;filename = path+filename f = file_info(filename) if ~f.exists then message, 'File not found.' ; Open file for readingw openr, lun, filename, /get_lun temp = 'temp' ; Get the horizontal scale header: readf, lun, temp btemp = byte(temp) spaces = where(btemp eq BSPACE) hScale = float(string(btemp[spaces[3]:spaces[4]-1])) hIndex = findgen(1000) * hscale * 1e6 ; Now get the vertical scale readf, lun, temp btemp = byte(temp) spaces = where(btemp eq BSPACE) vScale = float(string(btemp[spaces[3]:spaces[4]-1])) npixels = 32 ^ 2. vals = fltarr(32, 32, 1000) for n = 0, npixels - 1 do begin readf, lun, temp btemp = byte(temp) spaces = where(btemp eq BSPACE) xCell = fix(string(btemp[spaces[0]:spaces[1]-1])) yCell = fix(string(btemp[spaces[1]:spaces[2]-1])) ; print, xCell, yCell readf, lun, temp btemp = byte(temp) commas = where(btemp eq BCOMMA, nfound) ; Parse the values last = 0 for i = 0, nfound -1 do begin vals[xCell, yCell, i] = float(string(btemp[last:commas[i]-1])) last = commas[i]+1 endfor vals[xCell, yCell, nfound] = float(string(btemp[last:*])) endfor close, lun free_lun, lun !p.multi = [0, 8, 8] !y.range = yrange !y.style = 1 !p.charsize=0.8 var = fltarr(32, 32) dip = fltarr(32, 32) for i = 0, 15 do begin ;if not keyword_set(set_ps_plot) then window, xsize = 1200*1.5, ysize = 1200 for y0 = 0, 7 do begin for x0= 0, 7 do begin x1=x0+((i mod 4)*8) y1=y0+(i/4)*8 nbins = n_elements(vals[x1, y1, *]) plot, hindex, vals[x1, y1, *] * vScale, $ title = 'X '+num2str(x1) + ', Y '+num2str(y1),$ xtitle = 'Microseconds', ytitle = 'Volts' baseline = average(vals[x1, y1, *]) inrange = where(hindex gt 600 and hindex lt 1200, nin) var[x1, y1] = total(sqrt( ( (vals[x1, y1, inrange] - baseline) )^2.)) * vscale / nin inrange = where(hindex gt 1300 and hindex lt 1400, nin) dip[x1, y1] = vscale*(min(vals[x1, y1,*]) - baseline) ; oplot,hindex, fltarr(n_elements(hindex)) + average(vals[x1, y1, *])*vscale, color = 5 endfor endfor endfor !p.multi = [0, 0, 0] result = moment(var) std = sqrt(result[1]) bmax= result[0] + 4 * std bmin = result[0] - 4 *std nbin=100. sig = abs(var - result[0]) / std outliers = where(sig gt 4, noutlier) ;print, 'Number of oscillating pixels: ', noutlier badPix = fltarr(32, 32) for i = 0, noutlier - 1 do begin x1 = outliers[i] mod 32 y1 = floor(outliers[i] / 32) badPix[x1, y1] = 1. plot, hindex, vals[x1, y1, *] * vScale, $ title = 'X '+num2str(x1) + ', Y '+num2str(y1),$ xtitle = 'Microseconds', ytitle = 'Volts' baseline = average(vals[x1, y1, *]) oplot,hindex, fltarr(n_elements(hindex)) +baseline*vscale, color = 5 oplot,hindex, fltarr(n_elements(hindex)) + min(vals[x1, y1, *])*vscale, color = 5 print, sig[outliers[i]], dip[outliers[i]] pause endfor plotimage, bytscl(badPix,min = 0, max = 1),/xst,/yst,$ pixel_aspect_ratio=1.0,title = 'Oscilating Pixels: '+num2str(noutlier),$ charsize=csize1,xtit="Column",ytit="Row", position=[0.14,0.12,0.48,0.75] !y.range = 0 plot, position = [0.65,0.18,0.95,0.8], dip, var, psym = 4, /noerase, $ xtitle = 'Size of dip (Volts)', ytitle = 'Average Variation (Volts) from 400 - 1200 us' oplot, dip[outliers], var[outliers], color = 255, psy = 4 xyouts, min(dip)+(max(dip)-min(dip))*0.05, max(var)*0.9, charsize=csize, $ 'Mean step: '+string(average(dip[outliers]), format = '(f8.5)') + ' Volts' end