Changeset 780 in ETALON


Ignore:
Timestamp:
Jun 18, 2018, 5:32:04 PM (6 years ago)
Author:
moutardier
Message:

add fonction to select part of data and to convert lenght in step on lenght in mm in print_data.py and correct issue in residu

Location:
BPM
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • BPM/motor_control.py

    r779 r780  
    3737#horizontal_acquisition(4000,0,-4000,"test")   
    3838
    39 acquisition(-15000,15000,10000,-50000,50000,25000,"test")
     39acquisition(-100000,100000,20000,-50000,50000,10000,"test")
    4040
    4141#acquisition(-10000,10000,1000,-50000,0,5000,"test")
     
    5555
    5656#fichier = open("24-05-2018_acquisition_from_0_to_400000_step_of_1000.txt", "r")
    57 """
    58 A = fichier.read()
    59 
    60 X = []
    61 Y1 = []
    62 Y2 = []
    63 Y3 = []
    64 Y4 = []
    65 a = ""
    66 l = 0
    67 
    68 
    69 for i in A:
    70     if (i == "\n") :
    71          if l == 0:
    72              X.append(a)
    73              
    74              l += 1
    75          elif l == 1:
    76              Y1.append(a)
    77              #print(a)
    78              l += 1
    79          elif l == 2:
    80              Y2.append(a)
    81              l += 1
    82          elif l == 3:
    83              Y3.append(a)
    84              l += 1
    85          else:
    86              Y4.append(a)
    87              l = 0
    88          a = ""
    89     else:
    90         a += i
    91 
    92 def float_list(l):
    93     L = []
    94     for i in l:
    95         L.append(float(i))
    96     return(L)
    97    
    98 X = float_list(X)
    99 Y1 = float_list(Y1)
    100 Y2 = float_list(Y2)
    101 Y3 = float_list(Y3)
    102 Y4 = float_list(Y4)
    103 
    104 plt.plot(X,Y1)
    105 plt.plot(X,Y2)
    106 plt.plot(X,Y3)
    107 plt.plot(X,Y4)
    108 plt.show()
    109 """
    11057
    11158#fichier.close()
  • BPM/print_datas.py

    r779 r780  
    99    return(L)
    1010
    11 def product_list(L,x):
    12     Lx = []
    13     for i in L:
    14         Lx.append(i*x)
    15     return(Lx)
     11def product_list(L,x, b = None):
     12    if b is None:
     13        Lx = []
     14        for i in L:
     15            Lx.append(i*x)
     16        return(Lx)
     17    else:
     18        Lx = []
     19        for i in L:
     20            Lx.append(i*x +b)
     21        return(Lx)
    1622
    1723
     
    4652            a += i
    4753    fichier.close()
    48 
    4954    for i in range(5):
    5055        L[i] = float_list(L[i])
     
    6267    lr1 = stats.linregress(L[0],L[1]) # return tuple (pente,ordonnee a l'origine, coef de correlation, p-value, erreur standard de l'estimation)
    6368    plt.plot(L[0],L[1], "r", label = "BMP_ref")
    64     plt.plot(L[0],[lr1.slope*i + lr1.intercept for i in L[0]], "r--", label = "BMP_ref regression line, \nerror = "+str(lr1.stderr)+",\ncorrelation coefficient = "+str(lr1.rvalue))
     69    plt.plot(L[0],[lr1.slope*i + lr1.intercept for i in L[0]], "r--", label = "BMP_ref regression line, \nerror = "+str(round(lr1.stderr,3))+",\ncorrelation coefficient = "+str(round(lr1.rvalue,3)))
    6570   
    6671    lr2 = stats.linregress(L[0],L[2])
    6772    plt.plot(L[0],L[2], "b", label = "BMP_impr")
    68     plt.plot(L[0],[lr2.slope*i + lr2.intercept for i in L[0]], "b--", label = "BMP_impr regression line, \nerror = "+str(lr2.stderr)+",\ncorrelation coefficient = "+str(lr2.rvalue))
     73    plt.plot(L[0],[lr2.slope*i + lr2.intercept for i in L[0]], "b--", label = "BMP_impr regression line, \nerror = "+str(round(lr2.stderr,3))+",\ncorrelation coefficient = "+str(round(lr2.rvalue,3)))
    6974
    7075    lr3 = stats.linregress(L[0],L[3])
    7176    plt.plot(L[0],L[3], "g", label = "BMP_ref")
    72     plt.plot(L[0],[lr3.slope*i + lr3.intercept for i in L[0]], "g--", label = "BMP_ref regression line, \nerror = "+str(lr3.stderr)+",\ncorrelation coefficient = "+str(lr3.rvalue))
     77    plt.plot(L[0],[lr3.slope*i + lr3.intercept for i in L[0]], "g--", label = "BMP_ref regression line, \nerror = "+str(round(lr3.stderr,3))+",\ncorrelation coefficient = "+str(round(lr3.rvalue,3)))
    7378
    7479    lr4 = stats.linregress(L[0],L[4])
    7580    plt.plot(L[0],L[4], "m", label = "BMP_impr")
    76     plt.plot(L[0],[lr4.slope*i + lr4.intercept for i in L[0]], "m--", label = "BMP_impr regression line, \nerror = "+str(lr4.stderr)+",\ncorrelation coefficient = "+str(lr4.rvalue))
     81    plt.plot(L[0],[lr4.slope*i + lr4.intercept for i in L[0]], "m--", label = "BMP_impr regression line, \nerror = "+str(round(lr4.stderr,2))+",\ncorrelation coefficient = "+str(round(lr4.rvalue,3)))
    7782   
    7883    plt.legend()
     
    9297    lr2 = stats.linregress(L[0],L[2])
    9398    for i in range(len(L[2])):
    94         L[2][i] = L[2][i] -  lr1.slope*L[0][i] - lr1.intercept
     99        L[2][i] = L[2][i] -  lr2.slope*L[0][i] - lr2.intercept
    95100    plt.plot(L[0],L[2], "b", label = "BMP_impr")
    96101
    97102    lr3 = stats.linregress(L[0],L[3])
    98103    for i in range(len(L[3])):
    99         L[3][i] = L[3][i] -  lr1.slope*L[0][i] - lr1.intercept
     104        L[3][i] = L[3][i] -  lr3.slope*L[0][i] - lr3.intercept
    100105    plt.plot(L[0],L[3], "g", label = "BMP_ref")
    101106 
    102107    lr4 = stats.linregress(L[0],L[4])
    103108    for i in range(len(L[4])):
    104         L[4][i] = L[4][i] -  lr1.slope*L[0][i] - lr1.intercept
     109        L[4][i] = L[4][i] -  lr4.slope*L[0][i] - lr4.intercept
    105110    plt.plot(L[0],L[4], "m", label = "BMP_impr")
    106111    plt.legend()
     
    116121    plt.show()
    117122"""
    118 def print_data(fichier):
    119     L = read_data(fichier)
     123
     124def min_max(L,mini = None ,maxi = None):
     125    if mini is None :
     126        mini = -1
     127    if maxi is None :
     128        maxi = len(L[0])
     129    i_min = 0
     130    i_max = 0
     131    for i in range(len(L[0])):
     132        if  L[0][i] <= mini :
     133            i_min = i
     134        if  L[0][i] <= maxi :
     135            i_max = i
     136    if i_max < len(L[0]) :
     137        i_max += 1
     138    return([L[0][i_min:i_max],L[1][i_min:i_max],L[2][i_min:i_max],L[3][i_min:i_max],L[4][i_min:i_max]])
     139
     140
     141def convertion_step_mm(L,begin_mm,end_mm):
     142    begin_step = L[0]
     143    end_step = L[len(L)-1]
     144    a = float((end_mm - begin_mm))/(end_step - begin_step)
     145    b = begin_mm - a*begin_step
     146    print(a,b)
     147    print(L)
     148    L = product_list(L, a, b)
     149    return(L)
     150   
     151
     152#L = [[i for i in range(51)] for j in range(5)]
     153#print(convertion_step_mm(L[0],3.1,44520))
     154
     155   
     156def print_data(fichier, min = None, max = None):
     157    L = min_max(read_data(fichier),min,max)
    120158    print_graph(L)
     159    #print(L)
    121160
    122 def print_residu(fichier):
    123     L = read_data(fichier)
     161def print_residu(fichier, min = None, max = None):
     162    L = min_max(read_data(fichier), mini = min, maxi = max)
    124163    residu(L)
    125164
    126 print_data("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_20180611_160153_0.txt")
    127 print_residu("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_20180611_160153_0.txt")
     165#print_data("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_20180611_160153_0.txt",0.1,0.3)
     166#print_residu("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_20180611_160153_0.txt",0.1,0.3)
    128167
    129168#print_data("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_20180611_163036_0.txt")
Note: See TracChangeset for help on using the changeset viewer.