1 | import numpy as np |
---|
2 | import matplotlib.pyplot as plt |
---|
3 | from scipy import stats |
---|
4 | |
---|
5 | def float_list(l): |
---|
6 | L = [] |
---|
7 | for i in l: |
---|
8 | L.append(float(i)) |
---|
9 | return(L) |
---|
10 | |
---|
11 | def product_list(L,x): |
---|
12 | Lx = [] |
---|
13 | for i in L: |
---|
14 | Lx.append(i*x) |
---|
15 | return(Lx) |
---|
16 | |
---|
17 | |
---|
18 | def read_data(fichier): |
---|
19 | fichier = open(fichier, "r") |
---|
20 | A = fichier.read() |
---|
21 | L = [[],[],[],[],[]] |
---|
22 | a = "" |
---|
23 | l = 0 |
---|
24 | for i in A: |
---|
25 | if (i == " ") : |
---|
26 | if l == 0: |
---|
27 | L[0].append(a) |
---|
28 | l +=1 |
---|
29 | elif l == 1: |
---|
30 | L[1].append(a) |
---|
31 | #print(a) |
---|
32 | l += 1 |
---|
33 | elif l == 2: |
---|
34 | L[2].append(a) |
---|
35 | l += 1 |
---|
36 | elif l == 3: |
---|
37 | L[3].append(a) |
---|
38 | l += 1 |
---|
39 | else: |
---|
40 | L[4].append(a) |
---|
41 | l = 0 |
---|
42 | a = "" |
---|
43 | elif (i == "\n") : |
---|
44 | a = "" |
---|
45 | else: |
---|
46 | a += i |
---|
47 | fichier.close() |
---|
48 | |
---|
49 | for i in range(5): |
---|
50 | L[i] = float_list(L[i]) |
---|
51 | L[0] = product_list(L[0],10**-6) |
---|
52 | for i in range(1,5): |
---|
53 | L[i] = product_list(L[i],1000) |
---|
54 | return(L) |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | def print_graph(L): |
---|
59 | # a = np.array([L[0][i],L[1][i]] for i in range(len(L[0]))) |
---|
60 | fig = plt.figure(1) |
---|
61 | plt.clf() |
---|
62 | lr1 = stats.linregress(L[0],L[1]) # return tuple (pente,ordonnee a l'origine, coef de correlation, p-value, erreur standard de l'estimation) |
---|
63 | plt.plot(L[0],L[1], "r", label = "BMP_ref") |
---|
64 | plt.plot(L[0],[lr1.slope*i + lr1.intercept for i in L[0]], "r--", label = "BMP_ref regression line, \nerror = "+str(lr1.stderr)+",\ncorrelation coefficient = "+str(lr1.rvalue)) |
---|
65 | |
---|
66 | lr2 = stats.linregress(L[0],L[2]) |
---|
67 | plt.plot(L[0],L[2], "b", label = "BMP_impr") |
---|
68 | plt.plot(L[0],[lr2.slope*i + lr2.intercept for i in L[0]], "b--", label = "BMP_impr regression line, \nerror = "+str(lr2.stderr)+",\ncorrelation coefficient = "+str(lr2.rvalue)) |
---|
69 | |
---|
70 | lr3 = stats.linregress(L[0],L[3]) |
---|
71 | plt.plot(L[0],L[3], "g", label = "BMP_ref") |
---|
72 | plt.plot(L[0],[lr3.slope*i + lr3.intercept for i in L[0]], "g--", label = "BMP_ref regression line, \nerror = "+str(lr3.stderr)+",\ncorrelation coefficient = "+str(lr3.rvalue)) |
---|
73 | |
---|
74 | lr4 = stats.linregress(L[0],L[4]) |
---|
75 | plt.plot(L[0],L[4], "m", label = "BMP_impr") |
---|
76 | plt.plot(L[0],[lr4.slope*i + lr4.intercept for i in L[0]], "m--", label = "BMP_impr regression line, \nerror = "+str(lr4.stderr)+",\ncorrelation coefficient = "+str(lr4.rvalue)) |
---|
77 | |
---|
78 | plt.legend() |
---|
79 | plt.xlabel("length in million motor step") |
---|
80 | plt.ylabel("tension in mV") |
---|
81 | plt.show() |
---|
82 | |
---|
83 | def residu(L): |
---|
84 | fig = plt.figure(1) |
---|
85 | plt.clf() |
---|
86 | plt.title("Residu") |
---|
87 | lr1 = stats.linregress(L[0],L[1]) # return tuple (pente (.slope),ordonnee a l'origine (.intercept), coef de correlation (.rvalue), p-value (.pvalue ?), erreur standard de l'estimation (.stderr)) |
---|
88 | for i in range(len(L[1])): |
---|
89 | L[1][i] = L[1][i] - lr1.slope*L[0][i] - lr1.intercept |
---|
90 | plt.plot(L[0],L[1], "r", label = "BMP_ref") |
---|
91 | |
---|
92 | lr2 = stats.linregress(L[0],L[2]) |
---|
93 | for i in range(len(L[2])): |
---|
94 | L[2][i] = L[2][i] - lr1.slope*L[0][i] - lr1.intercept |
---|
95 | plt.plot(L[0],L[2], "b", label = "BMP_impr") |
---|
96 | |
---|
97 | lr3 = stats.linregress(L[0],L[3]) |
---|
98 | for i in range(len(L[3])): |
---|
99 | L[3][i] = L[3][i] - lr1.slope*L[0][i] - lr1.intercept |
---|
100 | plt.plot(L[0],L[3], "g", label = "BMP_ref") |
---|
101 | |
---|
102 | lr4 = stats.linregress(L[0],L[4]) |
---|
103 | for i in range(len(L[4])): |
---|
104 | L[4][i] = L[4][i] - lr1.slope*L[0][i] - lr1.intercept |
---|
105 | plt.plot(L[0],L[4], "m", label = "BMP_impr") |
---|
106 | plt.legend() |
---|
107 | plt.xlabel("length in million motor step") |
---|
108 | plt.ylabel("tension in mV") |
---|
109 | plt.show() |
---|
110 | |
---|
111 | """ |
---|
112 | ax2 = fig.add_axes((0.1,0.1,0.8,0.0)) |
---|
113 | ax2.yaxis.set_visible(False) # hide the yaxis |
---|
114 | ax2.set_xticklabels(10*L[0]) |
---|
115 | ax2.set_xlabel("lenght in mm") |
---|
116 | plt.show() |
---|
117 | """ |
---|
118 | def print_data(fichier): |
---|
119 | L = read_data(fichier) |
---|
120 | print_graph(L) |
---|
121 | |
---|
122 | def print_residu(fichier): |
---|
123 | L = read_data(fichier) |
---|
124 | residu(L) |
---|
125 | |
---|
126 | print_data("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_20180611_160153_0.txt") |
---|
127 | print_residu("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_20180611_160153_0.txt") |
---|
128 | |
---|
129 | #print_data("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_20180611_163036_0.txt") |
---|
130 | |
---|
131 | #print_data("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_vertical_acquisition_20180612_0.txt") |
---|
132 | #print_data("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_vertical_acquisition_20180612_0.txt") |
---|