Blame view
RingDown.py
1.12 KB
ebddd841b Add files via upload |
1 2 3 4 |
import matplotlib.pyplot as plt import numpy as np import csv, glob from scipy.optimize import curve_fit |
7d1b1e74d Resolve csv readi... |
5 |
list_files = (glob.glob('WA*1.CSV')) |
ebddd841b Add files via upload |
6 7 8 9 10 11 12 |
data = [] for f in list_files: data_iter = csv.reader(open(f, 'r'), delimiter = ',', quotechar = '"') for i in range(2): data_iter.next() |
613012b2d . |
13 14 |
#temp_data = [value for value in data_iter] #if ends with a number temp_data = [value[:-1] for value in data_iter]#if ends with a comma |
ebddd841b Add files via upload |
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
data.extend(temp_data) data = np.asarray(data, dtype = float) del(temp_data, list_files, value, f) plt.subplot(111) plt.clf() plt.plot(data[data[:,0]>=0,0], data[data[:,0]>=0,1], label ='mes') def func(t, tau, A, w , a, b): return A * np.exp(-t/tau) * np.sin((w+a*t)*t) + b popt, pcov = curve_fit(func, data[data[:,0]>=0,0], data[data[:,0]>=0,1], p0 = [1e-5, 1e-2, 1e5, 1e10, 1e-4], maxfev=10000) yfit = func(data[data[:,0]>=0,0], *popt) |
613012b2d . |
31 32 33 34 35 |
tau = float(popt[0]) Q = np.pi*299792458*tau/(2.*140e-3) #print(np.sqrt(np.diag(pcov))) print(tau, Q) |
ebddd841b Add files via upload |
36 37 38 39 40 41 42 |
plt.plot(data[data[:,0]>=0,0], yfit, label ='fit') plt.xlabel('t') plt.ylabel('Intensity') plt.grid(which='both') plt.legend() plt.show() |