Changeset 794 in ETALON


Ignore:
Timestamp:
Aug 7, 2018, 11:24:46 AM (6 years ago)
Author:
delerue
Message:

BPM code split in two parts.

Location:
BPM
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • BPM/print_datas.py

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