Index: /BPM/print_datas.py
===================================================================
--- /BPM/print_datas.py	(revision 793)
+++ /BPM/print_datas.py	(revision 794)
@@ -4,559 +4,10 @@
 import math
 from io import BytesIO
-
+#import sys
+#sys.path.append('.')
+from print_datas_lib import *
 
 global_index_figure = 0
 
-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
-    L = []
-    for i in range(len(l)):
-        if i in avoid:
-            L.append(l[i])
-        else:
-            L.append(float(l[i]))
-    return(L)
-
-def product_list(L,x, b = 0): # linear convertion of a list return L*x + b (b is 0 as default) 
-    Lx = []
-    for i in L:
-        Lx.append(i*x +b)   
-    return(Lx)
-
-
-#print(read_first_line("data/test.txt"))
-
-"""    #other way to read data (without data of type different than float)
-def read_data(fichier): # program to read data from a file of data with position of motor and them Va, Vb, Vc and Vd
-    list_data_name = read_first_line(fichier) #create a list of the name of the data in the file
-    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
-    return(list_data_name,data)
-"""
-
-def read_line(line): # allow to read one line of the files
-    data_name = ""
-    list_data = []
-    for data_car in line:
-        if (data_car == " ") or (data_car == "\n"):
-            if data_name != "":
-                list_data.append(data_name)
-            data_name = ""
-        else:
-            data_name += data_car
-    return(list_data)
-
-def read_data(fichier): # program to read data from a file of data 
-    data = open(fichier, 'r')
-    data_list = []
-    for line in data:
-        #print(line)
-        data_list.append(read_line(line))
-    data.close()
-    return(data_list[0],data_list[1:])
-
-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
-    name_number = float('nan')
-    for number in range(len(list_data_name)):
-        if data_name == list_data_name[number]:
-            name_number = number
-    return(name_number)
-
-def convert_data(list_data_name, data): # convert data from string to int 
-    data_avoid = number_of_data_name(list_data_name, "bpm_name") # all other data are string of float and must be convert in float
-    float_data = []
-    for sub_data in data:
-        float_data.append(float_list(sub_data, avoid = [data_avoid]))
-    return(float_data)
-
-def min_max(list_data_name, data, data_name):
-    number_data_name = number_of_data_name(list_data_name, data_name)
-    mini = data[0][number_data_name]
-    maxi = data[0][number_data_name]
-    for i in data:
-        if mini > i[number_data_name]:
-            mini = i[number_data_name]
-        if maxi < i[number_data_name]:
-            maxi = i[number_data_name]
-    return(mini,maxi)
-    
-#(list_data_name,data) = read_data("data/test.txt")
-#print(list_data_name)
-#print()
-#print(convert_data(list_data_name,data ))
-
-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)
-    data_number = number_of_data_name(list_data_name, data_name)
-    #print(data_number)
-    all_data_name = []
-    if data_name2 is None:
-        for data_list in data:
-            #print(data_number)
-            #print(data_name)
-            #print(type(data_number))
-            if not(data_list[data_number] in all_data_name):
-                all_data_name.append(data_list[data_number])
-        return(all_data_name)
-    else:
-        data_number2 = number_of_data_name(list_data_name, data_name2)
-        all_data_name2 = []
-        for data_list in data:
-            if not(data_list[data_number] in all_data_name):
-                all_data_name.append(data_list[data_number])
-            if not(data_list[data_number2] in all_data_name2):
-                all_data_name2.append(data_list[data_number2])
-        return(all_data_name,all_data_name2)
-    
-#(list_data_name,data) = read_data("data/test.txt")    
-#print(all_value_of_data(list_data_name, data, "bpm_name", data_name2 = None))
-
-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"
-    data_number = number_of_data_name(list_data_name, data_name)
-    list_of_keep_data = []
-    if data_number ==  float('nan'):
-        print("ERREUR in the name of cut data ")
-    elif not (inf is None):
-        if not (equal is None):
-            for value in range(len(data)):
-                if data[value][data_number] < inf or data[value][data_number] == equal:
-                    list_of_keep_data.append(value)
-        else:
-            for value in range(len(data)):
-                if data[value][data_number] < inf:
-                    list_of_keep_data.append(value)
-    elif not (sup is None):
-        if not (equal is None):
-            for value in range(len(data)):
-                if data[value][data_number] > sup or data[value][data_number] == equal:
-                    list_of_keep_data.append(value)
-        else:
-            for value in range(len(data)):
-                if data[value][data_number] > sup:
-                    list_of_keep_data.append(value)
-    elif not (equal is None):
-        for value in range(len(data)):
-            if data[value][data_number] == equal:
-                list_of_keep_data.append(value)
-    else:
-        return(data)
-    return([data[value] for value in list_of_keep_data])
-
-
-#def select_data(list_data_name, data, data_name1, data_name2, data_name3, data_name4)
-
-#def print_graph(list_data_name
-
-    
-#(list_data_name,data) = read_data("data/test.txt")
-#print(data)
-#print(cut_data(list_data_name, data, "bpm_name",equal = "bpm_E"))
-
-def moy_rms(list_data_name, data,data_name):
-    number_data_name = number_of_data_name(list_data_name, data_name)
-    moy = 0
-    rms = 0
-    data_len = float(len(data))
-    for data_list in data:
-        moy += data_list[number_data_name]/data_len
-    for data_list in data:
-        rms += (data_list[number_data_name] - moy)*(data_list[number_data_name] - moy)/data_len
-    return(moy,np.sqrt(rms))
-
-
-def moy_rms_data(list_data_name, data, x_data_name, y_data_name):
-    x_number_data_name = number_of_data_name(list_data_name, x_data_name)
-    moy_list = []
-    rms_list = []
-    X = []
-    if "bpm_name" in list_data_name:
-        bpm_number = number_of_data_name(list_data_name, "bpm_name")
-        all_bpm_name, all_x_data_name = all_value_of_data(list_data_name, data, data_name = "bpm_name", data_name2 = x_data_name)
-        for bpm_name in all_bpm_name:
-            cut_dat = cut_data(list_data_name, data, "bpm_name", equal = bpm_name)
-            for name in all_x_data_name:
-                moy,rms = moy_rms(list_data_name, cut_data(list_data_name, cut_dat, x_data_name, equal = name), y_data_name)
-                moy_list.append(moy)
-                rms_list.append(rms)
-                X.append(name)
-    else:
-        all_data_name = all_value_of_data(list_data_name, data, data_name = x_data_name)
-        for name in all_data_name:
-            moy,rms = moy_rms(list_data_name, cut_data(list_data_name, cut_data, x_data_name, equal = name), y_data_name)
-            moy_list.append(moy)
-            rms_list.append(rms)
-            X.append(name)
-    return(X,moy_list,rms_list)
-
-
-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) 
-    if begin_mm is None and end_mm is None:
-        return(data)
-    number_data_name = number_of_data_name(list_data_name, data_name)
-    begin_step,end_step = min_max(list_data_name, data, data_name)
-    if begin_mm is None:
-        begin_mm = begin_step
-    if end_mm is None:
-        end_mm = end_step
-    if end_step == begin_step:
-        return(data)
-    a = float((end_mm - begin_mm))/(end_step - begin_step)
-    b = begin_mm - a*begin_step
-    #print(a,b)
-    for index in range(len(data)):
-        data[index][number_data_name] = a*data[index][number_data_name] + b
-    return(data)
-
-
-def plot_legend_fr(data_name): # return the legende in french for a graph according to the data read
-    if data_name == "bpm_name" :
-        return("Nom du BPM")
-    elif data_name == "bpm_number" :
-        return("Numero du BPM")
-    elif data_name == "x_motor_step" :
-        return("Coordonnee x d'apres le moteur (en million de pas)")
-    elif data_name == "x_motor_mm" :
-        return("Coordonnee x d'apres le moteur (en mm)")
-    elif data_name == "y_motor_step" :
-        return("Coordonnee y d'apres le moteur (en en million pas)")
-    elif data_name == "y_motor_mm" :
-        return("Coordonnee y d'apres la regle optique (en mm)")
-    elif data_name == "Va" :
-        return("Tension sur l'electrode a (en mV)")
-    elif data_name == "Vb" :
-        return("Tension sur l'electrode b (en mV)")
-    elif data_name == "Vc" :
-        return("Tension sur l'electrode c (en mV)")
-    elif data_name == "Vd" :
-        return("Tension sur l'electrode d (en mV)")
-    elif data_name == "Sum": 
-        return("Somme des tensions sur les electrodes (en mV)")
-    elif data_name == "x_libera_mm" :
-        return("Coordonnee x d'apres le Libera (en mm)")
-    elif data_name == "y_libera_mm" :
-        return("Coordonnee y d'apres le Libera (en mm)")
-    else:
-        print("unknow ask data_name named " + data_name)
-        return("Inconnue")
-
-
-
-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
-    fig1 = plt.figure(index_figure)
-    if not(centrage is None):
-        mini,maxi =  min_max(list_data_name, data, x_data_name)
-        data = linear_fonction_on_data(list_data_name, data, x_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
-        mini,maxi =  min_max(list_data_name, data, y_data_name)
-        data = linear_fonction_on_data(list_data_name, data, y_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
-    if rms is None:
-        x_data_number = number_of_data_name(list_data_name, x_data_name)
-        X = [i[x_data_number] for i in data]
-        y_data_number = number_of_data_name(list_data_name, y_data_name)
-        Y = [i[y_data_number] for i in data]
-        rms = [0 for i in data]
-    else:
-        X,Y,rms = moy_rms_data(list_data_name, data, x_data_name, y_data_name)
-    if (x_data_name == "x_motor_step") or (x_data_name == "y_motor_step"):
-        X = [i/1000000. for i in X]
-    if y_data_name == "x_motor_step" or y_data_name == "y_motor_step":
-        Y = [i[y_data_number]/1000000. for i in data]
-    if legende is None:
-        plt.plot(X,Y, color+".")
-        plt.errorbar(X,Y,yerr = rms, ecolor = color)
-    else:
-        plt.plot(X,Y, color+".", label = legende)
-        plt.errorbar(X,Y,yerr = rms, ecolor = color)
-    if not(lin_reg is None):
-        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)
-        if legende is None:
-            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)))
-        else:
-            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)))            
-    plt.legend(fontsize=15)
-    x_label = plot_legend_fr(x_data_name)
-    y_label = plot_legend_fr(y_data_name)
-    plt.xlabel(x_label, fontsize=20)
-    plt.ylabel(y_label, fontsize=20)
-    if title is None:
-        plt.title(y_label + " en fonction de " + x_label, fontsize=20)
-    else:
-        plt.title(title, fontsize=20)
-    plt.gca().xaxis.set_tick_params(labelsize = 15)
-    plt.gca().yaxis.set_tick_params(labelsize = 15)
-
-    
-
-#(list_data_name,data) = read_data("data/test.txt")
-#data = convert_data(list_data_name, data)
-#print_graph_fr(list_data_name, data, "x_motor_mm", "x_motor_step", 1, color = "r", legende = "BPM_C", lin_reg = "true")
-
-#print_graph_fr(list_data_name, data, "x_motor_mm", "x_motor_step", 1, color = "b", legende = "BPM_C", lin_reg = "true")
-
-
-
-
-
-def plot_legend(data_name): # return the legende in english for a graph according to the data read
-    if data_name == "bpm_name" :
-        return("BPM name")
-    elif data_name == "bpm_number" :
-        return("BPM number")
-    elif data_name == "x_motor_step" :
-        return("x coordinate acording to motor (in step)")
-    elif data_name == "x_motor_mm" :
-        return("x coordinate acording to motor (in mm)")
-    elif data_name == "y_motor_step" :
-        return("y coordinate acording to motor (in step)")
-    elif data_name == "y_motor_mm" :
-        return("y coordinate acording the optical rule (in mm)")
-    elif data_name == "Va" :
-        return("Tension on electrode a (in mV)")
-    elif data_name == "Vb" :
-        return("Tension on electrode b (in mV)")
-    elif data_name == "Vc" :
-        return("Tension on electrode c (in mV)")
-    elif data_name == "Vd" :
-        return("Tension on electrode d (in mV)")
-    elif data_name == "Sum": 
-        return("Sum of tensions on electrodes (in mV)")
-    elif data_name == "x_libera_mm" :
-        return("x coordinate acording to Libera (in mm)")
-    elif data_name == "y_libera_mm" :
-        return("y coordonnee acording to Libera (in mm)")
-    elif data_name == "x_libera_um" :
-        return("x coordinate acording to Libera (in um)")
-    elif data_name == "y_libera_um" :
-        return("x coordonnee acording to Libera (in um)")
-    else:
-        print("unknow ask data_name named " + data_name)
-        return("Inconnue")
-
-    
-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
-    if not(centrage is None):
-        mini,maxi =  min_max(list_data_name, data, x_data_name)
-        data = linear_fonction_on_data(list_data_name, data, x_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
-        mini,maxi =  min_max(list_data_name, data, y_data_name)
-        data = linear_fonction_on_data(list_data_name, data, y_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
-    fig1 = plt.figure(index_figure)
-    if rms is None:
-        x_data_number = number_of_data_name(list_data_name, x_data_name)
-        X = [i[x_data_number] for i in data]
-        y_data_number = number_of_data_name(list_data_name, y_data_name)
-        Y = [i[y_data_number] for i in data]
-        rms = [0 for i in data]
-    else:
-        X,Y,rms = moy_rms_data(list_data_name, data, x_data_name, y_data_name)
-    if (x_data_name == "x_motor_step") or (x_data_name == "y_motor_step"):
-        X = [i/1000000. for i in X]
-    if y_data_name == "x_motor_step" or y_data_name == "y_motor_step":
-        Y = [i[y_data_number]/1000000. for i in data]
-    if legende is None:
-        plt.plot(X,Y, color+".")
-        plt.errorbar(X,Y,yerr = rms, ecolor = color)
-    else:
-        plt.plot(X,Y, color+".", label = legende)
-        plt.errorbar(X,Y,yerr = rms, ecolor = color)
-    if not(lin_reg is None):
-        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)
-        if legende is None:
-            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)))
-        else:
-            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)))
-            plt.legend(fontsize=15)
-    x_label = plot_legend(x_data_name)
-    y_label = plot_legend(y_data_name)
-    plt.xlabel(x_label, fontsize=20)
-    plt.ylabel(y_label, fontsize=20)
-    if title is None:
-        plt.title(y_label + " in fonction of " + x_label, fontsize=20)
-    else:
-        plt.title(title, fontsize=20)
-    plt.gca().xaxis.set_tick_params(labelsize = 15)
-    plt.gca().yaxis.set_tick_params(labelsize = 15)
-
-
-    
-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
-    if not(centrage is None):
-        mini,maxi =  min_max(list_data_name, data, x_data_name)
-        data = linear_fonction_on_data(list_data_name, data, x_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
-        mini,maxi =  min_max(list_data_name, data, y_data_name)
-        data = linear_fonction_on_data(list_data_name, data, y_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
-    fig1 = plt.figure(index_figure)
-    if rms is None:
-        x_data_number = number_of_data_name(list_data_name, x_data_name)
-        X = [i[x_data_number] for i in data]
-        y_data_number = number_of_data_name(list_data_name, y_data_name)
-        Y = [i[y_data_number] for i in data]
-        rms = [0 for i in data]
-    else:
-        X,Y,rms = moy_rms_data(list_data_name, data, x_data_name, y_data_name)
-    if (x_data_name == "x_motor_step") or (x_data_name == "y_motor_step"):
-        X = [i/1000000. for i in X]
-    if y_data_name == "x_motor_step" or y_data_name == "y_motor_step":
-        Y = [i[y_data_number]/1000000. for i in data]
-    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)
-    for index in range(len(Y)):
-        Y[index] = abs(Y[index] - (slope*X[index] + intercept))
-    if legende is None:
-        plt.plot(X,Y, color+".")
-    else:
-        plt.plot(X,Y, color+".", label = legende)
-        plt.legend(fontsize=15)
-    x_label = plot_legend(x_data_name)
-    y_label = plot_legend(y_data_name)
-    plt.xlabel(x_label, fontsize=20)
-    plt.ylabel(y_label, fontsize=20)
-    if title is None:
-        plt.title("Residu of " + y_label + " in fonction of " + x_label, fontsize=20)
-    else:
-        plt.title("Residu of " + y_label + " in fonction of " + x_label + "\n" +title, fontsize=20)
-    plt.gca().xaxis.set_tick_params(labelsize = 15)
-    plt.gca().yaxis.set_tick_params(labelsize = 15)
-
-
-
-#(list_data_name,data) = read_data("data/test.txt")
-#data = convert_data(list_data_name, data)
-#print_residu(list_data_name, data, "x_motor_mm", "x_motor_step", 1, color = "r", legende = "BPM_C")
-
-
-
-
-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
-    if not(centrage is None):
-        mini,maxi =  min_max(list_data_name, data, x_data_name)
-        data = linear_fonction_on_data(list_data_name, data, x_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
-        #mini,maxi =  min_max(list_data_name, data, y_data_name)
-        #data = linear_fonction_on_data(list_data_name, data, y_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
-    fig1 = plt.figure(index_figure)
-    if rms is None:
-        x_data_number = number_of_data_name(list_data_name, x_data_name)
-        X = [i[x_data_number] for i in data]
-        y_data_number = number_of_data_name(list_data_name, y_data_name)
-        Y = [i[y_data_number] for i in data]
-        rms = [0 for i in data]
-    else:
-        X,Y,rms = moy_rms_data(list_data_name, data, x_data_name, y_data_name)
-    if (x_data_name == "x_motor_step") or (x_data_name == "y_motor_step"):
-        X = [i/1000000. for i in X]
-    if y_data_name == "x_motor_step" or y_data_name == "y_motor_step":
-        Y = [i[y_data_number]/1000000. for i in data]
-    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)
-    moyenne = 0
-    len_Y = len(Y)
-    for index in range(len_Y):
-        Y[index] = abs(Y[index] - (slope*X[index] + intercept))
-        moyenne += Y[index]/len_Y
-    if legende is None:
-        plt.plot(X,Y, color+".")
-    else:
-        plt.plot(X,Y, color+".", label = legende + " residu moyen = " + str(round(moyenne,4)))
-    plt.legend(fontsize=15)
-    x_label = plot_legend_fr(x_data_name)
-    y_label = plot_legend_fr(y_data_name)
-    plt.xlabel(x_label, fontsize=20)
-    plt.ylabel(y_label, fontsize=20)
-    if title is None:
-        plt.title("Residu de " + y_label + "\nen fonction de " + x_label, fontsize=20)
-    else:
-        plt.title("Residu de " + y_label + "\nen fonction de " + x_label + "\n" +title, fontsize=20)
-    plt.gca().xaxis.set_tick_params(labelsize = 15)
-    plt.gca().yaxis.set_tick_params(labelsize = 15)
-
-
-"""
-(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")
-data = convert_data(list_data_name, data)
-print_graph(list_data_name, data, "x_motor_step", "x_libera_mm",0, color = "r", legende = "BPM_C", lin_reg = "true")
-print_residu_fr(list_data_name, data, "x_motor_mm", "x_motor_step", 1, color = "r", legende = "BPM_C")
-"""
-
-
-
-
-
-
-
-
-"""
-
-(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")
-data = convert_data(list_data_name, data)
-a,data = moy_rms_data(list_data_name, data, "x_motor_step", "x_libera_mm")
-#print(data)
-#print_graph(list_data_name, data, "x_motor_step", "x_libera_mm",0, color = "r", legende = "BPM_C", lin_reg = "true")
-#print_residu_fr(list_data_name, data, "x_motor_mm", "x_motor_step", 1, color = "r", legende = "BPM_C")
-"""
-
-def oposit_name(list_data_name, data_name, data_name2 = None):
-    if data_name[0] == "x":
-        if "y_motor_step" in list_data_name:
-            return("y_motor_step")
-    elif data_name[0] == "y":
-        if "x_motor_step" in list_data_name:
-            return("x_motor_step")
-    elif data_name[0] == "V":
-        if data_name2[0] == "x":
-            return("y_motor_step")
-        elif data_name2[0] == "y":
-            return("x_motor_step")
-    else:
-        print("ERROR MULTIPLE LINE")
-        return("")
-
-
-
-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):
-    (list_data_name,data) = read_data(fichier)
-    if not(x_data_name in list_data_name):
-        print("This x_data_name doesn't exist, choise within : ")
-        print(list_data_name)
-        return(0)
-    if not(y_data_name in list_data_name):
-        print("This y_data_name doesn't exist, choise within : ")
-        print(list_data_name)
-        return(0)
-    data = convert_data(list_data_name, data)
-    global global_index_figure # to creat different figure
-    linear_fonction_on_data(list_data_name, data, x_data_name, begin_mm = x_begin_mm, end_mm = x_end_mm)
-    linear_fonction_on_data(list_data_name, data, y_data_name, begin_mm = y_begin_mm, end_mm = y_end_mm)
-    data = cut_data(list_data_name, data, x_data_name, inf = x_maximal, equal = x_maximal)
-    data = cut_data(list_data_name, data, x_data_name, sup = x_minimal, equal = x_minimal)
-    data = cut_data(list_data_name, data, y_data_name, inf = y_maximal, equal = y_maximal)
-    data = cut_data(list_data_name, data, y_data_name, sup = y_minimal, equal = y_minimal)
-    if data == []:
-        print("cut to high")
-        return(0)
-    color_list = ["r","g","b","k","m","c","y"]
-    if "bpm_name" in list_data_name:
-        all_bpm_name = all_value_of_data(list_data_name, data, "bpm_name")
-        if not(one_bpm is None):
-            if one_bpm in all_bpm_name:
-                all_bpm_name = [one_bpm]
-            else:
-                print("This BPM doesn't exist, choise within : ")
-                print(all_bpm_name)
-                return(0)    
-        while len(all_bpm_name) > len(color_list):
-            color_list += color_list
-        oposit_y_data_name = oposit_name(list_data_name, y_data_name, x_data_name)
-        oposit_y_data_number = number_of_data_name(list_data_name, oposit_y_data_name)
-        if oposit_y_data_number == "":
-            for bpm_number in range(len(all_bpm_name)):
-                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)
-                if not(residu is None):
-                    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)
-            global_index_figure += 2
-        else:
-            all_oposit_y_value = all_value_of_data(list_data_name, data,oposit_y_data_name)
-            for index_value in range(len(all_oposit_y_value)):
-                data_cut =  cut_data(list_data_name, data, oposit_y_data_name, equal = all_oposit_y_value[index_value])
-                for bpm_number in range(len(all_bpm_name)):
-                    #print(cut_data(list_data_name, data_cut, "bpm_name", equal =  all_bpm_name[bpm_number]))
-                    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)
-                    if not(residu is None):
-                        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)
-            global_index_figure += 2*len(all_oposit_y_value)
-    else: # need to be done, same as befor with "bpm_number" to replace "bpm_name" 
-        print("ERROR TYPE OF DATA")
 
         
Index: /BPM/print_datas_lib.py
===================================================================
--- /BPM/print_datas_lib.py	(revision 794)
+++ /BPM/print_datas_lib.py	(revision 794)
@@ -0,0 +1,561 @@
+import numpy as np
+import matplotlib.pyplot as plt
+from scipy import stats
+import math
+from io import BytesIO
+
+
+global_index_figure = 0
+
+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
+    L = []
+    for i in range(len(l)):
+        if i in avoid:
+            L.append(l[i])
+        else:
+            L.append(float(l[i]))
+    return(L)
+
+def product_list(L,x, b = 0): # linear convertion of a list return L*x + b (b is 0 as default) 
+    Lx = []
+    for i in L:
+        Lx.append(i*x +b)   
+    return(Lx)
+
+
+#print(read_first_line("data/test.txt"))
+
+"""    #other way to read data (without data of type different than float)
+def read_data(fichier): # program to read data from a file of data with position of motor and them Va, Vb, Vc and Vd
+    list_data_name = read_first_line(fichier) #create a list of the name of the data in the file
+    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
+    return(list_data_name,data)
+"""
+
+def read_line(line): # allow to read one line of the files
+    data_name = ""
+    list_data = []
+    for data_car in line:
+        if (data_car == " ") or (data_car == "\n"):
+            if data_name != "":
+                list_data.append(data_name)
+            data_name = ""
+        else:
+            data_name += data_car
+    return(list_data)
+
+def read_data(fichier): # program to read data from a file of data 
+    data = open(fichier, 'r')
+    data_list = []
+    for line in data:
+        #print(line)
+        data_list.append(read_line(line))
+    data.close()
+    return(data_list[0],data_list[1:])
+
+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
+    name_number = float('nan')
+    for number in range(len(list_data_name)):
+        if data_name == list_data_name[number]:
+            name_number = number
+    return(name_number)
+
+def convert_data(list_data_name, data): # convert data from string to int 
+    data_avoid = number_of_data_name(list_data_name, "bpm_name") # all other data are string of float and must be convert in float
+    float_data = []
+    for sub_data in data:
+        float_data.append(float_list(sub_data, avoid = [data_avoid]))
+    return(float_data)
+
+def min_max(list_data_name, data, data_name):
+    number_data_name = number_of_data_name(list_data_name, data_name)
+    mini = data[0][number_data_name]
+    maxi = data[0][number_data_name]
+    for i in data:
+        if mini > i[number_data_name]:
+            mini = i[number_data_name]
+        if maxi < i[number_data_name]:
+            maxi = i[number_data_name]
+    return(mini,maxi)
+    
+#(list_data_name,data) = read_data("data/test.txt")
+#print(list_data_name)
+#print()
+#print(convert_data(list_data_name,data ))
+
+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)
+    data_number = number_of_data_name(list_data_name, data_name)
+    #print(data_number)
+    all_data_name = []
+    if data_name2 is None:
+        for data_list in data:
+            #print(data_number)
+            #print(data_name)
+            #print(type(data_number))
+            if not(data_list[data_number] in all_data_name):
+                all_data_name.append(data_list[data_number])
+        return(all_data_name)
+    else:
+        data_number2 = number_of_data_name(list_data_name, data_name2)
+        all_data_name2 = []
+        for data_list in data:
+            if not(data_list[data_number] in all_data_name):
+                all_data_name.append(data_list[data_number])
+            if not(data_list[data_number2] in all_data_name2):
+                all_data_name2.append(data_list[data_number2])
+        return(all_data_name,all_data_name2)
+    
+#(list_data_name,data) = read_data("data/test.txt")    
+#print(all_value_of_data(list_data_name, data, "bpm_name", data_name2 = None))
+
+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"
+    data_number = number_of_data_name(list_data_name, data_name)
+    list_of_keep_data = []
+    if data_number ==  float('nan'):
+        print("ERREUR in the name of cut data ")
+    elif not (inf is None):
+        if not (equal is None):
+            for value in range(len(data)):
+                if data[value][data_number] < inf or data[value][data_number] == equal:
+                    list_of_keep_data.append(value)
+        else:
+            for value in range(len(data)):
+                if data[value][data_number] < inf:
+                    list_of_keep_data.append(value)
+    elif not (sup is None):
+        if not (equal is None):
+            for value in range(len(data)):
+                if data[value][data_number] > sup or data[value][data_number] == equal:
+                    list_of_keep_data.append(value)
+        else:
+            for value in range(len(data)):
+                if data[value][data_number] > sup:
+                    list_of_keep_data.append(value)
+    elif not (equal is None):
+        for value in range(len(data)):
+            if data[value][data_number] == equal:
+                list_of_keep_data.append(value)
+    else:
+        return(data)
+    return([data[value] for value in list_of_keep_data])
+
+
+#def select_data(list_data_name, data, data_name1, data_name2, data_name3, data_name4)
+
+#def print_graph(list_data_name
+
+    
+#(list_data_name,data) = read_data("data/test.txt")
+#print(data)
+#print(cut_data(list_data_name, data, "bpm_name",equal = "bpm_E"))
+
+def moy_rms(list_data_name, data,data_name):
+    number_data_name = number_of_data_name(list_data_name, data_name)
+    moy = 0
+    rms = 0
+    data_len = float(len(data))
+    for data_list in data:
+        moy += data_list[number_data_name]/data_len
+    for data_list in data:
+        rms += (data_list[number_data_name] - moy)*(data_list[number_data_name] - moy)/data_len
+    return(moy,np.sqrt(rms))
+
+
+def moy_rms_data(list_data_name, data, x_data_name, y_data_name):
+    x_number_data_name = number_of_data_name(list_data_name, x_data_name)
+    moy_list = []
+    rms_list = []
+    X = []
+    if "bpm_name" in list_data_name:
+        bpm_number = number_of_data_name(list_data_name, "bpm_name")
+        all_bpm_name, all_x_data_name = all_value_of_data(list_data_name, data, data_name = "bpm_name", data_name2 = x_data_name)
+        for bpm_name in all_bpm_name:
+            cut_dat = cut_data(list_data_name, data, "bpm_name", equal = bpm_name)
+            for name in all_x_data_name:
+                moy,rms = moy_rms(list_data_name, cut_data(list_data_name, cut_dat, x_data_name, equal = name), y_data_name)
+                moy_list.append(moy)
+                rms_list.append(rms)
+                X.append(name)
+    else:
+        all_data_name = all_value_of_data(list_data_name, data, data_name = x_data_name)
+        for name in all_data_name:
+            moy,rms = moy_rms(list_data_name, cut_data(list_data_name, cut_data, x_data_name, equal = name), y_data_name)
+            moy_list.append(moy)
+            rms_list.append(rms)
+            X.append(name)
+    return(X,moy_list,rms_list)
+
+
+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) 
+    if begin_mm is None and end_mm is None:
+        return(data)
+    number_data_name = number_of_data_name(list_data_name, data_name)
+    begin_step,end_step = min_max(list_data_name, data, data_name)
+    if begin_mm is None:
+        begin_mm = begin_step
+    if end_mm is None:
+        end_mm = end_step
+    if end_step == begin_step:
+        return(data)
+    a = float((end_mm - begin_mm))/(end_step - begin_step)
+    b = begin_mm - a*begin_step
+    #print(a,b)
+    for index in range(len(data)):
+        data[index][number_data_name] = a*data[index][number_data_name] + b
+    return(data)
+
+
+def plot_legend_fr(data_name): # return the legende in french for a graph according to the data read
+    if data_name == "bpm_name" :
+        return("Nom du BPM")
+    elif data_name == "bpm_number" :
+        return("Numero du BPM")
+    elif data_name == "x_motor_step" :
+        return("Coordonnee x d'apres le moteur (en million de pas)")
+    elif data_name == "x_motor_mm" :
+        return("Coordonnee x d'apres le moteur (en mm)")
+    elif data_name == "y_motor_step" :
+        return("Coordonnee y d'apres le moteur (en en million pas)")
+    elif data_name == "y_motor_mm" :
+        return("Coordonnee y d'apres la regle optique (en mm)")
+    elif data_name == "Va" :
+        return("Tension sur l'electrode a (en mV)")
+    elif data_name == "Vb" :
+        return("Tension sur l'electrode b (en mV)")
+    elif data_name == "Vc" :
+        return("Tension sur l'electrode c (en mV)")
+    elif data_name == "Vd" :
+        return("Tension sur l'electrode d (en mV)")
+    elif data_name == "Sum": 
+        return("Somme des tensions sur les electrodes (en mV)")
+    elif data_name == "x_libera_mm" :
+        return("Coordonnee x d'apres le Libera (en mm)")
+    elif data_name == "y_libera_mm" :
+        return("Coordonnee y d'apres le Libera (en mm)")
+    else:
+        print("unknow ask data_name named " + data_name)
+        return("Inconnue")
+
+
+
+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
+    fig1 = plt.figure(index_figure)
+    if not(centrage is None):
+        mini,maxi =  min_max(list_data_name, data, x_data_name)
+        data = linear_fonction_on_data(list_data_name, data, x_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
+        mini,maxi =  min_max(list_data_name, data, y_data_name)
+        data = linear_fonction_on_data(list_data_name, data, y_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
+    if rms is None:
+        x_data_number = number_of_data_name(list_data_name, x_data_name)
+        X = [i[x_data_number] for i in data]
+        y_data_number = number_of_data_name(list_data_name, y_data_name)
+        Y = [i[y_data_number] for i in data]
+        rms = [0 for i in data]
+    else:
+        X,Y,rms = moy_rms_data(list_data_name, data, x_data_name, y_data_name)
+    if (x_data_name == "x_motor_step") or (x_data_name == "y_motor_step"):
+        X = [i/1000000. for i in X]
+    if y_data_name == "x_motor_step" or y_data_name == "y_motor_step":
+        Y = [i[y_data_number]/1000000. for i in data]
+    if legende is None:
+        plt.plot(X,Y, color+".")
+        plt.errorbar(X,Y,yerr = rms, ecolor = color)
+    else:
+        plt.plot(X,Y, color+".", label = legende)
+        plt.errorbar(X,Y,yerr = rms, ecolor = color)
+    if not(lin_reg is None):
+        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)
+        if legende is None:
+            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)))
+        else:
+            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)))            
+    plt.legend(fontsize=15)
+    x_label = plot_legend_fr(x_data_name)
+    y_label = plot_legend_fr(y_data_name)
+    plt.xlabel(x_label, fontsize=20)
+    plt.ylabel(y_label, fontsize=20)
+    if title is None:
+        plt.title(y_label + " en fonction de " + x_label, fontsize=20)
+    else:
+        plt.title(title, fontsize=20)
+    plt.gca().xaxis.set_tick_params(labelsize = 15)
+    plt.gca().yaxis.set_tick_params(labelsize = 15)
+
+    
+
+#(list_data_name,data) = read_data("data/test.txt")
+#data = convert_data(list_data_name, data)
+#print_graph_fr(list_data_name, data, "x_motor_mm", "x_motor_step", 1, color = "r", legende = "BPM_C", lin_reg = "true")
+
+#print_graph_fr(list_data_name, data, "x_motor_mm", "x_motor_step", 1, color = "b", legende = "BPM_C", lin_reg = "true")
+
+
+
+
+
+def plot_legend(data_name): # return the legende in english for a graph according to the data read
+    if data_name == "bpm_name" :
+        return("BPM name")
+    elif data_name == "bpm_number" :
+        return("BPM number")
+    elif data_name == "x_motor_step" :
+        return("x coordinate acording to motor (in step)")
+    elif data_name == "x_motor_mm" :
+        return("x coordinate acording to motor (in mm)")
+    elif data_name == "y_motor_step" :
+        return("y coordinate acording to motor (in step)")
+    elif data_name == "y_motor_mm" :
+        return("y coordinate acording the optical rule (in mm)")
+    elif data_name == "Va" :
+        return("Tension on electrode a (in mV)")
+    elif data_name == "Vb" :
+        return("Tension on electrode b (in mV)")
+    elif data_name == "Vc" :
+        return("Tension on electrode c (in mV)")
+    elif data_name == "Vd" :
+        return("Tension on electrode d (in mV)")
+    elif data_name == "Sum": 
+        return("Sum of tensions on electrodes (in mV)")
+    elif data_name == "x_libera_mm" :
+        return("x coordinate acording to Libera (in mm)")
+    elif data_name == "y_libera_mm" :
+        return("y coordonnee acording to Libera (in mm)")
+    elif data_name == "x_libera_um" :
+        return("x coordinate acording to Libera (in um)")
+    elif data_name == "y_libera_um" :
+        return("x coordonnee acording to Libera (in um)")
+    else:
+        print("unknow ask data_name named " + data_name)
+        return("Inconnue")
+
+    
+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
+    if not(centrage is None):
+        mini,maxi =  min_max(list_data_name, data, x_data_name)
+        data = linear_fonction_on_data(list_data_name, data, x_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
+        mini,maxi =  min_max(list_data_name, data, y_data_name)
+        data = linear_fonction_on_data(list_data_name, data, y_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
+    fig1 = plt.figure(index_figure)
+    if rms is None:
+        x_data_number = number_of_data_name(list_data_name, x_data_name)
+        X = [i[x_data_number] for i in data]
+        y_data_number = number_of_data_name(list_data_name, y_data_name)
+        Y = [i[y_data_number] for i in data]
+        rms = [0 for i in data]
+    else:
+        X,Y,rms = moy_rms_data(list_data_name, data, x_data_name, y_data_name)
+    if (x_data_name == "x_motor_step") or (x_data_name == "y_motor_step"):
+        X = [i/1000000. for i in X]
+    if y_data_name == "x_motor_step" or y_data_name == "y_motor_step":
+        Y = [i[y_data_number]/1000000. for i in data]
+    if legende is None:
+        plt.plot(X,Y, color+".")
+        plt.errorbar(X,Y,yerr = rms, ecolor = color)
+    else:
+        plt.plot(X,Y, color+".", label = legende)
+        plt.errorbar(X,Y,yerr = rms, ecolor = color)
+    if not(lin_reg is None):
+        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)
+        if legende is None:
+            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)))
+        else:
+            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)))
+            plt.legend(fontsize=15)
+    x_label = plot_legend(x_data_name)
+    y_label = plot_legend(y_data_name)
+    plt.xlabel(x_label, fontsize=20)
+    plt.ylabel(y_label, fontsize=20)
+    if title is None:
+        plt.title(y_label + " in fonction of " + x_label, fontsize=20)
+    else:
+        plt.title(title, fontsize=20)
+    plt.gca().xaxis.set_tick_params(labelsize = 15)
+    plt.gca().yaxis.set_tick_params(labelsize = 15)
+
+
+    
+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
+    if not(centrage is None):
+        mini,maxi =  min_max(list_data_name, data, x_data_name)
+        data = linear_fonction_on_data(list_data_name, data, x_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
+        mini,maxi =  min_max(list_data_name, data, y_data_name)
+        data = linear_fonction_on_data(list_data_name, data, y_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
+    fig1 = plt.figure(index_figure)
+    if rms is None:
+        x_data_number = number_of_data_name(list_data_name, x_data_name)
+        X = [i[x_data_number] for i in data]
+        y_data_number = number_of_data_name(list_data_name, y_data_name)
+        Y = [i[y_data_number] for i in data]
+        rms = [0 for i in data]
+    else:
+        X,Y,rms = moy_rms_data(list_data_name, data, x_data_name, y_data_name)
+    if (x_data_name == "x_motor_step") or (x_data_name == "y_motor_step"):
+        X = [i/1000000. for i in X]
+    if y_data_name == "x_motor_step" or y_data_name == "y_motor_step":
+        Y = [i[y_data_number]/1000000. for i in data]
+    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)
+    for index in range(len(Y)):
+        Y[index] = abs(Y[index] - (slope*X[index] + intercept))
+    if legende is None:
+        plt.plot(X,Y, color+".")
+    else:
+        plt.plot(X,Y, color+".", label = legende)
+        plt.legend(fontsize=15)
+    x_label = plot_legend(x_data_name)
+    y_label = plot_legend(y_data_name)
+    plt.xlabel(x_label, fontsize=20)
+    plt.ylabel(y_label, fontsize=20)
+    if title is None:
+        plt.title("Residu of " + y_label + " in fonction of " + x_label, fontsize=20)
+    else:
+        plt.title("Residu of " + y_label + " in fonction of " + x_label + "\n" +title, fontsize=20)
+    plt.gca().xaxis.set_tick_params(labelsize = 15)
+    plt.gca().yaxis.set_tick_params(labelsize = 15)
+
+
+
+#(list_data_name,data) = read_data("data/test.txt")
+#data = convert_data(list_data_name, data)
+#print_residu(list_data_name, data, "x_motor_mm", "x_motor_step", 1, color = "r", legende = "BPM_C")
+
+
+
+
+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
+    if not(centrage is None):
+        mini,maxi =  min_max(list_data_name, data, x_data_name)
+        data = linear_fonction_on_data(list_data_name, data, x_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
+        #mini,maxi =  min_max(list_data_name, data, y_data_name)
+        #data = linear_fonction_on_data(list_data_name, data, y_data_name, begin_mm = (mini - maxi)/2., end_mm = (maxi - mini)/2.)
+    fig1 = plt.figure(index_figure)
+    if rms is None:
+        x_data_number = number_of_data_name(list_data_name, x_data_name)
+        X = [i[x_data_number] for i in data]
+        y_data_number = number_of_data_name(list_data_name, y_data_name)
+        Y = [i[y_data_number] for i in data]
+        rms = [0 for i in data]
+    else:
+        X,Y,rms = moy_rms_data(list_data_name, data, x_data_name, y_data_name)
+    if (x_data_name == "x_motor_step") or (x_data_name == "y_motor_step"):
+        X = [i/1000000. for i in X]
+    if y_data_name == "x_motor_step" or y_data_name == "y_motor_step":
+        Y = [i[y_data_number]/1000000. for i in data]
+    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)
+    moyenne = 0
+    len_Y = len(Y)
+    for index in range(len_Y):
+        Y[index] = abs(Y[index] - (slope*X[index] + intercept))
+        moyenne += Y[index]/len_Y
+    if legende is None:
+        plt.plot(X,Y, color+".")
+    else:
+        plt.plot(X,Y, color+".", label = legende + " residu moyen = " + str(round(moyenne,4)))
+    plt.legend(fontsize=15)
+    x_label = plot_legend_fr(x_data_name)
+    y_label = plot_legend_fr(y_data_name)
+    plt.xlabel(x_label, fontsize=20)
+    plt.ylabel(y_label, fontsize=20)
+    if title is None:
+        plt.title("Residu de " + y_label + "\nen fonction de " + x_label, fontsize=20)
+    else:
+        plt.title("Residu de " + y_label + "\nen fonction de " + x_label + "\n" +title, fontsize=20)
+    plt.gca().xaxis.set_tick_params(labelsize = 15)
+    plt.gca().yaxis.set_tick_params(labelsize = 15)
+
+
+"""
+(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")
+data = convert_data(list_data_name, data)
+print_graph(list_data_name, data, "x_motor_step", "x_libera_mm",0, color = "r", legende = "BPM_C", lin_reg = "true")
+print_residu_fr(list_data_name, data, "x_motor_mm", "x_motor_step", 1, color = "r", legende = "BPM_C")
+"""
+
+
+
+
+
+
+
+
+"""
+
+(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")
+data = convert_data(list_data_name, data)
+a,data = moy_rms_data(list_data_name, data, "x_motor_step", "x_libera_mm")
+#print(data)
+#print_graph(list_data_name, data, "x_motor_step", "x_libera_mm",0, color = "r", legende = "BPM_C", lin_reg = "true")
+#print_residu_fr(list_data_name, data, "x_motor_mm", "x_motor_step", 1, color = "r", legende = "BPM_C")
+"""
+
+def oposit_name(list_data_name, data_name, data_name2 = None):
+    if data_name[0] == "x":
+        if "y_motor_step" in list_data_name:
+            return("y_motor_step")
+    elif data_name[0] == "y":
+        if "x_motor_step" in list_data_name:
+            return("x_motor_step")
+    elif data_name[0] == "V":
+        if data_name2[0] == "x":
+            return("y_motor_step")
+        elif data_name2[0] == "y":
+            return("x_motor_step")
+    else:
+        print("ERROR MULTIPLE LINE")
+        return("")
+
+
+
+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):
+    (list_data_name,data) = read_data(fichier)
+    if not(x_data_name in list_data_name):
+        print("This x_data_name doesn't exist, choise within : ")
+        print(list_data_name)
+        return(0)
+    if not(y_data_name in list_data_name):
+        print("This y_data_name doesn't exist, choise within : ")
+        print(list_data_name)
+        return(0)
+    data = convert_data(list_data_name, data)
+    global global_index_figure # to creat different figure
+    linear_fonction_on_data(list_data_name, data, x_data_name, begin_mm = x_begin_mm, end_mm = x_end_mm)
+    linear_fonction_on_data(list_data_name, data, y_data_name, begin_mm = y_begin_mm, end_mm = y_end_mm)
+    data = cut_data(list_data_name, data, x_data_name, inf = x_maximal, equal = x_maximal)
+    data = cut_data(list_data_name, data, x_data_name, sup = x_minimal, equal = x_minimal)
+    data = cut_data(list_data_name, data, y_data_name, inf = y_maximal, equal = y_maximal)
+    data = cut_data(list_data_name, data, y_data_name, sup = y_minimal, equal = y_minimal)
+    if data == []:
+        print("cut to high")
+        return(0)
+    color_list = ["r","g","b","k","m","c","y"]
+    if "bpm_name" in list_data_name:
+        all_bpm_name = all_value_of_data(list_data_name, data, "bpm_name")
+        if not(one_bpm is None):
+            if one_bpm in all_bpm_name:
+                all_bpm_name = [one_bpm]
+            else:
+                print("This BPM doesn't exist, choise within : ")
+                print(all_bpm_name)
+                return(0)    
+        while len(all_bpm_name) > len(color_list):
+            color_list += color_list
+        oposit_y_data_name = oposit_name(list_data_name, y_data_name, x_data_name)
+        oposit_y_data_number = number_of_data_name(list_data_name, oposit_y_data_name)
+        if oposit_y_data_number == "":
+            for bpm_number in range(len(all_bpm_name)):
+                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)
+                if not(residu is None):
+                    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)
+            global_index_figure += 2
+        else:
+            all_oposit_y_value = all_value_of_data(list_data_name, data,oposit_y_data_name)
+            for index_value in range(len(all_oposit_y_value)):
+                data_cut =  cut_data(list_data_name, data, oposit_y_data_name, equal = all_oposit_y_value[index_value])
+                for bpm_number in range(len(all_bpm_name)):
+                    #print(cut_data(list_data_name, data_cut, "bpm_name", equal =  all_bpm_name[bpm_number]))
+                    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)
+                    if not(residu is None):
+                        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)
+            global_index_figure += 2*len(all_oposit_y_value)
+    else: # need to be done, same as befor with "bpm_number" to replace "bpm_name" 
+        print("ERROR TYPE OF DATA")
+
