Changeset 785 in ETALON


Ignore:
Timestamp:
Jul 19, 2018, 4:23:43 PM (6 years ago)
Author:
moutardier
Message:

change print_data to read data from libera

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BPM/print_datas.py

    r784 r785  
    2323    Data_list = [[[] for i in range(9)] for j in range(3)]
    2424    value = ""
    25     index = 0
     25    index = -1
    2626    for i in Data:
    2727        if (i == " ") :
    2828            if index == -1:
    2929                bpm_index = int(value)
    30                 Data_list[0].append(value)
    3130                index +=1
    32             elif index == 1:
    33                 Data_list[1].append(value)
    34                 #print(value)
    35                 index += 1
    36             elif index == 2:
    37                 Data_list[2].append(value)
    38                 index += 1
    39             elif index == 3:
    40                 Data_list[3].append(value)
    41                 index += 1
    4231            else:
    43                 Data_list[4].append(value)
    44                 index = 0
     32                Data_list[bpm_index][index].append(value)
     33                index += 1
    4534            value = ""
    4635        elif (i == "\n") :
    47             value = ""
     36            if value != "":
     37                Data_list[bpm_index][index].append(value)
     38                value = ""
    4839            index = -1
    4940        else:
    5041            value += i
    5142    fichier.close()
    52     for i in range(5):
    53         Data_list[i] = float_list(Data_list[i])
    54     Data_list[0] = product_list(Data_list[0],10**-6)
     43    for bpm in Data_list:
     44        for i in range(len(bpm)):
     45            bpm[i] = float_list(bpm[i])
     46    return(Data_list)
     47"""
     48
     49        bpm[0] = product_list(Data_list[0],10**-6)
     50
    5551    for i in range(1,5):
    5652        Data_list[i] = product_list(Data_list[i],1000)
    57     return(Data_list)
    58 
     53"""
    5954
    6055
     
    10095
    10196
    102 def print_graph(L): # program to print graph of X_libera vs X_motor with a list L = [[[x_motor_position][y_motor_position][Va][Vb][Vc][Vd][sum][x_libera_position][y_libera_position]][same for BPM1][same for BPM2]], also do a linear regretion and print the equation
     97def print_graph_xmotor_ymotor_Va_Vb_Vc_Vd_sum_x_y(data,lin_reg = None): # program to print graph of X_libera vs X_motor with a list data = [[[x_motor_position][y_motor_position][Va][Vb][Vc][Vd][sum][x_libera_position][y_libera_position]][same for BPM1][same for BPM2]],also do a linear regretion and print the equation
    10398    global global_index_figure # to creat different figure
    10499    fig1 = plt.figure(global_index_figure)
    105100    global_index_figure += 1
    106101    plt.clf()
    107     for bpm_data in range(L):
    108         lr1 = stats.linregress(bpm_data[0],bpm_data[7]) # return tuple (pente,ordonnee a l'origine, coef de correlation, p-value, erreur standard de l'estimation)
    109         plt.plot(bpm_data[0],bpm_data[7], "r", label = "BMP_ref")
    110         plt.plot(bpm_data[0],[lr1.slope*i + lr1.intercept for i in bpm_data[0]], "r--", label = "BMP_ref regression line, \nerror = "+str(round(lr1.stderr,3))+",\ncorrelation coefficient = "+str(round(lr1.rvalue,3)))
    111 
    112 
    113 
    114 
    115 
    116 
    117 
    118     """
    119     lr1 = stats.linregress(L[1],L[1]) # return tuple (pente,ordonnee a l'origine, coef de correlation, p-value, erreur standard de l'estimation)
     102    color = ["r","g","b"]
     103    legende = ["BPM soleil","BPM impr","BPM ref"]
     104    for bpm_number in range(len(data)):
     105        plt.plot(data[bpm_number][0],data[bpm_number][7], color[bpm_number]+".", label = legende[bpm_number])
     106        if lin_reg == "yes":
     107            lr1 = stats.linregress(data[bpm_number][0],data[bpm_number][7]) # return tuple (pente,ordonnee a l'origine, coef de correlation, p-value, erreur standard de l'estimation)
     108            plt.plot(data[bpm_number][0],[lr1.slope*i + lr1.intercept for i in data[bpm_number][0]], color[bpm_number]+"--", label = legende[bpm_number] + " regression line, \nerror = "+str(round(lr1.stderr,3))+",\ncorrelation coefficient = "+str(round(lr1.rvalue,3)))
     109    plt.legend()
     110    plt.xlabel("length in million motor step") #, fontsize=20)
     111    plt.ylabel("tension in mV")
     112    plt.gca().yaxis.set_tick_params(labelsize = 8)
     113       
     114
     115
     116
     117def print_graph_position_Va_Vb_Vc_Vd(L): # program to print graph of X_libera vs X_motor with a list L = [[position][Va][Vb][Vc][Vd]], also do a linear regretion and print the equation
     118    global global_index_figure # to creat different figure
     119    fig1 = plt.figure(global_index_figure)
     120    global_index_figure += 1
     121    plt.clf()
     122   
     123    lr1 = stats.linregress(L[0],L[1]) # return tuple (pente,ordonnee a l'origine, coef de correlation, p-value, erreur standard de l'estimation)
    120124    plt.plot(L[0],L[1], "r", label = "BMP_ref")
    121125    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)))
     
    138142    plt.gca().yaxis.set_tick_params(labelsize = 8)
    139143#    plt.show()
    140 """
     144
    141145def residu_position_Va_Vb_Vc_Vd(L): # program to do graph of residu of data give in a list with [[position][Va][Vb][Vc][Vd]]
    142146    global global_index_figure
     
    177181"""
    178182
    179 def min_max(L,mini = None ,maxi = None): #program to cut a list L = [[position][Va][Vb][Vc][Vd]] with minimum value of position = mini and maximum value of position = maxi
    180     if mini is None :
    181         mini = L[0][0]
    182     if maxi is None :
    183         maxi = L[0][len(L[0])-1]
    184     if mini > maxi:
    185         mini,maxi = maxi,mini
     183
     184
     185
     186
     187
     188
     189def residu_xmotor_ymotor_Va_Vb_Vc_Vd_sum_x_y(data): # program to print graph of X_libera vs X_motor with a list data = [[[x_motor_position][y_motor_position][Va][Vb][Vc][Vd][sum][x_libera_position][y_libera_position]][same for BPM1][same for BPM2]],also do a linear regretion and print the equation
     190    global global_index_figure # to creat different figure
     191    fig1 = plt.figure(global_index_figure)
     192    global_index_figure += 1
     193    plt.clf()
     194    color = ["r","g","b"]
     195    legende = ["BPM soleil","BPM impr","BPM ref"]
     196    for bpm_number in range(len(data)):
     197        lr1 = stats.linregress(data[bpm_number][0],data[bpm_number][7]) # return tuple (pente,ordonnee a l'origine, coef de correlation, p-value, erreur standard de l'estimation)
     198    #    residu = product_list(data[bpm_number][7], lr1.slope, b =  lr1.intercept)
     199        residu = []
     200        for i in range(len(data[bpm_number][0])):
     201            residu.append(abs(data[bpm_number][7][i] - data[bpm_number][0][i]*lr1.slope - lr1.intercept))
     202        plt.plot(data[bpm_number][0], residu, color[bpm_number]+".", label = legende[bpm_number])
     203    plt.legend()
     204    plt.title("Residu en fonction de la position")
     205    plt.xlabel("length in million motor step")
     206    plt.ylabel("tension in mV")
     207    plt.gca().yaxis.set_tick_params(labelsize = 8)
     208#    plt.s
     209
     210
     211
     212
     213
     214def min_max(data, cut_index, mini = None ,maxi = None): #program to cut a list data = [[position][Va][Vb][Vc][Vd]] with minimum value of position = mini and maximum value of position = maxi
     215    if mini is None and maxi is None :
     216        return(data)
     217    elif mini is None :
     218        for i in data[cut_index]:
     219            if i < mini :
     220                mini = i
     221    elif maxi is None:
     222        for i in data[cut_index]:
     223            if maxi < i :
     224                maxi = i
    186225    index_list = []
    187     for i in range(len(L[0])):
    188         if  L[0][i] >= mini and L[0][i] <= maxi :
     226    for i in range(len(data[cut_index])):
     227        if  data[cut_index][i] >= mini and data[cut_index][i] <= maxi :
    189228            index_list.append(i)
    190     return([[L[0][i] for i in index_list],[L[1][i] for i in index_list],[L[2][i] for i in index_list],[L[3][i] for i in index_list],[L[4][i] for i in index_list]])
    191 
    192 
    193 def convertion_step_mm(L,begin_mm,end_mm): # length convertion
    194     begin_step = L[0]
    195     end_step = L[len(L)-1]
     229    return([[data[j][i] for i in index_list] for j in range(len(data))])
     230
     231            #return([[data[0][i] for i in index_list],[data[1][i] for i in index_list],[data[2][i] for i in index_list],[data[3][i] for i in index_list],[data[4][i] for i in index_list]])
     232
     233
     234def convertion_step_mm(data,begin_mm,end_mm): # length convertion
     235#    print(data)
     236    if begin_mm is None:
     237        begin_mm = data[0]
     238    if end_mm is None:
     239        end_mm = data[len(data)-1]
     240    begin_step = data[0]
     241    end_step = data[len(data)-1]
    196242    a = float((end_mm - begin_mm))/(end_step - begin_step)
    197243    b = begin_mm - a*begin_step
    198244    print(a,b)
    199     print(L)
    200     L = product_list(L, a, b)
    201     return(L)
     245    data = product_list(data, a, b)
     246    return(data)
    202247   
    203248
     
    207252   
    208253def print_data_position_Va_Vb_Vc_Vd(fichier, min = None, max = None):
    209     L = min_max(read_data_position_Va_Vb_Vc_Vd(fichier), mini = min, maxi = max)
    210     print_graph(L)
     254    L = min_max(read_data_position_Va_Vb_Vc_Vd(fichier), 0, mini = min, maxi = max)
     255    print_graph_position_Va_Vb_Vc_Vd(L)
    211256    #print(L)
    212257
    213 def print_residu_position_Va_Vb_Vc_Vd(fichier, min = None, max = None):
    214     L = min_max(read_data_position_Va_Vb_Vc_Vd(fichier), mini = min, maxi = max)
     258def print_residu_position_Va_Vb_Vc_Vd(fichier, min_position = None, max_position = None):
     259    L = min_max(read_data_position_Va_Vb_Vc_Vd(fichier), 0, mini = min_position, maxi = max_position)
    215260    residu_position_Va_Vb_Vc_Vd(L)
    216 
    217 print_data_position_Va_Vb_Vc_Vd("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_20180611_160153_0.txt",0.1,0.3)
    218 print_residu_position_Va_Vb_Vc_Vd("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_20180611_160153_0.txt",0.1,0.3)
    219 
     261   
     262def print_data_xmotor_ymotor_Va_Vb_Vc_Vd_sum_x_y(fichier, lin_reg = "yes", minx = None, maxx = None, miny = None, maxy = None, begin_mm = None, end_mm = None):
     263    data = read_data_xmotor_ymotor_Va_Vb_Vc_Vd_sum_x_y(fichier)
     264    if (not minx is None) or (not maxx is None):
     265        data =  [min_max(bpm, 0, mini = minx, maxi = maxx) for bpm in data]
     266    if (not miny is None) or (not maxy is None):
     267        data =  [min_max(bpm, 1, mini = miny, maxi = maxy) for bpm in data]
     268    if (not begin_mm is None) or (not end_mm is None):
     269        for bpm_index in range(len(data)):
     270            data[bpm_index][0] = convertion_step_mm(data[bpm_index][0], (begin_mm - end_mm)/2, (-begin_mm +  end_mm)/2)
     271    print_graph_xmotor_ymotor_Va_Vb_Vc_Vd_sum_x_y(data,lin_reg)
     272
     273def print_residu_xmotor_ymotor_Va_Vb_Vc_Vd_sum_x_y(fichier, minx = None, maxx = None, miny = None, maxy = None):
     274    data = read_data_xmotor_ymotor_Va_Vb_Vc_Vd_sum_x_y(fichier)
     275    if (not minx is None) or (not maxx is None):
     276        data =  [min_max(bpm, 0, mini = minx, maxi = maxx) for bpm in data]
     277    if (not miny is None) or (not maxy is None):
     278        data =  [min_max(bpm, 1, mini = miny, maxi = maxy) for bpm in data]
     279    residu_xmotor_ymotor_Va_Vb_Vc_Vd_sum_x_y(data)
     280
     281#print_data_xmotor_ymotor_Va_Vb_Vc_Vd_sum_x_y("data/BPM-number_x-motor_y-motor_Va_Vb_Vc_Vd_Sum_X_Y_BPM0-soleil_BPM1-impr_BPM2-ref_20180718_1.txt",  miny = 0, maxy = 57)
     282#print_residu_xmotor_ymotor_Va_Vb_Vc_Vd_sum_x_y("data/BPM-number_x-motor_y-motor_Va_Vb_Vc_Vd_Sum_X_Y_BPM0-soleil_BPM1-impr_BPM2-ref_20180718_1.txt")
     283
     284print_data_xmotor_ymotor_Va_Vb_Vc_Vd_sum_x_y("data/BPM-number_x-motor_y-motor_Va_Vb_Vc_Vd_Sum_X_Y_BPM0-soleil_BPM1-impr_BPM2-ref_20180718_2_convert-100000_94,36_100000_78,72.txt", begin_mm = 78.72, end_mm = 94.36)
     285#print_residu_xmotor_ymotor_Va_Vb_Vc_Vd_sum_x_y("data/BPM-number_x-motor_y-motor_Va_Vb_Vc_Vd_Sum_X_Y_BPM0-soleil_BPM1-impr_BPM2-ref_20180718_2_convert-100000_94,36_100000_78,72.txt")
     286
     287#print_data_xmotor_ymotor_Va_Vb_Vc_Vd_sum_x_y("data/test.txt", begin_mm = 100)
     288#print_data_xmotor_ymotor_Va_Vb_Vc_Vd_sum_x_y("data/test.txt, begin_mm = 0, end_mm = 1")
     289#print_residu_xmotor_ymotor_Va_Vb_Vc_Vd_sum_x_y("data/test.txt")
     290
     291
     292#print_data_position_Va_Vb_Vc_Vd("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_20180611_160153_0.txt",0.1,0.3)
     293#print_residu_position_Va_Vb_Vc_Vd("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_20180611_160153_0.txt",0.1,0.3)
    220294#print_data_position_Va_Vb_Vc_Vd("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_20180611_163036_0.txt")
    221 
    222295#print_data_position_Va_Vb_Vc_Vd("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_vertical_acquisition_20180612_0.txt")
    223296#print_data_position_Va_Vb_Vc_Vd("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_vertical_acquisition_20180612_0.txt")
Note: See TracChangeset for help on using the changeset viewer.