Commit 98e71dda5c6966c7189f7f6bf4d33780d4f2dff1

Authored by bmarechal
1 parent 613012b2de
Exists in master

use sys.argv

Showing 1 changed file with 2 additions and 2 deletions Inline Diff

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, sys
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(sys.argv[1]))
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] #if ends with a number 14 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 15 15 temp_data = [value[:-1] for value in data_iter]#if ends with a comma
data.extend(temp_data) 16 16 data.extend(temp_data)
17 17
data = np.asarray(data, dtype = float) 18 18 data = np.asarray(data, dtype = float)
19 19
del(temp_data, list_files, value, f) 20 20 del(temp_data, list_files, value, f)
21 21
plt.subplot(111) 22 22 plt.subplot(111)
plt.clf() 23 23 plt.clf()
24 24
plt.plot(data[data[:,0]>=0,0], data[data[:,0]>=0,1], label ='mes') 25 25 plt.plot(data[data[:,0]>=0,0], data[data[:,0]>=0,1], label ='mes')
26 26
def func(t, tau, A, w , a, b): 27 27 def func(t, tau, A, w , a, b):
return A * np.exp(-t/tau) * np.sin((w+a*t)*t) + b 28 28 return A * np.exp(-t/tau) * np.sin((w+a*t)*t) + b
29 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) 30 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) 31 31 yfit = func(data[data[:,0]>=0,0], *popt)
32 32
tau = float(popt[0]) 33 33 tau = float(popt[0])
Q = np.pi*299792458*tau/(2.*140e-3) 34 34 Q = np.pi*299792458*tau/(2.*140e-3)