Commit b31e251b56f07960ad3a9218e73f1a9ee0e4dabf
1 parent
c21bab35d9
Exists in
master
...
Showing 1 changed file with 1 additions and 1 deletions Inline Diff
dat_ident.py
| # -*- coding: utf-8 -*- | 1 | 1 | # -*- coding: utf-8 -*- | |
| 2 | 2 | |||
| import csv, time, glob, datetime, os | 3 | 3 | import csv, time, glob, datetime, os | |
| import matplotlib.pyplot as plt | 4 | 4 | import matplotlib.pyplot as plt | |
| import matplotlib.dates as md | 5 | 5 | import matplotlib.dates as md | |
| 6 | 6 | |||
| #from scipy import signal | 7 | 7 | #from scipy import signal | |
| #from scipy.optimize import curve_fit | 8 | 8 | #from scipy.optimize import curve_fit | |
| 9 | 9 | |||
| tic = time.time() | 10 | 10 | tic = time.time() | |
| 11 | 11 | |||
| os.chdir('/home/user/sicav_data/Manip/2016/2016-03/') | 12 | 12 | os.chdir('/home/bma/server/data/2016/2016-03') | |
| 13 | 13 | |||
| def getColumn(filename, column): | 14 | 14 | def getColumn(filename, column): | |
| results = [] | 15 | 15 | results = [] | |
| for dat_file in sorted(glob.glob(filename)): | 16 | 16 | for dat_file in sorted(glob.glob(filename)): | |
| file_result = csv.reader(open(dat_file), delimiter='\t') | 17 | 17 | file_result = csv.reader(open(dat_file), delimiter='\t') | |
| results = results + map(float,[result[column] for result in file_result]) | 18 | 18 | results = results + map(float,[result[column] for result in file_result]) | |
| return results | 19 | 19 | return results | |
| 20 | 20 | |||
| t = getColumn('*-lakeshore.dat', 0) | 21 | 21 | t = getColumn('*-lakeshore.dat', 0) | |
| T1 = getColumn('*-lakeshore.dat', 2) | 22 | 22 | T1 = getColumn('*-lakeshore.dat', 2) | |
| T2 = getColumn('*-lakeshore.dat', 3) | 23 | 23 | T2 = getColumn('*-lakeshore.dat', 3) | |
| T3 = getColumn('*-lakeshore.dat', 4) | 24 | 24 | T3 = getColumn('*-lakeshore.dat', 4) | |
| T4 = getColumn('*-lakeshore.dat', 5) | 25 | 25 | T4 = getColumn('*-lakeshore.dat', 5) | |
| 26 | 26 | |||
| """ | 27 | 27 | """ | |
| n = 400 | 28 | 28 | n = 400 | |
| t = [t[n*i] for i in range(len(t)/n)] | 29 | 29 | t = [t[n*i] for i in range(len(t)/n)] | |
| T1 = [T1[n*i] for i in range(len(T1)/n)] | 30 | 30 | T1 = [T1[n*i] for i in range(len(T1)/n)] | |
| T2 = [T2[n*i] for i in range(len(T2)/n)] | 31 | 31 | T2 = [T2[n*i] for i in range(len(T2)/n)] | |
| T3 = [T3[n*i] for i in range(len(T3)/n)] | 32 | 32 | T3 = [T3[n*i] for i in range(len(T3)/n)] | |
| T4 = [T4[n*i] for i in range(len(T4)/n)] | 33 | 33 | T4 = [T4[n*i] for i in range(len(T4)/n)] | |
| 34 | 34 | |||
| def func(U, a0, b1, b2, y0): | 35 | 35 | def func(U, a0, b1, b2, y0): | |
| sys = signal.lti([a0],[b2, b1, 1]) | 36 | 36 | sys = signal.lti([a0],[b2, b1, 1]) | |
| y = sys.output(U, t, y0) | 37 | 37 | y = sys.output(U, t, y0) | |
| return y[1] | 38 | 38 | return y[1] | |
| 39 | 39 | |||
| print('Fitting...') | 40 | 40 | print('Fitting...') | |
| popt, cov = curve_fit(func, T1, T4) | 41 | 41 | popt, cov = curve_fit(func, T1, T4) | |
| print(popt) | 42 | 42 | print(popt) | |
| Yfit = func(T1, *popt) | 43 | 43 | Yfit = func(T1, *popt) | |
| """ | 44 | 44 | """ | |
| timetamps = [datetime.datetime.fromtimestamp(ti) for ti in t] | 45 | 45 | timetamps = [datetime.datetime.fromtimestamp(ti) for ti in t] | |
| datenums=md.date2num(timetamps) | 46 | 46 | datenums=md.date2num(timetamps) | |
| 47 | 47 | |||
| plt.subplots_adjust(bottom=0.35) | 48 | 48 | plt.subplots_adjust(bottom=0.35) | |
| plt.xticks(rotation=90) | 49 | 49 | plt.xticks(rotation=90) | |
| ax=plt.gca() | 50 | 50 | ax=plt.gca() | |
| xfmt = md.DateFormatter('%Y-%m-%d %H:%M:%S') | 51 | 51 | xfmt = md.DateFormatter('%Y-%m-%d %H:%M:%S') | |
| ax.xaxis.set_major_formatter(xfmt) | 52 | 52 | ax.xaxis.set_major_formatter(xfmt) | |
| 53 | 53 |