source: ETALON/BPM/print_datas_lib.py @ 798

Last change on this file since 798 was 798, checked in by delerue, 6 years ago

Added Codesys directory

File size: 28.9 KB
Line 
1import numpy as np
2import matplotlib.pyplot as plt
3from scipy import stats
4import math
5from io import BytesIO
6
7
8global_index_figure = 0
9
10figure_size_in_hundreds_pixels=(12,8)
11
12
13
14def float_list(l, avoid = []): # convert a list of char in a list of float, and it avoid all data in the list of index that must be avoid
15    L = []
16    for i in range(len(l)):
17        if i in avoid:
18            L.append(l[i])
19        else:
20            L.append(float(l[i]))
21    return(L)
22
23def product_list(L,x, b = 0): # linear convertion of a list return L*x + b (b is 0 as default)
24    Lx = []
25    for i in L:
26        Lx.append(i*x +b)   
27    return(Lx)
28
29
30#print(read_first_line("data/test.txt"))
31
32"""    #other way to read data (without data of type different than float)
33def read_data(fichier): # program to read data from a file of data with position of motor and them Va, Vb, Vc and Vd
34    list_data_name = read_first_line(fichier) #create a list of the name of the data in the file
35    data = np.genfromtxt(fichier, delimiter=",", dtype="|U5", autostrip=True)# np.genfromtxt('data/test.txt', delimiter=' ', skip_header = 1) ### can't be use with other thiks than number
36    return(list_data_name,data)
37"""
38
39def read_line(line): # allow to read one line of the files
40    data_name = ""
41    list_data = []
42    for data_car in line:
43        if (data_car == " ") or (data_car == "\n"):
44            if data_name != "":
45                list_data.append(data_name)
46            data_name = ""
47        else:
48            data_name += data_car
49    return(list_data)
50
51def read_data(fichier): # program to read data from a file of data
52    data = open(fichier, 'r')
53    data_list = []
54    for line in data:
55        #print(line)
56        data_list.append(read_line(line))
57    data.close()
58    return(data_list[0],data_list[1:])
59
60def number_of_data_name(list_data_name, data_name): # give the number of a data in list_data_name with the name data_name
61    name_number = float('nan')
62    for number in range(len(list_data_name)):
63        if data_name == list_data_name[number]:
64            name_number = number
65    return(name_number)
66
67def convert_data(list_data_name, data): # convert data from string to int
68    data_avoid = number_of_data_name(list_data_name, "bpm_name") # all other data are string of float and must be convert in float
69    float_data = []
70    for sub_data in data:
71        float_data.append(float_list(sub_data, avoid = [data_avoid]))
72    return(float_data)
73
74def min_max(list_data_name, data, data_name):
75    number_data_name = number_of_data_name(list_data_name, data_name)
76    mini = data[0][number_data_name]
77    maxi = data[0][number_data_name]
78    for i in data:
79        if mini > i[number_data_name]:
80            mini = i[number_data_name]
81        if maxi < i[number_data_name]:
82            maxi = i[number_data_name]
83    return(mini,maxi)
84   
85#(list_data_name,data) = read_data("data/test.txt")
86#print(list_data_name)
87#print()
88#print(convert_data(list_data_name,data ))
89
90def all_value_of_data(list_data_name, data, data_name, data_name2 = None): #return a list that contain all different value that take data_name in data, data_name2 is to avoid 2 read of data for taken twice the same thing (used in moy_rms_data)
91    data_number = number_of_data_name(list_data_name, data_name)
92    #print(data_number)
93    all_data_name = []
94    if data_name2 is None:
95        for data_list in data:
96            #print(data_number)
97            #print(data_name)
98            #print(type(data_number))
99            if not(data_list[data_number] in all_data_name):
100                all_data_name.append(data_list[data_number])
101        return(all_data_name)
102    else:
103        data_number2 = number_of_data_name(list_data_name, data_name2)
104        all_data_name2 = []
105        for data_list in data:
106            if not(data_list[data_number] in all_data_name):
107                all_data_name.append(data_list[data_number])
108            if not(data_list[data_number2] in all_data_name2):
109                all_data_name2.append(data_list[data_number2])
110        return(all_data_name,all_data_name2)
111   
112#(list_data_name,data) = read_data("data/test.txt")   
113#print(all_value_of_data(list_data_name, data, "bpm_name", data_name2 = None))
114
115def cut_data(list_data_name, data, data_name, inf = None, equal = None, sup = None): # return list of data with were there is a contrain on the data name "data_name"
116    data_number = number_of_data_name(list_data_name, data_name)
117    list_of_keep_data = []
118    if data_number ==  float('nan'):
119        print("ERREUR in the name of cut data ")
120    elif not (inf is None):
121        if not (equal is None):
122            for value in range(len(data)):
123                if data[value][data_number] < inf or data[value][data_number] == equal:
124                    list_of_keep_data.append(value)
125        else:
126            for value in range(len(data)):
127                if data[value][data_number] < inf:
128                    list_of_keep_data.append(value)
129    elif not (sup is None):
130        if not (equal is None):
131            for value in range(len(data)):
132                if data[value][data_number] > sup or data[value][data_number] == equal:
133                    list_of_keep_data.append(value)
134        else:
135            for value in range(len(data)):
136                if data[value][data_number] > sup:
137                    list_of_keep_data.append(value)
138    elif not (equal is None):
139        for value in range(len(data)):
140            if data[value][data_number] == equal:
141                list_of_keep_data.append(value)
142    else:
143        return(data)
144    return([data[value] for value in list_of_keep_data])
145
146
147#def select_data(list_data_name, data, data_name1, data_name2, data_name3, data_name4)
148
149#def print_graph(list_data_name
150
151   
152#(list_data_name,data) = read_data("data/test.txt")
153#print(data)
154#print(cut_data(list_data_name, data, "bpm_name",equal = "bpm_E"))
155
156def moy_rms(list_data_name, data,data_name):
157    number_data_name = number_of_data_name(list_data_name, data_name)
158    moy = 0
159    rms = 0
160    data_len = float(len(data))
161    for data_list in data:
162        moy += data_list[number_data_name]/data_len
163    for data_list in data:
164        rms += (data_list[number_data_name] - moy)*(data_list[number_data_name] - moy)/data_len
165    return(moy,np.sqrt(rms))
166
167
168def moy_rms_data(list_data_name, data, x_data_name, y_data_name):
169    x_number_data_name = number_of_data_name(list_data_name, x_data_name)
170    moy_list = []
171    rms_list = []
172    X = []
173    if "bpm_name" in list_data_name:
174        bpm_number = number_of_data_name(list_data_name, "bpm_name")
175        all_bpm_name, all_x_data_name = all_value_of_data(list_data_name, data, data_name = "bpm_name", data_name2 = x_data_name)
176        for bpm_name in all_bpm_name:
177            cut_dat = cut_data(list_data_name, data, "bpm_name", equal = bpm_name)
178            for name in all_x_data_name:
179                moy,rms = moy_rms(list_data_name, cut_data(list_data_name, cut_dat, x_data_name, equal = name), y_data_name)
180                moy_list.append(moy)
181                rms_list.append(rms)
182                X.append(name)
183    else:
184        all_data_name = all_value_of_data(list_data_name, data, data_name = x_data_name)
185        for name in all_data_name:
186            moy,rms = moy_rms(list_data_name, cut_data(list_data_name, cut_data, x_data_name, equal = name), y_data_name)
187            moy_list.append(moy)
188            rms_list.append(rms)
189            X.append(name)
190    return(X,moy_list,rms_list)
191
192
193def linear_fonction_on_data(list_data_name, data, data_name, begin_mm = None, end_mm = None): # convert the data name data_name (use to length convertion)
194    if begin_mm is None and end_mm is None:
195        return(data)
196    number_data_name = number_of_data_name(list_data_name, data_name)
197    begin_step,end_step = min_max(list_data_name, data, data_name)
198    if begin_mm is None:
199        begin_mm = begin_step
200    if end_mm is None:
201        end_mm = end_step
202    if end_step == begin_step:
203        return(data)
204    a = float((end_mm - begin_mm))/(end_step - begin_step)
205    b = begin_mm - a*begin_step
206    #print(a,b)
207    for index in range(len(data)):
208        data[index][number_data_name] = a*data[index][number_data_name] + b
209    return(data)
210
211
212def plot_legend_fr(data_name): # return the legende in french for a graph according to the data read
213    if data_name == "bpm_name" :
214        return("Nom du BPM")
215    elif data_name == "bpm_number" :
216        return("Numero du BPM")
217    elif data_name == "x_motor_step" :
218        return("Coordonnee x d'apres le moteur (en million de pas)")
219    elif data_name == "x_motor_mm" :
220        return("Coordonnee x d'apres le moteur (en mm)")
221    elif data_name == "y_motor_step" :
222        return("Coordonnee y d'apres le moteur (en en million pas)")
223    elif data_name == "y_motor_mm" :
224        return("Coordonnee y d'apres la regle optique (en mm)")
225    elif data_name == "Va" :
226        return("Tension sur l'electrode a (en mV)")
227    elif data_name == "Vb" :
228        return("Tension sur l'electrode b (en mV)")
229    elif data_name == "Vc" :
230        return("Tension sur l'electrode c (en mV)")
231    elif data_name == "Vd" :
232        return("Tension sur l'electrode d (en mV)")
233    elif data_name == "Sum": 
234        return("Somme des tensions sur les electrodes (en mV)")
235    elif data_name == "x_libera_mm" :
236        return("Coordonnee x d'apres le Libera (en mm)")
237    elif data_name == "y_libera_mm" :
238        return("Coordonnee y d'apres le Libera (en mm)")
239    else:
240        print("unknow ask data_name named " + data_name)
241        return("Inconnue")
242
243
244
245def print_graph_fr(list_data_name, data, x_data_name, y_data_name, index_figure, color = "r",title = None, legende = None, lin_reg = None, rms = None, centrage = None): # program to print graph of y_data_name vs x_data_name in french
246    fig1 = plt.figure(index_figure,figsize=figure_size_in_hundreds_pixels, dpi=100)
247    if not(centrage is None):
248        mini,maxi =  min_max(list_data_name, data, x_data_name)
249        data = linear_fonction_on_data(list_data_name, data, x_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
250        mini,maxi =  min_max(list_data_name, data, y_data_name)
251        data = linear_fonction_on_data(list_data_name, data, y_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
252    if rms is None:
253        x_data_number = number_of_data_name(list_data_name, x_data_name)
254        X = [i[x_data_number] for i in data]
255        y_data_number = number_of_data_name(list_data_name, y_data_name)
256        Y = [i[y_data_number] for i in data]
257        rms = [0 for i in data]
258    else:
259        X,Y,rms = moy_rms_data(list_data_name, data, x_data_name, y_data_name)
260    if (x_data_name == "x_motor_step") or (x_data_name == "y_motor_step"):
261        X = [i/1000000. for i in X]
262    if y_data_name == "x_motor_step" or y_data_name == "y_motor_step":
263        Y = [i[y_data_number]/1000000. for i in data]
264    if not(lin_reg is None):
265        plt.plot(X,Y, color+".")
266        slope, intercept, r_value, p_value, std_err = stats.linregress(X,Y) # return tuple (pente,ordonnee a l'origine, coef de correlation, p-value, erreur standard de l'estimation)
267        if legende is None:
268#            plt.plot(X,[slope*i + intercept for i in X], color+"--", label =  " regression lineaire, \nerreur = "+str(round(std_err,3))+",\ncoefficient de correlation = "+str(round(r_value,3)) + "\npente de la regression lineaire = " + str(round(slope,3)))
269            plt.plot(X,[slope*i + intercept for i in X], color+"--")
270        else:
271            plt.plot(X,[slope*i + intercept for i in X], color+"--", label = legende + " : reg. lin, \nerr = "+str(round(std_err,3))+",\ncoef correl = "+str(round(r_value,3))+ "\npente = " + str(round(slope,3)))           
272            plt.legend(fontsize=15,bbox_to_anchor=(1.11, 1.11))           
273    else:
274        if legende is None:
275            plt.plot(X,Y, color+".")
276            plt.errorbar(X,Y,yerr = rms, ecolor = color)
277        else:
278            plt.plot(X,Y, color+".", label = legende)
279            plt.errorbar(X,Y,yerr = rms, ecolor = color)
280
281    x_label = plot_legend_fr(x_data_name)
282    y_label = plot_legend_fr(y_data_name)
283    plt.xlabel(x_label, fontsize=20)
284    plt.ylabel(y_label, fontsize=20)
285    if title is None:
286        plt.title(y_label + " en fonction de " + x_label, fontsize=20)
287    else:
288        plt.title(title, fontsize=20)
289    plt.gca().xaxis.set_tick_params(labelsize = 15)
290    plt.gca().yaxis.set_tick_params(labelsize = 15)
291
292   
293
294#(list_data_name,data) = read_data("data/test.txt")
295#data = convert_data(list_data_name, data)
296#print_graph_fr(list_data_name, data, "x_motor_mm", "x_motor_step", 1, color = "r", legende = "BPM_C", lin_reg = "true")
297
298#print_graph_fr(list_data_name, data, "x_motor_mm", "x_motor_step", 1, color = "b", legende = "BPM_C", lin_reg = "true")
299
300
301
302
303
304def plot_legend(data_name): # return the legende in english for a graph according to the data read
305    if data_name == "bpm_name" :
306        return("BPM name")
307    elif data_name == "bpm_number" :
308        return("BPM number")
309    elif data_name == "x_motor_step" :
310        return("x coordinate acording to motor (in step)")
311    elif data_name == "x_motor_mm" :
312        return("x coordinate acording to motor (in mm)")
313    elif data_name == "y_motor_step" :
314        return("y coordinate acording to motor (in step)")
315    elif data_name == "y_motor_mm" :
316        return("y coordinate acording the optical rule (in mm)")
317    elif data_name == "Va" :
318        return("Tension on electrode a (in mV)")
319    elif data_name == "Vb" :
320        return("Tension on electrode b (in mV)")
321    elif data_name == "Vc" :
322        return("Tension on electrode c (in mV)")
323    elif data_name == "Vd" :
324        return("Tension on electrode d (in mV)")
325    elif data_name == "Sum": 
326        return("Sum of tensions on electrodes (in mV)")
327    elif data_name == "x_libera_mm" :
328        return("x coordinate acording to Libera (in mm)")
329    elif data_name == "y_libera_mm" :
330        return("y coordonnee acording to Libera (in mm)")
331    elif data_name == "x_libera_um" :
332        return("x coordinate acording to Libera (in um)")
333    elif data_name == "y_libera_um" :
334        return("x coordonnee acording to Libera (in um)")
335    else:
336        print("unknow ask data_name named " + data_name)
337        return("Inconnue")
338
339   
340def print_graph(list_data_name, data, x_data_name, y_data_name, index_figure, color = "r",title = None, legende = None, lin_reg = None, rms = None, centrage = None):  # program to print graph of y_data_name vs x_data_name in english
341    if not(centrage is None):
342        mini,maxi =  min_max(list_data_name, data, x_data_name)
343        data = linear_fonction_on_data(list_data_name, data, x_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
344        mini,maxi =  min_max(list_data_name, data, y_data_name)
345        data = linear_fonction_on_data(list_data_name, data, y_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
346    fig1 = plt.figure(index_figure,figsize=figure_size_in_hundreds_pixels, dpi=100)
347    if rms is None:
348        x_data_number = number_of_data_name(list_data_name, x_data_name)
349        X = [i[x_data_number] for i in data]
350        y_data_number = number_of_data_name(list_data_name, y_data_name)
351        Y = [i[y_data_number] for i in data]
352        rms = [0 for i in data]
353    else:
354        X,Y,rms = moy_rms_data(list_data_name, data, x_data_name, y_data_name)
355    if (x_data_name == "x_motor_step") or (x_data_name == "y_motor_step"):
356        X = [i/1000000. for i in X]
357    if y_data_name == "x_motor_step" or y_data_name == "y_motor_step":
358        Y = [i[y_data_number]/1000000. for i in data]
359    if legende is None:
360        plt.plot(X,Y, color+".")
361        plt.errorbar(X,Y,yerr = rms, ecolor = color)
362    else:
363        plt.plot(X,Y, color+".", label = legende)
364        plt.errorbar(X,Y,yerr = rms, ecolor = color)
365    if not(lin_reg is None):
366        slope, intercept, r_value, p_value, std_err = stats.linregress(X,Y) # return tuple (pente,ordonnee a l'origine, coef de correlation, p-value, erreur standard de l'estimation)
367        if legende is None:
368#            plt.plot(X,[slope*i + intercept for i in X], color+"--", label =  "linear regression, \nerror = "+str(round(std_err,3))+",\ncorrelation coefficient = "+str(round(r_value,3)) + "\nslope = " + str(round(slope,3)))
369            plt.plot(X,[slope*i + intercept for i in X], color+"--")
370        else:
371            plt.plot(X,[slope*i + intercept for i in X], color+"--", label = legende + " : lineare regression, \nerror = "+str(round(std_err,3))+",\ncorrelation coefficient = "+str(round(r_value,3))+ "\nslope = " + str(round(slope,3)))
372            plt.legend(fontsize=15)
373    x_label = plot_legend(x_data_name)
374    y_label = plot_legend(y_data_name)
375    plt.xlabel(x_label, fontsize=20)
376    plt.ylabel(y_label, fontsize=20)
377    if title is None:
378        plt.title(y_label + " in fonction of " + x_label, fontsize=20)
379    else:
380        plt.title(title, fontsize=20)
381    plt.gca().xaxis.set_tick_params(labelsize = 15)
382    plt.gca().yaxis.set_tick_params(labelsize = 15)
383
384
385   
386def print_residu(list_data_name, data, x_data_name, y_data_name, index_figure, color = "r", legende = None , title = None, rms = None, centrage = None):  # program to print graph of residu of y_data_name vs x_data_name in english
387    if not(centrage is None):
388        mini,maxi =  min_max(list_data_name, data, x_data_name)
389        data = linear_fonction_on_data(list_data_name, data, x_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
390        mini,maxi =  min_max(list_data_name, data, y_data_name)
391        data = linear_fonction_on_data(list_data_name, data, y_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
392    fig1 = plt.figure(index_figure,figsize=figure_size_in_hundreds_pixels, dpi=100)
393    if rms is None:
394        x_data_number = number_of_data_name(list_data_name, x_data_name)
395        X = [i[x_data_number] for i in data]
396        y_data_number = number_of_data_name(list_data_name, y_data_name)
397        Y = [i[y_data_number] for i in data]
398        rms = [0 for i in data]
399    else:
400        X,Y,rms = moy_rms_data(list_data_name, data, x_data_name, y_data_name)
401    if (x_data_name == "x_motor_step") or (x_data_name == "y_motor_step"):
402        X = [i/1000000. for i in X]
403    if y_data_name == "x_motor_step" or y_data_name == "y_motor_step":
404        Y = [i[y_data_number]/1000000. for i in data]
405    slope, intercept, r_value, p_value, std_err  = stats.linregress(X,Y) # return tuple (pente,ordonnee a l'origine, coef de correlation, p-value, erreur standard de l'estimation)
406    for index in range(len(Y)):
407        Y[index] = abs(Y[index] - (slope*X[index] + intercept))
408    if legende is None:
409        plt.plot(X,Y, color+".")
410    else:
411        plt.plot(X,Y, color+".", label = legende)
412        plt.legend(fontsize=15)
413    x_label = plot_legend(x_data_name)
414    y_label = plot_legend(y_data_name)
415    plt.xlabel(x_label, fontsize=20)
416    plt.ylabel(y_label, fontsize=20)
417    if title is None:
418        plt.title("Residu of " + y_label + " in fonction of " + x_label, fontsize=20)
419    else:
420        plt.title("Residu of " + y_label + " in fonction of " + x_label + "\n" +title, fontsize=20)
421    plt.gca().xaxis.set_tick_params(labelsize = 15)
422    plt.gca().yaxis.set_tick_params(labelsize = 15)
423
424
425
426#(list_data_name,data) = read_data("data/test.txt")
427#data = convert_data(list_data_name, data)
428#print_residu(list_data_name, data, "x_motor_mm", "x_motor_step", 1, color = "r", legende = "BPM_C")
429
430
431
432
433def print_residu_fr(list_data_name, data, x_data_name, y_data_name, index_figure, color = "r", legende = None, title = None, rms = None, centrage = None):  # program to print graph of residu of y_data_name vs x_data_name in french
434    if not(centrage is None):
435        mini,maxi =  min_max(list_data_name, data, x_data_name)
436        data = linear_fonction_on_data(list_data_name, data, x_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
437        #mini,maxi =  min_max(list_data_name, data, y_data_name)
438        #data = linear_fonction_on_data(list_data_name, data, y_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
439    fig1 = plt.figure(index_figure,figsize=figure_size_in_hundreds_pixels, dpi=100)
440    if rms is None:
441        x_data_number = number_of_data_name(list_data_name, x_data_name)
442        X = [i[x_data_number] for i in data]
443        y_data_number = number_of_data_name(list_data_name, y_data_name)
444        Y = [i[y_data_number] for i in data]
445        rms = [0 for i in data]
446    else:
447        X,Y,rms = moy_rms_data(list_data_name, data, x_data_name, y_data_name)
448    if (x_data_name == "x_motor_step") or (x_data_name == "y_motor_step"):
449        X = [i/1000000. for i in X]
450    if y_data_name == "x_motor_step" or y_data_name == "y_motor_step":
451        Y = [i[y_data_number]/1000000. for i in data]
452    slope, intercept, r_value, p_value, std_err = stats.linregress(X,Y) # return tuple (pente,ordonnee a l'origine, coef de correlation, p-value, erreur standard de l'estimation)
453    moyenne = 0
454    len_Y = len(Y)
455    for index in range(len_Y):
456        Y[index] = abs(Y[index] - (slope*X[index] + intercept))
457        moyenne += Y[index]/len_Y
458    if legende is None:
459        plt.plot(X,Y, color+".")
460    else:
461        plt.plot(X,Y, color+".", label = legende + " residu moyen = " + str(round(moyenne,4)))
462        plt.legend(fontsize=15)
463    x_label = plot_legend_fr(x_data_name)
464    y_label = plot_legend_fr(y_data_name)
465    plt.xlabel(x_label, fontsize=20)
466    plt.ylabel(y_label, fontsize=20)
467    if title is None:
468        plt.title("Residu de " + y_label + "\nen fonction de " + x_label, fontsize=20)
469    else:
470        plt.title("Residu de " + y_label + "\nen fonction de " + x_label + "\n" +title, fontsize=20)
471    plt.gca().xaxis.set_tick_params(labelsize = 15)
472    plt.gca().yaxis.set_tick_params(labelsize = 15)
473
474
475"""
476(list_data_name,data) = read_data("data/bpm_name_bpm_number_x_motor_step_x_motor_mm_y_motor_step_y_motor_mm_Va_Vb_Vc_Vd_Sum_x_libera_mm_y_libera_mm_BPM0-E_BPM1-impr_BPM2-C_100pts-horizontal_3pts-vertical_20180801_0.txt")
477data = convert_data(list_data_name, data)
478print_graph(list_data_name, data, "x_motor_step", "x_libera_mm",0, color = "r", legende = "BPM_C", lin_reg = "true")
479print_residu_fr(list_data_name, data, "x_motor_mm", "x_motor_step", 1, color = "r", legende = "BPM_C")
480"""
481
482
483
484
485
486
487
488
489"""
490
491(list_data_name,data) = read_data("data/bpm_name_bpm_number_x_motor_step_x_motor_mm_y_motor_step_y_motor_mm_Va_Vb_Vc_Vd_Sum_x_libera_mm_y_libera_mm_BPM0-E_BPM1-impr_BPM2-C_100pts-horizontal_3pts-vertical_20180801_0.txt")
492data = convert_data(list_data_name, data)
493a,data = moy_rms_data(list_data_name, data, "x_motor_step", "x_libera_mm")
494#print(data)
495#print_graph(list_data_name, data, "x_motor_step", "x_libera_mm",0, color = "r", legende = "BPM_C", lin_reg = "true")
496#print_residu_fr(list_data_name, data, "x_motor_mm", "x_motor_step", 1, color = "r", legende = "BPM_C")
497"""
498
499def oposit_name(list_data_name, data_name, data_name2 = None):
500    if data_name[0] == "x":
501        if "y_motor_step" in list_data_name:
502            return("y_motor_step")
503    elif data_name[0] == "y":
504        if "x_motor_step" in list_data_name:
505            return("x_motor_step")
506    elif data_name[0] == "V":
507        if data_name2[0] == "x":
508            return("y_motor_step")
509        elif data_name2[0] == "y":
510            return("x_motor_step")
511    else:
512        print("ERROR MULTIPLE LINE")
513        return("")
514
515
516
517def graph_fr(fichier, x_data_name, y_data_name, lin_reg = None, residu = None, rms = None, x_begin_mm = None, x_end_mm = None, y_begin_mm = None, y_end_mm = None, x_minimal = None, x_maximal = None, y_minimal = None,  y_maximal = None, centrage = None, one_bpm = None, legende = "yes", save_figure = None):
518    (list_data_name,data) = read_data(fichier)
519    if not(x_data_name in list_data_name):
520        print("This x_data_name doesn't exist, choise within : ")
521        print(list_data_name)
522        return(0)
523    if not(y_data_name in list_data_name):
524        print("This y_data_name doesn't exist, choise within : ")
525        print(list_data_name)
526        return(0)
527    data = convert_data(list_data_name, data)
528    global global_index_figure # to creat different figure
529    linear_fonction_on_data(list_data_name, data, x_data_name, begin_mm = x_begin_mm, end_mm = x_end_mm)
530    linear_fonction_on_data(list_data_name, data, y_data_name, begin_mm = y_begin_mm, end_mm = y_end_mm)
531    print("Data size")
532    print(len(data))
533    if not(x_maximal is None):
534        data = cut_data(list_data_name, data, x_data_name, inf = x_maximal, equal = x_maximal)
535        print("x_maximal "+str(x_maximal))
536        print(len(data))
537    if not(x_minimal is None):
538        data = cut_data(list_data_name, data, x_data_name, sup = x_minimal, equal = x_minimal)
539        print("x_minimal "+str(x_minimal))
540        print(len(data))
541    if not(y_maximal is None):
542        print("y_maximal "+str(y_maximal))
543        data = cut_data(list_data_name, data, y_data_name, inf = y_maximal, equal = y_maximal)
544        print(len(data))
545    if not(y_minimal is None):
546        print("y_minimal "+str(y_minimal))
547        data = cut_data(list_data_name, data, y_data_name, sup = y_minimal, equal = y_minimal)
548        print(len(data))
549    if data == []:
550        print("cut to high")
551        return(0)
552    color_list = ["r","g","b","k","m","c","y"]
553    if "bpm_name" in list_data_name:
554        all_bpm_name = all_value_of_data(list_data_name, data, "bpm_name")
555        if not(one_bpm is None):
556            if one_bpm in all_bpm_name:
557                all_bpm_name = [one_bpm]
558            else:
559                print("This BPM doesn't exist, choise within : ")
560                print(all_bpm_name)
561                return(0)   
562        while len(all_bpm_name) > len(color_list):
563            color_list += color_list
564        oposit_y_data_name = oposit_name(list_data_name, y_data_name, x_data_name)
565        oposit_y_data_number = number_of_data_name(list_data_name, oposit_y_data_name)
566        if oposit_y_data_number == "":
567            for bpm_number in range(len(all_bpm_name)):
568                if not(legende is None):
569                    the_legend=all_bpm_name[bpm_number]
570                    print(the_legend)
571                else:
572                    the_legend=None
573                print_graph_fr(list_data_name, cut_data(list_data_name, data, "bpm_name", equal =  all_bpm_name[bpm_number]), x_data_name, y_data_name, global_index_figure, color = color_list[bpm_number], legende = the_legend, lin_reg = lin_reg, rms = rms, centrage = centrage)
574                if not(save_figure is None):
575                    plt.savefig(save_figure+'_'+str(global_index_figure)+'.png')
576                    print("Figure saved")
577                    print(save_figure+'_'+str(global_index_figure)+'.png')
578                if not(residu is None):
579                    print_residu_fr(list_data_name,  cut_data(list_data_name, data, "bpm_name", equal = all_bpm_name[bpm_number]), x_data_name, y_data_name, global_index_figure + 1, color_list[bpm_number], legende = the_legend, rms = rms, centrage = centrage)
580                    if not(save_figure is None):
581                        plt.savefig(save_figure+'_residu_'+str(global_index_figure)+'.png')
582            global_index_figure += 2
583        else:
584            all_oposit_y_value = all_value_of_data(list_data_name, data,oposit_y_data_name)
585            for index_value in range(len(all_oposit_y_value)):
586                data_cut =  cut_data(list_data_name, data, oposit_y_data_name, equal = all_oposit_y_value[index_value])
587                for bpm_number in range(len(all_bpm_name)):
588                    if not(legende is None):
589                        the_legend=all_bpm_name[bpm_number]
590                    else:
591                        the_legend=None
592                    #print(cut_data(list_data_name, data_cut, "bpm_name", equal =  all_bpm_name[bpm_number]))
593                    print_graph_fr(list_data_name, cut_data(list_data_name, data_cut, "bpm_name", equal =  all_bpm_name[bpm_number]), x_data_name, y_data_name, global_index_figure + 2*index_value, color = color_list[bpm_number], legende = the_legend, lin_reg = lin_reg, rms = rms, title = oposit_y_data_name + " = " + str(all_oposit_y_value[index_value]), centrage = centrage)
594                    if not(residu is None):
595                        print_residu_fr(list_data_name, cut_data(list_data_name, data_cut, "bpm_name", equal = all_bpm_name[bpm_number]), x_data_name, y_data_name, global_index_figure + 2*index_value + 1, color_list[bpm_number], legende = the_legend, rms = rms, title = oposit_y_data_name + " = " + str(all_oposit_y_value[index_value]), centrage = centrage)                       
596                if not(save_figure is None):
597                    plt.figure(global_index_figure + 2*index_value)
598                    plt.savefig(save_figure+'_'+str(global_index_figure + 2*index_value)+'.png')
599                    print("Figure saved")
600                    print(save_figure+'_'+str(global_index_figure + 2*index_value)+'.png')
601                    if not(residu is None):
602                        plt.figure(global_index_figure + 2*index_value+1)
603                        plt.savefig(save_figure+'_residu_'+str(global_index_figure + 2*index_value)+'.png')
604                global_index_figure += 2*len(all_oposit_y_value)
605    else: # need to be done, same as befor with "bpm_number" to replace "bpm_name"
606        print("ERROR TYPE OF DATA")
607
Note: See TracBrowser for help on using the repository browser.