def demo3(myfile): """plot fastframe record on continuous time scale. not very practical for high frame counts or large delays between triggers""" volts, tstart, tscale, tfrac, tdatefrac, tdate = tekwfm.read_wfm(myfile) # create time vector samples, frames = volts.shape tstop = samples * tscale + tstart t = np.linspace(tstart, tstop, num=samples, endpoint=False) # fractional trigger times = np.zeros(volts.shape) for frame, subsample in enumerate(tfrac): toff = subsample * tscale times[:,frame] = t + toff # scale trigger times to first frame ref_frame = 0 tdate -= tdate[ref_frame] tdatefrac -= tdatefrac[ref_frame] # the following operation reduces resolution # this may not be suitable for high frame counts # or acquisitions with large delays between triggers tdateall = tdate + tdatefrac times += tdateall # shift sample times # plot plt.figure(3) plt.plot(times, volts) plt.xlabel('time (s)') plt.ylabel('volts (V)') plt.title('all frames, continuous time') plt.show()
def demo2(myfile): """plot frame 0 vs all frames on a two plot figure with locked time axes""" volts, tstart, tscale, tfrac, tdatefrac, tdate = tekwfm.read_wfm(myfile) # print trigger time stamps print('local trigger times for: {}'.format(myfile)) for frame, utcseconds in enumerate(tdate): print('frame: {:02d}, trigger: {}'.format(frame, time.ctime(utcseconds))) # create time vector samples, frames = volts.shape tstop = samples * tscale + tstart t = np.linspace(tstart, tstop, num=samples, endpoint=False) # fractional trigger times = np.zeros(volts.shape) for frame, subsample in enumerate(tfrac): toff = subsample * tscale times[:,frame] = t + toff # plot: fastframe plt.figure(2) ax1 = plt.subplot(2, 1, 1) ax1.axvline(linewidth=1, color='r') # trigger annotation ax1.plot(times[:,0], volts[:,0]) plt.ylabel('volts (V)') plt.title('only frame 1') ax2 = plt.subplot(2, 1, 2, sharex=ax1) ax2.axvline(linewidth=1, color='r') # trigger annotation ax2.plot(times, volts) plt.xlabel('time (s)') plt.ylabel('volts (V)') plt.title('all frames') plt.show()
def ReadFile(File, FileName, FilePeaks, Print_Introduction_bool, dleddt, distance, height): File = File.rstrip('\n') print("\nReading File:\n" + ntpath.split(File)[1]) # Read File volts, tstart, tscale, tfrac, tdatefrac, tdate = tekwfm.read_wfm(File) # Create time vector samples, frames = volts.shape tstop = samples * tscale + tstart t = np.linspace(tstart, tstop, num=samples, endpoint=False) times = np.zeros(volts.shape) for frame, subsample in enumerate(tfrac): toff = subsample * tscale times[:, frame] = t + toff # Conversions k_times = 1e9 k_volts = 1e3 times *= k_times # times in ns volts *= k_volts # volts in mV # Invert: volts *= -1 # DLED times_dled, volts_dled = DLED(times, volts, dleddt) # Print Introduction if Print_Introduction_bool: FilePeaks.write("Peaks from file:\n") FilePeaks.write(FileName + "\n") FilePeaks.write("Sampling = " + str(1 / (tscale * k_times)) + " GHz (Time Resolution = " + str(tscale * k_times * 1e3) + " ps)\n") FilePeaks.write( "Peaks found with find_peaks(volts_dled[:,i], height=0)\n") FilePeaks.write("NO trace smoothing\n") FilePeaks.write("TimeWindow = [" + str(tstart * k_times) + " , " + str(tstop * k_times) + "] ns, Dt = " + str((tstop - tstart) * k_times) + " ns\n") FilePeaks.write("DLED related: dleddt = " + str(dleddt) + " indices\n") FilePeaks.write("END_INTRODUCTION\n") # Find Peaks for i in range(frame + 1): # for i in range(3): indices, _ = find_peaks(volts_dled[:, i], height=height, distance=distance) for j in range(len(indices)): FilePeaks.write( str(times_dled[indices[j], i]) + "\t" + str(volts_dled[indices[j], i]) + "\n") FilePeaks.write("N\n")
def demo4(myfile): """plot bar chart of time between frames""" volts, tstart, tscale, tfrac, tdatefrac, tdate = tekwfm.read_wfm(myfile) samples, frames = volts.shape x = np.arange(1, frames) iseconds = np.diff(tdate) fseconds = np.diff(tdatefrac) # the following operation reduces resolution # this may not be suitable for high frame counts # or acquisitions with large delays between triggers fseconds += iseconds # bar plot plt.figure(4) plt.bar(x, fseconds) #plt.xticks(x) plt.xlabel('diff(frame)') plt.ylabel('time (s)') plt.title('time between frames') plt.show()
def demo1(myfile): """print date of trigger and plot scaled wfm 'myfile'""" volts, tstart, tscale, tfrac, tdatefrac, tdate = tekwfm.read_wfm(myfile) # print trigger time stamp print('local trigger time for: {}'.format(myfile)) print('trigger: {}'.format(time.ctime(tdate))) # create time vector toff = tfrac * tscale samples, frames = volts.shape tstop = samples * tscale + tstart t = np.linspace(tstart+toff, tstop+toff, num=samples, endpoint=False) # plot plt.figure(1) plt.axvline(linewidth=1, color='r') # trigger annotation plt.plot(t, volts) plt.xlabel('time (s)') plt.ylabel('volts (V)') plt.title('single waveform') plt.show()
prerun_name = path + '/' for i in range(len(file_split) - 2): prerun_name += file_split[i] + '_' return len(ch_set), len(run_set), prerun_name max(run_num) numbChannels, numbFiles, fname = openfiles(path) if numbChannels != 4: raise Exception("Problem with the number of channels") for fnum in range(1, numbFiles + 1): print("I'm reading: %s%i_CH1.wfm" % (fname, fnum)) volts_ch1, tstart_ch1, tscale_ch1, tfrac_ch1, tdatefrac_ch1, tdate_ch1 = tekwfm.read_wfm( "%s%i_CH1.wfm" % (fname, fnum)) volts_ch2, tstart_ch2, tscale_ch2, tfrac_ch2, tdatefrac_ch2, tdate_ch2 = tekwfm.read_wfm( "%s%i_CH2.wfm" % (fname, fnum)) volts_ch3, tstart_ch3, tscale_ch3, tfrac_ch3, tdatefrac_ch3, tdate_ch3 = tekwfm.read_wfm( "%s%i_CH3.wfm" % (fname, fnum)) volts_ch4, tstart_ch4, tscale_ch4, tfrac_ch4, tdatefrac_ch4, tdate_ch4 = tekwfm.read_wfm( "%s%i_CH4.wfm" % (fname, fnum)) if tfrac_ch1.all() != tfrac_ch2.all() and tfrac_ch1.all() != tfrac_ch3.all( ) and tfrac_ch1.all() != tfrac_ch4.all(): raise Exception("times don't match between channels!") if tscale_ch1 != tscale_ch2 and tscale_ch1 != tscale_ch3 and tscale_ch1 != tscale_ch4: raise Exception("time scales don't match between channels!") for evt_local in range(len(tfrac_ch1)): i_evt[0] = evt_local + len(tfrac_ch1) * (fnum - 1)