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