Exemplo n.º 1
0
    def calc_data(self):
        x = numpy.array([self.data['list_t']])
        y = numpy.array([self.data['list_v_1']])
        xx = numpy.linspace(0, 10 * self.data['list_t[1]'], 100)
        matplotlib.pyplot.scatter(x, y)
        f = scipy.interpolate.interp1d(x, y, kind="cubic")
        ynew = f(xx)
        matplotlib.pyplot.plot(xx, ynew, "g")
        matplotlib.pyplot.show()
        ynew1 = f(self.data['list_q[1]'] + 0.001)
        ynew2 = f(self.data['list_q[1]'] - 0.001)
        v = math.fabs(ynew1 - ynew2) / 0.002
        self.data['v'] = v

        db = Method.average(self.data['list_db'])
        self.data['db'] = db
        dp = Method.average(self.data['list_dp'])
        self.data['dp'] = dp
        hb = Method.average(self.data['list_hb'])
        self.data['hb'] = hb
        hp = Method.average(self.data['list_hp'])
        self.data['hp'] = hp
        k = self.data['pl_m'] * 3 * 10**8 * self.data['v'] * (
            4 * self.data['hp'] + self.data['dp']
        ) / (self.data['dp'] + 2 * self.data['hp']) * self.data['hb'] / (
            self.data['list_q[0]'] -
            self.data['list_q[1]']) * 2 / (math.pi * self.data['db']**2)
        self.data['k'] = k
Exemplo n.º 2
0
 def calc_data(self):
     # list_dif_d 长度为x折半的数组,为逐差相减的结果
     # num_d 逐差法求得的平均值
     list_dtx = []
     for i in range(0, 10):
         list_dtx.append(
             (self.data['list_d2'][i] - self.data['list_d1'][i]) / 30)
     num_d = Method.average(list_dtx)
     num_dt_l = 30 * num_d
     num_lbd = 2 * num_d
     self.data['list_dtx'] = list_dtx
     self.data['num_d'] = num_d
     # num_lbd = round(num_lbd,5)
     num_ave_f = (float(
         (self.data['list_f'][0] + self.data['list_f'][1]) / 2.0))
     num_delta_f = abs(self.data['list_f'][0] -
                       self.data['list_f'][1]) / 2.0
     num_f = num_ave_f
     num_c = num_lbd * num_f
     self.data['num_lbd'] = num_lbd
     self.data['num_ave_f'] = num_ave_f
     self.data['num_delta_f'] = num_delta_f
     self.data['num_u_f'] = num_delta_f / sqrt(3)
     self.data['num_c'] = num_c
     self.data['num_f'] = num_f
Exemplo n.º 3
0
    def calc_uncertainty(self):
        # 计算线性拟合的A类不确定度
        Sigma = 0
        for i in range(0, len(self.data['X'])):
            Sigma += (self.data['Y'][i] - (self.data['b'] + self.data['a'] * self.data['X'][i]))**2
        k = len(self.data['X'])
        ua_B = (Sigma / (k - 2))**(1 / 2)
        ua_a = self.data['b'] * (((1 / self.data['r']**2 - 1) / (k - 2))**(1 / 2))
        X_square = []
        for i in range(0, k):
            X_square[i] = self.data['X'][i]**2
        ua_b = ua_a * (Method.average(X_square)**(1 / 2))
        self.data.update({"ua_B":ua_B, "ua_a":ua_a, "ua_b":ua_b})

        # 求theta的B类不确定度,分别合成不同V的不确定度,计算加权平均后V_avg的不确定度
        ub_theta = 1 / math.sqrt(3) * math.pi / 180
        u_V = []
        for i in range(0, 4):
            u_V.append(self.data['V'][i] * math.sqrt(1 / self.data['Theta'][i]**2 * ub_theta**2 + 1 / self.data['Magnetic_induction2'][i]**2 * ua_B**2))
        u_V1 = u_V[0]
        u_V2 = u_V[1]
        u_V3 = u_V[2]
        u_V4 = u_V[3]
        u2_Vavg = 1 / (u_V1**(-2) + u_V2**(-2) + u_V3**(-2) + u_V4**(-2))
        u_Vavg = math.sqrt(u2_Vavg)
        V_avg = u2_Vavg * (self.data['V'][0] / u_V1**2 + self.data['V'][1] / u_V2**2 + self.data['V'][2] / u_V3**2 + self.data['V'][3] / u_V4**2)
        self.data.update({"ub_theta":ub_theta, "u_V1":u_V1, "u_V2":u_V2, "u_V3":u_V3, "u_V4":u_V4, "u_Vavg":u_Vavg, "V_avg":V_avg})
