Commit 3c9512ae81ac1e35fa4fc15e0742fd3d3668ad57
1 parent
7d1b1e74d2
Exists in
master
-
Showing 1 changed file with 2 additions and 1 deletions Inline Diff
RingDown.py
import matplotlib.pyplot as plt | 1 | 1 | import matplotlib.pyplot as plt | |
import numpy as np | 2 | 2 | import numpy as np | |
import csv, glob | 3 | 3 | import csv, glob | |
from scipy.optimize import curve_fit | 4 | 4 | from scipy.optimize import curve_fit | |
5 | 5 | |||
list_files = (glob.glob('WA*1.CSV')) | 6 | 6 | list_files = (glob.glob('WA*1.CSV')) | |
7 | 7 | |||
data = [] | 8 | 8 | data = [] | |
9 | 9 | |||
for f in list_files: | 10 | 10 | for f in list_files: | |
data_iter = csv.reader(open(f, 'r'), delimiter = ',', quotechar = '"') | 11 | 11 | data_iter = csv.reader(open(f, 'r'), delimiter = ',', quotechar = '"') | |
for i in range(2): | 12 | 12 | for i in range(2): | |
data_iter.next() | 13 | 13 | data_iter.next() | |
temp_data = [value for value in data_iter] | 14 | 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 | |||
data.extend(temp_data) | 15 | 16 | data.extend(temp_data) | |
16 | 17 | |||
data = np.asarray(data, dtype = float) | 17 | 18 | data = np.asarray(data, dtype = float) | |
18 | 19 | |||
del(temp_data, list_files, value, f) | 19 | 20 | del(temp_data, list_files, value, f) | |
20 | 21 | |||
plt.subplot(111) | 21 | 22 | plt.subplot(111) | |
plt.clf() | 22 | 23 | plt.clf() | |
23 | 24 | |||
plt.plot(data[data[:,0]>=0,0], data[data[:,0]>=0,1], label ='mes') | 24 | 25 | plt.plot(data[data[:,0]>=0,0], data[data[:,0]>=0,1], label ='mes') | |
25 | 26 | |||
def func(t, tau, A, w , a, b): | 26 | 27 | def func(t, tau, A, w , a, b): | |
return A * np.exp(-t/tau) * np.sin((w+a*t)*t) + b | 27 | 28 | return A * np.exp(-t/tau) * np.sin((w+a*t)*t) + b | |
28 | 29 | |||
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) | 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) | |
yfit = func(data[data[:,0]>=0,0], *popt) | 30 | 31 | yfit = func(data[data[:,0]>=0,0], *popt) | |
31 | 32 | |||
plt.plot(data[data[:,0]>=0,0], yfit, label ='fit') | 32 | 33 | plt.plot(data[data[:,0]>=0,0], yfit, label ='fit') |