def draw_times(axis, pkvals, pkinds, wt) : """Adds to figure axis a set of vertical lines for found peaks. Parameters: - axis - figure axis to draw a single waveform - pkvals [np.array] - 1-d peak values - pkinds [np.array] - 1-d peak indexes in wt - wt [np.array] - 1-d waveform sample times - is used to get time [sec] from pkinds """ for v,i in zip(pkvals,pkinds) : t = wt[i] gr.drawLine(axis, (t,t), (-v,v), s=10, linewidth=1, color='k')
def draw_times_old(ax, wf, wt): #wf -= wf[0:1000].mean() edges = find_edges(wf, BASE, THR, CFR, DEADTIME, LEADINGEDGE) # pairs of (amplitude,sampleNumber) #print(' nhits:', edges.shape[0],) #print(' edges:', edges) for (amp, ind) in edges: x0 = wt[int(ind)] xarr = (x0, x0) yarr = (amp, -amp) gr.drawLine(ax, xarr, yarr, s=10, linewidth=1, color='k') return edges
def draw_waveforms(wfs, wts, nev): """Draws all waveforms on figure axes, one waveform per axis. Parameters: - wfs [np.array] shape=(NUM_CHANNELS, NUM_SAMPLES) - waveform intensities - wts [np.array] shape=(NUM_CHANNELS, NUM_SAMPLES) - waveform times """ t0_sec = time() #======== peak-finding algorithm ============ #wfs, wts = array_of_selected_channels(wfs), array_of_selected_channels(wts) nhits, pkinds, pkvals, pktsec = peaks(wfs, wts) pkinds, pkvals = peaks.peak_indexes_values(wfs, wts) # massaging for V4 dt_sec = time() - t0_sec wfssel, wtssel = peaks.waveforms_preprocessed( wfs, wts) # selected time range and subtracted offset thr = peaks.THR #============================================ print_ndarr(wtssel, ' wtssel: ', last=4) print(' wf processing time(sec) = %8.6f' % dt_sec) print_ndarr(nhits, ' nhits : ', last=10) print_ndarr(pkinds, ' pkinds: ', last=4) print_ndarr(pktsec, ' pktsec: ', last=4) print_ndarr(pkvals, ' pkvals: ', last=4) for ch in range(naxes): ax[ch].clear() ax[ch].set_xlim(time_range_sec) ax[ch].set_ylabel(ylab[ch], fontsize=14) # draw waveform ax[ch].plot(wtssel[ch], wfssel[ch], gfmt[ch], linewidth=lw) # draw line for threshold level gr.drawLine(ax[ch], ax[ch].get_xlim(), (thr, thr), s=10, linewidth=1, color='k') # draw lines for peak times draw_times(ax[ch], pkvals[ch], pkinds[ch], wtssel[ch]) gr.set_win_title(fig, 'Event: %d' % nev) gr.draw_fig(fig) gr.show(mode='non-hold')
def draw_times(ax, wf, wt) : #wf -= wf[0:1000].mean() t0_sec = time() #wf = np.array(WF, dtype=np.double) pkvals = np.zeros((100,), dtype=np.double) pkinds = np.zeros((100,), dtype=np.uint32) npks = wfpkfinder_cfd(wf, BASE, THR, CFR, DEADTIME, LEADINGEDGE, pkvals, pkinds) print(' wf proc npks:%3d time(sec) = %8.6f' % (npks, time()-t0_sec)) #edges = np.array(((100,5000),(200,10000))) edges = zip(pkvals,pkinds) for (amp,ind) in edges : x0 = wt[int(ind)] xarr = (x0,x0) yarr = (amp,-amp) gr.drawLine(ax, xarr, yarr, s=10, linewidth=1, color='k')
def draw_waveforms(wf, wt) : for i in range(naxes) : ax[i].clear() ax[i].set_xlim(TIME_RANGE) ax[i].set_ylabel(ylab[i], fontsize=14) ich = ch[i] print(' == ch:%2d %3s'%(ich,ylab[i]), end = '') wftot = wf[ich,:] wttot = wt[ich,:] wfsel = np.copy(wftot[BBEG:BEND]) wtsel = np.copy(wttot[BBEG:BEND]) wfsel -= wftot[BBAV:BEAV].mean() ax[i].plot(wtsel, wfsel, gfmt[i], linewidth=lw) gr.drawLine(ax[i], ax[i].get_xlim(), (THR,THR), s=10, linewidth=1, color='k') draw_times(ax[i], wfsel, wtsel) gr.draw_fig(fig) gr.show(mode='non-hold')
def draw_times(ax, wf, wt): #extrema = 0.1* wf_extremas(ax, wf, wt, rank=10) #gr.drawLine(ax, wt, extrema, s=10, linewidth=1, color='k') #return #wf -= wf[0:1000].mean() #edges = find_edges(wf, BASE, THR, CFR, DEADTIME, LEADINGEDGE) edges = wf_extremas(ax, wf, wt, rank=10) # pairs of (amplitude,sampleNumber) nhits = edges.shape[0] #print(' nhits:', nhits,) #print(' edges:', edges) for (amp, ind) in edges: x0 = wt[int(ind)] xarr = (x0, x0) yarr = (amp, -amp) gr.drawLine(ax, xarr, yarr, s=10, linewidth=1, color='k') return edges
t0_sec = time() wff = gaussian_filter1d(wf, 3, axis=-1, order=0, output=None, mode='reflect', cval=0.0, truncate=4.0) print('==== gaussian_filter1d for signal consumed time %.6f sec' % (time() - t0_sec)) #ax0.plot(t, wff, 'g-', linewidth=1, **kwargs) ax1.hist(t, bins=nbins, weights=wff, color='b', histtype='step', **kwargs) gr.drawLine(ax1, ax1.get_xlim(), (THR, THR), s=10, linewidth=1, color='k') cond_wff_sig = wff < THR sig_wff = np.select([ cond_wff_sig, ], [ ones_wf, ], default=0) ax1.hist(t, bins=nbins, weights=sig_wff * 0.1, color='g', histtype='step', **kwargs) #sideband region
for i, ax in enumerate(axes): ax.set_xlim(left=binmin, right=binmax) ax.set_ylabel('ax%d' % i) ax.grid(True) #---------- ax0.set_xlabel('sample/time') ax0.set_ylabel('waveform') t = np.arange(binmin, binmax, 1) #ax0.plot(t, sig, 'b-', linewidth=1, **kwargs) ax0.hist(t, bins=wf.size, weights=wf, color='b', histtype='step', **kwargs) ax0.hist(t, bins=wff.size, weights=wff, color='y', histtype='step', **kwargs) gr.drawLine(ax0, ax0.get_xlim(), (THR, THR), s=10, linewidth=1, color='k') cond_wff = wff < THR sig_wff = np.select([ cond_wff, ], [ ones_wf, ], default=0) ax0.hist(t, bins=wff.size, weights=cond_wff * 0.1, color='g', histtype='step', **kwargs) print('XXXX pkinds', pkinds)
'y-', 'c-', ) ylab = ( 'X1', 'X2', 'Y1', 'Y2', 'MCP', 'XX', 'YY', ) ax = [gr.add_axes(fig, axwin=(x0, y0 + i * dy, w, h)) for i in range(naxes)] zerocross = (382, 344, 388, 336, 500) #---------- for i in range(naxes): ax[i].clear() wl = wf[i,:] if tname=='1' else\ wf[i,8000:16000] ax[i].plot(wl, gfmt[0], linewidth=1) gr.drawLine(ax[i], ax[i].get_xlim(), (0, 0), s=10, linewidth=1, color='k') z = zerocross[i] print('ch:%d sum-signal: %.1f sum-tail: %.1f' % (i, np.sum(wl[:z]), np.sum(wl[z:]))) gr.show() #----------
#sos = butter(10, 10, 'hp', fs=10000, output='sos') #sigf = sosfilt(sos, sigf) print('==== gaussian_filter1d for signal consumed time %.6f sec' % (time() - t0_sec)) t = np.arange(binmin, binmax, 1) #ax0.plot(t, sig, 'b-', linewidth=1, **kwargs) ax0.hist(t, bins=sig.size, weights=sig, color='b', histtype='step', **kwargs) #---------- #sigf = gaussian_filter1d(sig, 5, axis=-1, order=0, output=None, mode='reflect', cval=0.0, truncate=4.0) #ax0.plot(t, sigf, 'g-', linewidth=1, **kwargs) ax1.hist(t, bins=nbins, weights=sigf, color='g', histtype='step', **kwargs) gr.drawLine(ax1, ax1.get_xlim(), (THR, THR), s=10, linewidth=1, color='k') thrmask = sigf < THR ax1.hist(t, bins=nbins, weights=thrmask * 0.1, color='r', histtype='step', **kwargs) #grinds = np.transpose(np.array(np.argwhere(thrmask))) grinds = np.array(np.nonzero(thrmask)) print('XXXXXXXXX grinds.shape:', grinds.shape) for i, group in enumerate(grinds): print('gr:%02d range:%04d-%04d n in group:%04d' % (i, group[0], group[-1], len(group)))