Exemplo n.º 4
0
 def calc_data_2(self):
     i = 0
     self.data['x_1'] = list_x_1 = []
     self.data['x_2'] = list_x_2 = []
     self.data["list_f"] = list_f = []
     while i<5 :
         list_f[i] = (list_x_1[i] + list_x_2[i])/2 - pl_x
         i = i + 1
     self.data["num_f"] = num_f = Method.average(self.data['list_f'])
Exemplo n.º 5
0
 def calc_data_3(self):
     i = 0
     self.data['list_3_f'] = list_3_f = []
     self.data['list_a'] = list_a = []
     self.data['list_b'] = list_b = []
     self.data['overline_3_f'] = overline_3_f
     while i<5 :
         list_3_f[i] = ( list_a[i]^2 - list_b[i]^2 ) / 4*list_b[i]
         i = i + 1
     overline_3_f = Method.average(self.data['list_3_f'])
Exemplo n.º 6
0
 def calc_data(self):
     # 求直径D的平均值
     num_D = Method.average(self.data['list_D'])
     self.data['num_D'] = num_D
     # 一元线性回归求电阻率
     num_b, num_a, num_r = Fitting.linear(self.data['list_l'], self.data['list_R_x'])
     self.data['num_b'] = num_b
     self.data['num_r'] = num_r
     num_rho = math.pi * num_D * num_D * num_b / 4
     self.data['num_rho']=num_rho
Exemplo n.º 7
0
 def calc_data(self):
     # 计算间距
     yd = [], gd = [], pd = [], ld = []
     for i in range(0, 6):
         yd[i] = self.data['yl'][i] - self.data['yr'][i]
         gd[i] = self.data['gl'][i] - self.data['gr'][i]
         pd[i] = self.data['pl'][i] - self.data['pr'][i]
         ld[i] = self.data['ll'][i] - self.data['lr'][i]
     self.data['yd'] = yd, self.data['gd'] = gd, self.data[
         'pd'] = pd, self.data['ld'] = ld
     yd_avg = Method.average(yd)
     gd_avg = Method.average(gd)
     pd_avg = Method.average(pd)
     ld_avg = Method.average(ld)
     self.data['yd_avg'] = yd_avg, self.data['gd_avg'] = gd_avg, self.data[
         'pd_avg'] = pd_avg, self.data['ld_avg'] = ld_avg
     # 计算波长
     lambda_y = yd_avg / ld_avg * self.data['lambda_0']
     lambda_g = gd_avg / ld_avg * self.data['lambda_0']
     lambda_p = pd_avg / ld_avg * self.data['lambda_0']
     self.data['lambda_y'] = lambda_y, self.data[
         'lambda_g'] = lambda_g, self.data['lambda_p'] = lambda_p
Exemplo n.º 8
0
    def calc_data(self):
        x = arr_k = asarray(self.data['arr_k'])
        y = arr_D_sq = asarray(self.data['arr_D_sq'])
        b, a, r = Fitting.linear(x, y)
        self.data['b'] = b
        self.data['a'] = a
        self.data['r'] = r
        x_mean = Method.average(x)
        y_mean = Method.average(y)
        x_sq_mean = Method.average(x ** 2)
        y_sq_mean = Method.average(y ** 2)
        xy_mean = Method.average(x * y)

        self.data['x_mean'] = x_mean
        self.data['y_mean'] = y_mean
        self.data['x_sq_mean'] = x_sq_mean
        self.data['y_sq_mean'] = y_sq_mean
        self.data['xy_mean'] = xy_mean

        lbd = self.data['lambda'] * 1e-6
        R = b / (4 * lbd)
        self.data['R'] = R
        pass
