dat_ident.py
1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
import csv, time, glob, datetime, os
import matplotlib.pyplot as plt
import matplotlib.dates as md
#from scipy import signal
#from scipy.optimize import curve_fit
tic = time.time()
os.chdir('/home/bma/server/data/2016/2016-03')
def getColumn(filename, column):
results = []
for dat_file in sorted(glob.glob(filename)):
file_result = csv.reader(open(dat_file), delimiter='\t')
results = results + map(float,[result[column] for result in file_result])
return results
t = getColumn('*-lakeshore.dat', 0)
T1 = getColumn('*-lakeshore.dat', 2)
T2 = getColumn('*-lakeshore.dat', 3)
T3 = getColumn('*-lakeshore.dat', 4)
T4 = getColumn('*-lakeshore.dat', 5)
"""
n = 400
t = [t[n*i] for i in range(len(t)/n)]
T1 = [T1[n*i] for i in range(len(T1)/n)]
T2 = [T2[n*i] for i in range(len(T2)/n)]
T3 = [T3[n*i] for i in range(len(T3)/n)]
T4 = [T4[n*i] for i in range(len(T4)/n)]
def func(U, a0, b1, b2, y0):
sys = signal.lti([a0],[b2, b1, 1])
y = sys.output(U, t, y0)
return y[1]
print('Fitting...')
popt, cov = curve_fit(func, T1, T4)
print(popt)
Yfit = func(T1, *popt)
"""
timetamps = [datetime.datetime.fromtimestamp(ti) for ti in t]
datenums=md.date2num(timetamps)
plt.subplots_adjust(bottom=0.35)
plt.xticks(rotation=90)
ax=plt.gca()
xfmt = md.DateFormatter('%Y-%m-%d %H:%M:%S')
ax.xaxis.set_major_formatter(xfmt)
plt.plot(datenums, T1, label = 'Table')
plt.plot(datenums, T2, label = 'Link st.')
plt.plot(datenums, T3, label = 'PT2')
plt.plot(datenums, T4, label = 'Reg. st.')
#plt.plot(datenums, Yfit, label = 'Fit')
plt.legend()
plt.grid()
plt.show()
toc = time.time() - tic
print(toc)