Commit ee82fa8490e3105729eaa4ca5549ba0c896abddc
1 parent
84d931fb3d
Exists in
master
.
Showing 1 changed file with 0 additions and 45 deletions Side-by-side Diff
RingDown.py
1 | -import matplotlib.pyplot as plt | |
2 | -import numpy as np | |
3 | -import csv, glob, sys | |
4 | -from scipy.optimize import curve_fit | |
5 | - | |
6 | -list_files = (glob.glob(sys.argv[1])) | |
7 | - | |
8 | -data = [] | |
9 | - | |
10 | -for f in list_files: | |
11 | - data_iter = csv.reader(open(f, 'r'), delimiter = ',', quotechar = '"') | |
12 | - for i in range(2): | |
13 | - data_iter.next() | |
14 | - #temp_data = [value for value in data_iter] #if ends with a number | |
15 | - temp_data = [value[:-1] for value in data_iter]#if ends with a comma | |
16 | - data.extend(temp_data) | |
17 | - | |
18 | -data = np.asarray(data, dtype = float) | |
19 | - | |
20 | -del(temp_data, list_files, value, f) | |
21 | - | |
22 | -plt.subplot(111) | |
23 | -plt.clf() | |
24 | - | |
25 | -plt.plot(data[data[:,0]>=0,0], data[data[:,0]>=0,1], label ='mes') | |
26 | - | |
27 | -def func(t, tau, A, w , a, b): | |
28 | - return A * np.exp(-t/tau) * np.sin((w+a*t)*t) + b | |
29 | - | |
30 | -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) | |
31 | -yfit = func(data[data[:,0]>=0,0], *popt) | |
32 | - | |
33 | -tau = float(popt[0]) | |
34 | -Q = np.pi*299792458*tau/(2.*140e-3) | |
35 | - | |
36 | -#print(np.sqrt(np.diag(pcov))) | |
37 | -print(tau, Q) | |
38 | - | |
39 | -plt.plot(data[data[:,0]>=0,0], yfit, label ='fit') | |
40 | - | |
41 | -plt.xlabel('t') | |
42 | -plt.ylabel('Intensity') | |
43 | -plt.grid(which='both') | |
44 | -plt.legend() | |
45 | -plt.show() |