Exemplo n.º 9
0
 def calc_data1(self):
     list_A = []
     for rows in self.data['list_data'][0]:
         row = []
         for item in rows:
             value_degree = Method.degree_trans(item)
             if (value_degree > 1000) | (value_degree < -1000):
                 print('数据出现错误,请检查实验表格第' +
                       str(self.data['list_data'].index(rows) + 4) + '行第' +
                       str(rows.index(item) + 2) + '列的度和分是否以空格分隔')
             else:
                 row.append(value_degree)
         value_A = (row[3] + row[2] - row[1] - row[0]) / 4
         if value_A < 0:
             value_A = value_A + 90
         list_A.append(value_A)
     aver_A = Method.average(list_A)
     self.data['list_A'] = list_A
     self.data['aver_A'] = aver_A
Exemplo n.º 10
0
 def calc_data_d(self):
     list_d_2xita1 = []
     list_d_2xita1_print = []
     for i in range(5):
         list_d_2xita1.append(
             self.simple_2xita(self.data['list_d_a1'],
                               self.data['list_d_b1'],
                               self.data['list_d_a2'],
                               self.data['list_d_b2'], i))
         list_d_2xita1_print.append(180 * list_d_2xita1[i] / 3.14)
     self.data['list_d_2xita1'] = list_d_2xita1
     self.data['list_d_2xita1_print'] = list_d_2xita1_print
     d_2xita2 = ((self.data['a1_2'] - self.data['a2_2']) +
                 self.data['b1_2'] - self.data['b2_2']) / 2
     self.data['d_2xita2'] = d_2xita2
     d_2xita1_average = Method.average(list_d_2xita1)
     d_xita1_average = d_2xita1_average / 2
     self.data['d_2xita1_average'] = d_2xita1_average
     self.data['d_xita1_average'] = d_xita1_average
     d1 = 589.3 / sin(d_xita1_average)
     self.data['d1'] = d1 / 1000
     d2 = 2 * 589.3 / sin(3.14 * d_2xita2 / 360)
     self.data['d2'] = d2 / 1000
Exemplo n.º 11
0
 def calc_data2(self):
     list_delta_m = []
     for rows in self.data['list_data'][1]:
         row = []
         for item in rows:
             value_degree = Method.degree_trans(item)
             if (value_degree > 1000) | (value_degree < -1000):
                 print('数据出现错误,请检查实验表格第' +
                       str(self.data['list_data'].index(rows) + 4) + '行第' +
                       str(rows.index(item) + 8) + '列的度和分是否以空格分隔')
             else:
                 row.append(value_degree)
         value_delta_m = (row[3] + row[2] - row[1] - row[0]) / 2
         if value_delta_m < 0:
             value_delta_m = value_delta_m + 180
         list_delta_m.append(value_delta_m)
     delta_m = Method.average(list_delta_m)
     n1 = float(
         sin((delta_m + self.data['aver_A']) / 360 * pi) /
         sin(self.data['aver_A'] / 360 * pi))
     self.data['list_delta_m'] = list_delta_m
     self.data['aver_delta_m'] = delta_m
     self.data['n1'] = n1
Exemplo n.º 12
0
 def calc_data3(self):
     list_delta = []
     for rows in self.data['list_data'][2]:
         row = []
         for item in rows:
             value_degree = Method.degree_trans(item)
             if (value_degree > 1000) | (value_degree < -1000):
                 print('数据出现错误,请检查实验表格第' +
                       str(self.data['list_data'].index(rows) + 4) + '行第' +
                       str(rows.index(item) + 14) + '列的度和分是否以空格分隔')
             else:
                 row.append(value_degree)
         value_delta = (row[0] + row[1] - row[2] - row[3]) / 2
         if value_delta < 0:
             value_delta = value_delta + 180
         list_delta.append(value_delta)
     delta = Method.average(list_delta)
     n2 = float(
         sqrt((
             (cos(self.data['aver_A'] / 180 * pi) + sin(delta / 180 * pi)) /
             sin(self.data['aver_A'] / 180 * pi))**2 + 1))
     self.data['list_delta'] = list_delta
     self.data['aver_delta'] = delta
     self.data['n2'] = n2
