def wf_data(wf_path, res_path, n_wf, threshold): all_amplitude = np.array([]) all_delay = np.array([]) areas = np.array([]) trc = Trc() allMyData = list(os.listdir(wf_path)) for input_file in allMyData[:n_wf]: print("Sto facendo il file {}\n".format(input_file)) my_wf = '{}/{}.'.format(wf_path, input_file) time, ampl, _ = trc.open(my_wf) ampl = -ampl _, amplDLED = DLED(time, ampl, 50) amplDLED = wf_correction(time, amplDLED, threshold) peaks, _ = find_peaks(amplDLED, height=threshold, prominence=0.01) peak_timestamp = time[peaks] peak_amplitude = amplDLED[peaks] time_distance = peak_timestamp[1:] - peak_timestamp[:-1] all_delay = np.concatenate((all_delay, time_distance)) all_amplitude = np.concatenate((all_amplitude, peak_amplitude[1:])) dt = np.abs(time[1:] - time[:-1]) dt = dt.mean() for i in range(2, len(peaks) - 2): if peak_timestamp[i] - peak_timestamp[ i - 1] > 100e-9 and peak_timestamp[ i + 1] - peak_timestamp[i] > 100e-9: #if time_distance[i] > 100e-9 and time_distance[i-1] > 100e-9: area = compute_area(ampl, peaks[i], dt) area = np.array([area]) areas = np.concatenate((areas, area)) fampl = open(f'{res_path}/all_ampl.txt', 'w') fareas = open(f'{res_path}/all_areas.txt', 'w') fdelay = open(f'{res_path}/all_delay.txt', 'w') #fdcr = open(f'{res_path}/dark_count_rate.txt', 'w') for i in areas: fareas.write(f'{i} \n') fareas.close() for i in range(len(all_amplitude)): fampl.write(f'{all_amplitude[i]} \n') fdelay.write(f'{all_delay[i]} \n') fdelay.close() fampl.close() return areas, all_amplitude, all_delay
def compute_area(inputfile): trc = Trc() time, ampl, _ = trc.open(inputfile) ampl = -ampl baseline = ampl[:150].mean() dt = (np.abs(time[1:] - time[:-1])).mean() area = ((ampl - baseline) * dt).sum() return area
def wf_data(wf_path, n_wf): all_amplitude = np.array([]) all_delay = np.array([]) areas = np.array([]) trc = Trc() #allMyData = list = os.listdir('C:/Users/39348/Desktop/Thesis_Software/test-gpib/A6_56V') allMyData = list(os.listdir(wf_path)) for input_file in allMyData[:n_wf]: print("Sto facendo il file {}\n".format(input_file)) my_wf = '{}/{}.'.format(wf_path, input_file) time, ampl, d = trc.open(my_wf) amplDLED = wf_correction(time, ampl) peaks, _ = find_peaks(-amplDLED, height=0.0085, prominence=0.02) peak_timestamp = time[peaks] peak_amplitude = amplDLED[peaks] time_distance = peak_timestamp[1:] - peak_timestamp[:-1] all_delay = np.concatenate((all_delay, time_distance)) all_amplitude = np.concatenate((all_amplitude, -peak_amplitude[1:])) dt = np.abs(time[1:] - time[:-1]) dt = dt.mean() for i in range(2, len(peaks) - 2): if peak_timestamp[i] - peak_timestamp[i - 1] > 500e-9: area = compute_area(ampl, peaks[i], dt) area = np.array([area]) areas = np.concatenate((areas, area)) return areas, all_amplitude, all_delay
timeDLED = time_delay amplDLED = ampl_delay - ampl return timeDLED, amplDLED def gaus(x, a, mu, sigma): return a * norm.pdf(x, mu, sigma) if __name__ == '__main__': allMyData = list = os.listdir( 'C:/Users/39348/Desktop/Thesis_Software/test-gpib/A6_56V') trc = Trc() areas = np.array([]) for input_file in allMyData[:20]: print("Sto facendo il file {}\n".format(input_file)) wf_path = 'C:/Users/39348/Desktop/Thesis_Software/test-gpib/A6_56V/{}.'.format( input_file) time, ampl, d = trc.open(wf_path) #print(d) timeDLED, amplDLED = DLED(time, ampl, 20) peaks, _ = find_peaks(-amplDLED, height=0.0085, prominence=0.02) peak_timestamp = time[peaks] peak_amplitude = amplDLED[peaks]
import numpy as np import os from matplotlib import pyplot as plt from readTrc import Trc trc = Trc() time, _, _ = trc.open('C:/Users/Marco/Desktop/C1--trigger--00000.trc') dt = (time[-1] - time[0]) * 40 print(time[-1] - time[0])
#plt.style.use('thesis') def compute_area(ampl, picco, dt): baseline = ampl[picco - 200:picco - 100].mean() ampl[picco - 200:picco + 900] = ampl[picco - 200:picco + 900] - baseline area = (ampl[picco - 200:picco + 900] * dt).sum() #plt.figure() #plt.plot(ampl[picco-200:picco+900]) #plt.plot(ampl[picco-200:picco-100]) #plt.show() return area time, a, _ = Trc().open( 'C:/Users/Marco/Desktop/Saturazione/9.5/C1--trigger--00000.trc') a = -a ''' timeDLED, amplDLED = DLED(time, ampl, 50) #plt.figure() #plt.plot(ampl) #plt.figure() #plt.plot(amplDLED) peaks, _ = find_peaks(amplDLED, height=0.016, prominence=0.005) amplDLED = wf_correction(timeDLED, amplDLED, 0.016) peaks, _ = find_peaks(amplDLED, height=0.016, prominence=0.005) peak_timestamp = time[peaks] time_distance = peak_timestamp[1:]-peak_timestamp[:-1]
import numpy as np import os import argparse import matplotlib.pyplot as plt from readTrc import Trc filepath = 'C:/Users/Marco/Desktop/Saturazione/foot/6' allMyData = list(os.listdir(filepath)) print(allMyData[0]) trc = Trc() time, ampl, _ = trc.open(f'{filepath}/{allMyData[0]}') ampl = -ampl baseline = ampl[:150].mean() f = 0.3 a = np.where((ampl-baseline)>f*max(ampl-baseline)) plt.figure() plt.plot(time, ampl-baseline) plt.plot(time, (ampl-baseline)[a[0]]) plt.plot(time, np.zeros(len(time))+f*max(ampl-baseline)) plt.show()