Exemplo n.º 13
0
    def calc_data(self):
        # 实验一
        # TODO ua_rx和ub_rx的计算方式有点问题 (不知道那个k是个什么物理量啊)
        num_b, num_a, num_r = Fitting.linear(self.data['list_x'],
                                             self.data['list_y'], False)
        self.data['num_a'] = num_a
        self.data['num_b'] = num_b
        self.data['num_r'] = num_r
        num_rx = num_b
        list_k = []
        for i in range(0, 8):
            list_k.append(self.data['list_x'][i] / self.data['list_y'][i])
        # num_ua_b = Method.a_uncertainty(list_k)
        num_k = 8
        num_ave_x = Method.average(self.data['list_x'])
        num_ave_y = Method.average(self.data['list_y'])
        num_ua_b = num_b * (1 / (num_k - 2) * ((1 / num_r)**2 - 1))**(1 / 2)
        num_u_u = 0.00433
        num_u_i = 0.0000433
        num_ub_rx_rx = sqrt((num_u_u / num_ave_y)**2 +
                            (num_u_i / num_ave_x)**2)
        num_ub_rx = num_ub_rx_rx * num_rx
        num_u_rx = (num_ub_rx**2 + num_ua_b**2)**(1 / 2)
        num_u_rx_1bit, pwr = Method.scientific_notation(num_u_rx)
        num_fin_rx = int(num_rx * (10**pwr)) / (10**pwr)
        self.data['num_ave_y'] = num_ave_y
        self.data['num_ave_x'] = num_ave_x
        self.data['num_ub_rx'] = num_ub_rx
        self.data['num_ub_rx_rx'] = num_ub_rx_rx
        self.data['num_u_u'] = num_u_u
        self.data['num_u_i'] = num_u_i
        self.data['num_rx'] = num_rx
        self.data['num_ua_b'] = num_ua_b
        self.data['num_u_rx'] = num_u_rx
        self.data['str_fin_rx'] = "%.0f±%.0f" % (num_fin_rx, num_u_rx_1bit)

        # 实验二
        num_2r1 = self.data['list_2'][0]
        num_2u = self.data['list_2'][1]
        num_2r0 = self.data['list_2'][2]
        num_2d = self.data['list_2'][3]
        num_2r2 = self.data['list_2'][4]
        num_2rg = num_2r2
        num_2ki = (num_2r1 * num_2u) / ((num_2r0 + num_2r1) * num_2rg * num_2d)
        num_dt_2r0 = InstrumentError.resistance_box(self.data['list_a0'],
                                                    self.data['list_r0'],
                                                    self.data['list_rbox0'][0])
        num_dt_2r1 = InstrumentError.resistance_box(self.data['list_a1'],
                                                    self.data['list_r1'],
                                                    self.data['list_rbox0'][1])
        num_dt_2r2 = InstrumentError.resistance_box(self.data['list_a2'],
                                                    self.data['list_r2'],
                                                    self.data['list_rbox0'][2])
        num_u_2r0 = num_dt_2r0 / sqrt(3)
        num_u_2r1 = num_dt_2r1 / sqrt(3)
        num_u_2r2 = num_dt_2r2 / sqrt(3)
        num_u_2u = 0.005 * 3 / sqrt(3)
        num_u_2d = 1 / sqrt(3)
        num_u_2r1_2r0 = sqrt((num_u_2r1)**2 + (num_u_2r0)**2)
        num_u_2ki_2ki = sqrt((num_u_2r1 / num_2r1)**2 +
                             (num_u_2r1_2r0 / (num_2r0 + num_2r1))**2 +
                             (num_u_2u / num_2u)**2 +
                             (num_u_2r2 / num_2r2)**2 + (num_u_2d / num_2d)**2)
        num_u_2ki = num_u_2ki_2ki * num_2ki
        num_u_2rg_1bit, pwr = Method.scientific_notation(num_u_2r2)
        num_fin_rg = int(num_rx * (10**pwr)) / (10**pwr)
        num_u_2ki_1bit, pwr = Method.scientific_notation(num_u_2ki)
        num_fin_ki = int(num_rx * (10**pwr)) / (10**pwr)
        self.data['str_fin_ki'] = "%.3f±%.3f" % (num_fin_ki, num_u_2ki_1bit)
        self.data['str_fin_rg'] = "%.0f±%.0f" % (num_fin_rg, num_u_2rg_1bit)
        self.data['num_dt_2r0'] = num_dt_2r0
        self.data['num_dt_2r1'] = num_dt_2r1
        self.data['num_dt_2r2'] = num_dt_2r2
        self.data['num_2r1'] = num_2r1
        self.data['num_2r2'] = num_2r2
        self.data['num_2r0'] = num_2r0
        self.data['num_2d'] = num_2d
        self.data['num_2u'] = num_2u
        self.data['num_u_2u'] = num_u_2u
        self.data['num_u_2d'] = num_u_2d
        self.data['num_u_2r1_2r0'] = num_u_2r1_2r0
        self.data['num_u_2ki_2ki'] = num_u_2ki_2ki
        self.data['num_u_2ki'] = num_u_2ki
        self.data['num_2ki'] = num_2ki

        # 实验三
        num_3rs = self.data['list_3'][0]
        num_3v = self.data['list_3'][1]
        num_3d = self.data['list_3'][2]
        num_3rg = self.data['list_3'][3]
        num_3ki = self.data['list_3'][4]
        num_u3_Nm1 = self.data['list_3'][7]
        num_u3_Nm2 = self.data['list_3'][8]
        num_u3_d = self.data['list_3'][9]
        num_u3_a1 = self.data['list_3'][5]
        num_u3_a2 = self.data['list_3'][6]
        num_u3_rg = self.data['list_3'][10]
        num_u3_ki = self.data['list_3'][11]

        num_3rxh = num_3rs / ((num_3rg + num_3rs) * num_3ki) * num_3v / num_3d
        num_u3_rs = InstrumentError.electromagnetic_instrument(
            num_u3_a1, num_u3_Nm1) / sqrt(3)
        num_u3_v = InstrumentError.electromagnetic_instrument(
            num_u3_a2, num_u3_Nm2) / sqrt(3)
        num_u3_r = (num_u3_rg**2 + num_u3_rs**2)**(1 / 2)
        num_u3_rxh_rxh = ((num_u3_rs / num_3rs)**2 + (num_u3_r / num_3rs)**2 +
                          (num_u3_v / num_3v)**2 + (num_u3_ki / num_3ki)**2 +
                          (num_u3_d / num_3d)**2)**(1 / 2)
        num_u3_rxh = num_u3_rxh_rxh * num_3rxh
        num_u3_rxh_1bit, pwr = Method.scientific_notation(num_u3_rxh)
        num_fin_rxh = int(num_3rxh * (10**pwr)) / (10**pwr)

        self.data['str_fin_rxh'] = "%.3f±%.3f" % (num_fin_rxh, num_u3_rxh_1bit)
        self.data['num_3rxh'] = num_3rxh
        self.data['num_u3_rs'] = num_u3_rs
        self.data['num_u3_v'] = num_u3_v
        self.data['num_u3_r'] = num_u3_r
        self.data['num_u3_rxh_rxh'] = num_u3_rxh_rxh
        self.data['num_u3_rxh'] = num_u3_rxh
        self.data['num_3rs'] = num_3rs
        self.data['num_3v'] = num_3v
        self.data['num_3d'] = num_3d
        self.data['num_3rg'] = num_3rg
        self.data['num_3ki'] = num_3ki
        self.data['num_u3_Nm1'] = num_u3_Nm1
        self.data['num_u3_Nm2'] = num_u3_Nm2
        self.data['num_2ki'] = num_2ki
        self.data['num_u3_d'] = num_u3_d
        self.data['num_u3_a1'] = num_u3_a1
        self.data['num_u3_a2'] = num_u3_a2
        self.data['num_u3_rg'] = num_u3_rg
        self.data['num_u3_ki'] = num_u3_ki
Exemplo n.º 14
0
    def calc_data_Rh(self):
        #三种光要算Rh啦(r为红,b为蓝,p为紫)
        list_r_2xita1 = []
        list_r_2xita1_print = []
        for i in range(5):
            list_r_2xita1.append(
                self.simple_2xita(self.data['list_r_a1'],
                                  self.data['list_r_b1'],
                                  self.data['list_r_a2'],
                                  self.data['list_r_b2'], i))
            list_r_2xita1_print.append(180 * list_r_2xita1[i] / 3.14)
        self.data['list_r_2xita1'] = list_r_2xita1
        self.data['list_r_2xita1_print'] = list_r_2xita1_print
        r_2xita1_average = Method.average(list_r_2xita1)
        r_xita1_average = r_2xita1_average / 2
        self.data['r_2xita1_average'] = r_2xita1_average
        self.data['r_xita1_average'] = r_xita1_average
        lambdaR = self.uncertainty['d_av'] * sin(r_xita1_average)
        r_RH = 36 / (5 * lambdaR)
        self.data['r_2xita1_average'] = r_2xita1_average
        self.data['r_xita1_average'] = r_xita1_average
        self.data['r_RH'] = r_RH
        self.data['lambdaR'] = lambdaR

        list_b_2xita1 = []
        list_b_2xita1_print = []
        for i in range(5):
            list_b_2xita1.append(
                self.simple_2xita(self.data['list_b_a1'],
                                  self.data['list_b_b1'],
                                  self.data['list_b_a2'],
                                  self.data['list_b_b2'], i))
            list_b_2xita1_print.append(180 * list_b_2xita1[i] / 3.14)
        self.data['list_b_2xita1'] = list_b_2xita1
        self.data['list_b_2xita1_print'] = list_b_2xita1_print
        b_2xita1_average = Method.average(list_b_2xita1)
        b_xita1_average = b_2xita1_average / 2
        self.data['b_2xita1_average'] = b_2xita1_average
        self.data['b_xita1_average'] = b_xita1_average
        lambdaB = self.uncertainty['d_av'] * sin(b_xita1_average)
        b_RH = 16 / (3 * lambdaB)
        self.data['b_2xita1_average'] = b_2xita1_average
        self.data['b_xita1_average'] = b_xita1_average
        self.data['b_RH'] = b_RH
        self.data['lambdaB'] = lambdaB
        #purple
        list_p_2xita1 = []
        list_p_2xita1_print = []
        for i in range(5):
            list_p_2xita1.append(
                self.simple_2xita(self.data['list_p_a1'],
                                  self.data['list_p_b1'],
                                  self.data['list_p_a2'],
                                  self.data['list_p_b2'], i))
            list_p_2xita1_print.append(180 * list_p_2xita1[i] / 3.14)
        self.data['list_p_2xita1'] = list_p_2xita1
        self.data['list_p_2xita1_print'] = list_p_2xita1_print
        p_2xita1_average = Method.average(list_p_2xita1)
        p_xita1_average = p_2xita1_average / 2
        self.data['p_2xita1_average'] = p_2xita1_average
        self.data['p_xita1_average'] = p_xita1_average
        lambdaP = self.uncertainty['d_av'] * sin(p_xita1_average)
        p_RH = 100 / (21 * lambdaP)
        self.data['p_2xita1_average'] = p_2xita1_average
        self.data['p_xita1_average'] = p_xita1_average
        self.data['p_RH'] = p_RH
        self.data['lambdaP'] = lambdaP