def calc_uncertainty(self): # 计算不确定度 ub_d = 0.001 / sqrt(3) ua_d0 = Method.a_uncertainty(self.data['ld']) # 这里容易写错,一定要用原始数据的数组 u_d0 = sqrt(ua_d0**2 + ub_d**2) ua_dy = Method.a_uncertainty(self.data['yd']) u_dy = sqrt(ua_dy**2 + ub_d**2) u_lambda_y = self.data['lambda_y'] * sqrt( (u_dy / self.data['yd_avg'])**2 + (u_d0 / self.data['ld_avg'])**2) self.data.update({ "ub_d": ub_d, "ua_d0": ua_d0, "u_d0": u_d0, "ua_dy": ua_dy, "u_dy": u_dy, "u_lambda_y": u_lambda_y }) ua_dg = Method.a_uncertainty(self.data['gd']) u_dg = sqrt(ua_dg**2 + ub_d**2) u_lambda_g = self.data['lambda_g'] * sqrt( (u_dg / self.data['gd_avg'])**2 + (u_d0 / self.data['ld_avg'])**2) ua_dp = Method.a_uncertainty(self.data['pd']) u_dp = sqrt(ua_dp**2 + ub_d**2) u_lambda_p = self.data['lambda_p'] * sqrt( (u_dp / self.data['pd_avg'])**2 + (u_d0 / self.data['ld_avg'])**2) self.data.update({ "ua_dg": ua_dg, "u_dg": u_dg, "u_lambda_g": u_lambda_g, "ua_dp": ua_dp, "u_dp": u_dp, "u_lambda_p": u_lambda_p })
def calc_uncertainty_detail(data_list, result_list): sunc = Simplified() uncertain_data = {} ua_10delta_x = Method.a_uncertainty(result_list['diff_10delta_x']) ub_10delta_x = sunc.micrometer / sqrt(3) u_10delta_x = sqrt(ua_10delta_x**2 + ub_10delta_x**2) u_delta_x = u_10delta_x / 10 ub_S = sqrt((sunc.steel_ruler / 10 / sqrt(3))**2 + (data_list['delta_s'] / sqrt(3))**2) ub_b = sqrt((sunc.micrometer / sqrt(3))**2 + (data_list['delta_b_b'] * result_list['b'] / sqrt(3))**2) ub_b1 = sqrt((sunc.micrometer / sqrt(3))**2 + (data_list['delta_b_b'] * result_list['b1'] / sqrt(3))**2) u_lbd_lbd = sqrt((u_delta_x / result_list['delta_x'])**2 + (ub_b / result_list['b'] / 2)**2 + (ub_b1 / result_list['b1'] / 2)**2 + 2 * ((ub_S / (result_list['S'] + result_list['S1']))**2)) u_lbd = u_lbd_lbd * result_list['result_lambda'] final_lbd = Method.final_expression(result_list['result_lambda'], u_lbd) uncertain_data['ua_10delta_x'] = ua_10delta_x uncertain_data['ub_10delta_x'] = ub_10delta_x uncertain_data['u_10delta_x'] = u_10delta_x uncertain_data['u_delta_x'] = u_delta_x uncertain_data['u_S'] = ub_S uncertain_data['u_b'] = ub_b uncertain_data['u_b1'] = ub_b1 uncertain_data['u_lbd_lbd'] = u_lbd_lbd uncertain_data['u_lbd'] = u_lbd uncertain_data['final'] = final_lbd return uncertain_data
def calc_uncertainty_d(self): # 计算光程差d的a,b及总不确定度 Ua_2xita1 = Method.a_uncertainty( self.data['list_d_2xita1']) # 这里容易写错,一定要用原始数据的数组 Ub_2xita1 = 1.679e-4 U_xita1 = sqrt(Ub_2xita1**2 + Ua_2xita1**2) / 2 Ud1 = abs(self.data['d1'] * U_xita1 / tan(self.data['d_xita1_average'])) Ub_2xita2 = 1.679e-4 Ud2 = abs(self.data['d2'] * Ub_2xita2 / (2 * tan(3.14 * self.data['d_2xita2'] / 360))) self.uncertainty.update({ "Ua_2xita1": Ua_2xita1, "Ub_2xita1": Ub_2xita1, "Ua_xita1": Ua_2xita1 / 2, "Ub_xita1": Ub_2xita1 / 2, "U_xita1": U_xita1, "Ud1": Ud1, "Ub_2xita2": Ub_2xita2, "Ub_xita2": Ub_2xita2 / 2, "Ud2": Ud2 }) d1 = self.data['d1'] d2 = self.data['d2'] d_av = (d1 / (Ud1**2) + d2 / (Ud2**2)) / (1 / (Ud1**2) + 1 / (Ud2**2)) Ud_av = sqrt((Ud1**2) * (Ud2**2) / (Ud1**2) + (Ud2**2)) self.uncertainty.update({"d_av": d_av, "Ud_av": Ud_av}) self.data['final1'] = Method.final_expression(d_av, Ud_av)
def calc_uncertainty(self): # 计算一元线性回归的不确定度 num_u_b = self.data['num_b'] * sqrt((1 / (self.data['num_r'] ** 2) - 1) / (8 - 2)) self.data['num_u_b'] = num_u_b # 计算直径D的不确定度 num_ua_D = Method.a_uncertainty(self.data['list_D']) num_ub_D = 0.03 / sqrt(3) /1000 num_u_D = sqrt(num_ua_D ** 2 + num_ub_D ** 2) self.data.update({"num_ua_D":num_ua_D, "num_ub_D":num_ub_D, "num_u_D":num_u_D}) # 电阻率不确定度的合成 num_u_rho_rho = sqrt((num_u_D / self.data['num_D']) ** 2 + (num_u_b / self.data['num_b']) ** 2) num_rho = self.data['num_rho'] num_u_rho = num_u_rho_rho * num_rho self.data.update({"num_u_rho_rho": num_u_rho_rho, "num_u_rho": num_u_rho}) # 输出带不确定度的最终结果: 不确定度保留一位有效数字, 物理量结果与不确定度首位有效数字对齐 self.data['final_1'] = Method.final_expression(self.data['num_rho'], self.data['num_u_rho']) # 单电桥测电阻 # 灵敏度分析 num_S = self.data['num_delta_n'] / self.data['num_delta_R_3'] num_delta_lmd = 0.2 / num_S num_u_lmd = num_delta_lmd / sqrt(3) self.data.update({"num_S": num_S, "num_delta_lmd":num_delta_lmd, "num_u_lmd":num_u_lmd}) # 仪器误差 num_delta_yi = InstrumentError.dc_bridge(self.data['num_a_pct'], self.data['num_R_3'],self.data['num_R_0']) num_u_yi = num_delta_yi / sqrt(3) num_u_R_x = sqrt(num_u_yi ** 2 + num_u_lmd ** 2) self.data.update({"num_delta_yi": num_delta_yi, "num_u_yi": num_u_yi, "num_u_R_x": num_u_R_x}) # 输出带不确定度的最终结果: 不确定度保留一位有效数字, 物理量结果与不确定度首位有效数字对齐 self.data['final_2'] = Method.final_expression(self.data['num_R_3'], self.data['num_u_R_x']) print(self.data['final_2'])
def calc_uncertainty3(self): # 计算顶角A的a,b及总不确定度 ua_delta = Method.a_uncertainty( self.data['list_delta']) # 这里容易写错,一定要用原始数据的数组 ub_delta = (1 / 60) / sqrt(3) u_delta = sqrt(ua_delta**2 + ub_delta**2) self.data.update({ "ua_delta": ua_delta, "ub_delta": ub_delta, "u_delta": u_delta }) part_1 = -1 / sin(self.data['aver_A'] / 180 * pi) - sin( self.data['aver_delta'] / 180 * pi) * cos( self.data['aver_A'] / 180 * pi) / (sin( self.data['aver_A'] / 180 * pi)**2) part_4 = (cos(self.data['aver_A'] / 180 * pi) + sin(self.data['aver_delta'] / 180 * pi)) / sin( self.data['aver_A'] / 180 * pi) n_delta = cos( self.data['aver_delta'] / 180 * pi) * part_4 / self.data['n2'] n_A = part_1 * part_4 / self.data['n2'] u_n2 = sqrt((n_delta * u_delta / 180 * pi)**2 + (n_A * self.data['u_A'] / 180 * pi)**2) self.data['u_n2'] = u_n2 self.data['final_n2'] = Method.final_expression(self.data['n2'], u_n2)
def calc_uncertainty1(self): # 计算顶角A的a,b及总不确定度 ua_A = Method.a_uncertainty(self.data['list_A']) # 这里容易写错,一定要用原始数据的数组 ub_A = (1 / 60) / sqrt(3) / 2 u_A = sqrt(ua_A**2 + ub_A**2) self.data.update({"ua_A": ua_A, "ub_A": ub_A, "u_A": u_A}) self.data['final_A'] = Method.final_expression(self.data['aver_A'], u_A)
def calc_uncertainty(self): Ua = Method.a_uncertainty(self.data['list_dif_d']) # a类不确定度 Ub = 0.1 / (numpy.sqrt(3)) # b类不确定度 U = numpy.sqrt(numpy.square(Ua) + numpy.square(Ub)) # 总的不确定度 self.data.update({"Ua": Ua, "Ub": Ub, "U": U}) ave_d = self.data['ave_d'] #res_final, unc_final, pwr = Method.final_expression(ave_d,U) #self.data['final'] = "(%s±%s)*10e(%s)"%(res_final,unc_final,pwr) #base_U, pwr = Method.scientific_notation(U) #将不确定度转化为只有一位有效数字的科学计数法 #volt_final = int(ave_d *(10**pwr))/(10 ** pwr) #对物理量保留有效数字,截断处理 self.data['final'] = "%.1f±%.1f" % (ave_d, U) self.data['relative_error'] = abs( (float(int(ave_d * 10) / 10 - 11.55)) / 11.55)
def calc_uncertainty(self): # 计算光程差d的a,b及总不确定度 ua_d = Method.a_uncertainty(self.data['list_d']) # 这里容易写错,一定要用原始数据的数组 ub_d = 0.00005 / sqrt(3) u_d = sqrt(ua_d**2 + ub_d**2) self.uncertainty.update({"ua_d": ua_d, "ub_d": ub_d, "u_d": u_d}) # 计算圈数N的不确定度 N = self.data['N'] u_N = 1 / sqrt(3) self.uncertainty['u_N'] = u_N d, N = self.data['d'], self.data['N'] # 波长的不确定度合成 u_lbd_lbd = sqrt((u_d / d)**2 + (u_N / N)**2) lbd = self.data['lbd'] u_lbd = u_lbd_lbd * lbd self.uncertainty.update({"u_lbd_lbd": u_lbd_lbd, "u_lbd": u_lbd}) # 输出带不确定度的最终结果: 不确定度保留一位有效数字, 物理量结果与不确定度首位有效数字对齐 self.data['final'] = Method.final_expression(lbd, u_lbd)
def calc_uncertainty2(self): # 计算顶角A的a,b及总不确定度 ua_delta_m = Method.a_uncertainty( self.data['list_delta_m']) # 这里容易写错,一定要用原始数据的数组 ub_delta_m = (1 / 60) / sqrt(3) u_delta_m = sqrt(ua_delta_m**2 + ub_delta_m**2) self.data.update({ "ua_delta_m": ua_delta_m, "ub_delta_m": ub_delta_m, "u_delta_m": u_delta_m }) part_1 = cos((self.data['aver_delta_m'] / 180 * pi + self.data['aver_A'] / 180 * pi) / 2) part_4 = sin(self.data['aver_A'] / 180 * pi / 2) n_delta_m = 0.5 * part_1 / part_4 n_A = -sin(self.data['aver_delta_m'] / 180 * pi / 2) / 2 / (part_4**2) u_n1 = sqrt((n_delta_m * u_delta_m / 180 * pi)**2 + (n_A * self.data['u_A'] / 180 * pi)**2) self.data['u_n1'] = u_n1 self.data['final_n1'] = Method.final_expression(self.data['n1'], u_n1)
def calc_uncertainty(self): # 计算光程差d的a,b及总不确定度 ua_d = Method.a_uncertainty(self.data['d_arr']) # 这里容易写错,一定要用原始数据的数组 ub_d = 0.00005 / sqrt(3) u_d = sqrt(ua_d**2 + ub_d**2) self.data.update({"ua_d": ua_d, "ub_d": ub_d, "u_d": u_d}) # 计算圈数N的不确定度 N = self.data['N'] u_N = 1 / sqrt(3) self.data['u_N'] = u_N d, N = self.data['d'], self.data['N'] # 波长的不确定度合成 u_lbd_lbd = sqrt((u_d / d)**2 + (u_N / N)**2) lbd = self.data['lbd'] u_lbd = u_lbd_lbd * lbd self.data.update({"u_lbd_lbd": u_lbd_lbd, "u_lbd": u_lbd}) # 输出带不确定度的最终结果 # TODO: 输出最终结果的修约方法稍稍有点问题,待修改 bse, pwr = Method.scientific_notation(u_lbd) lbd_f = int(lbd * (10**pwr)) / (10**pwr) # 保留有效数字,截断处理 self.data['final'] = "%.0f±%.0f" % (lbd_f, bse)
def calc_uncertainty(self): list_a = [] list_x = self.data['list_x'] list_y = self.data['list_y'] list_graph2 = self.data['list_graph2'] voltage_begin = self.data['voltage_begin'] voltage_end = self.data['voltage_end'] resitence = self.data['resitence'] c1 = self.data['c1'] c0 = self.data['c0'] list_weight = self.data['list_weight'] m_water = list_weight[1] - list_weight[0] for i in range(len(list_x)): list_a.append(list_y[i] - list_graph2[1] * list_x[i]) self.data['list_a'] = list_a Ua = Method.a_uncertainty(self.data['list_a']) self.data['Ua'] = Ua UJ = abs( ((voltage_begin + voltage_end) / 2)**2 / (Ua * resitence * (c0 * m_water * 0.001 + c1 * list_weight[3] * 0.001 + 64.38))) self.data['UJ'] = UJ
def calc_uncertainty(self): list_tmp = [] for i in self.data['list_dtx']: list_tmp.append(i * 0.001 / 15) # num_ua_d = sqrt( (Method.variance(self.data['list_d'])) / (10 * 9) ) num_ua_d = Method.a_uncertainty(list_tmp) # print(num_ua_d) num_ub1_d = 0.005 / sqrt(3) num_ub2_d = 0.1 / sqrt(3) num_u_d = sqrt(num_ua_d**2 + num_ub1_d**2 + num_ub2_d**2) self.data.update({ "num_ua_d": num_ua_d, "num_ub1_d": num_ub1_d, "num_ub2_d": num_ub2_d, "num_u_d": num_u_d }) num_d = self.data['num_d'] num_lbd = self.data['num_lbd'] num_c = self.data['num_c'] num_f = self.data['num_f'] num_u_f = self.data['num_u_f'] num_u_lbd = 2 * num_u_d num_u_c_c = sqrt((num_u_lbd / num_lbd)**2 + (num_u_f / num_f)**2) num_u_c = num_u_c_c * num_c self.data['num_u_c'] = num_u_c self.data['num_u_c_c'] = num_u_c_c self.data.update({"num_u_lbd": num_u_lbd}) num_u_lbd_1bit, pwr = Method.scientific_notation(num_u_lbd) num_u_f_1bit, pwr = Method.scientific_notation( num_u_f) # 将不确定度转化为只有一位有效数字的科学计数法 num_u_c_1bit, pwr = Method.scientific_notation( num_u_c) # 将不确定度转化为只有一位有效数字的科学计数法 num_fin_lbd = int(num_lbd * (10**pwr)) / (10**pwr) # 对物理量保留有效数字,截断处理 num_fin_f = int(num_f * (10**pwr)) / (10**pwr) num_fin_c = int(num_c * (10**pwr)) / (10**pwr) self.data['num_fin_c'] = "%.2f±%.2f" % (num_fin_c, num_u_c_1bit) self.data['num_fin_f'] = "%.0f±%.0f" % (num_fin_f, num_u_f_1bit) self.data['num_fin_lbd'] = "%.0f±%.0f" % (num_fin_lbd, num_u_lbd_1bit)
def calc_uncertainty_3(self): u_3_f = 0 self.data["u_3_f"] = u_3_f u_3_f = Method.a_uncertainty(self.data['list_3_f'])
def calc_uncertainty_2(self): num_u_f = 0 self.data["num_u_f"] = num_u_f num_u_f = Method.a_uncertainty(self.data['list_f'])
def calc_uncertainty_Rh(self): Ua_2xita1_r = Method.a_uncertainty( self.data['list_r_2xita1']) # 这里容易写错,一定要用原始数据的数组 Ub_2xita1_r = 1.679e-4 Ua_xita1_r = Ua_2xita1_r / 2 Ub_xita1_r = Ub_2xita1_r / 2 U_xita1_r = sqrt(Ub_xita1_r**2 + Ua_xita1_r**2) self.uncertainty.update({ "Ua_xita1_r": Ua_xita1_r, "Ub_xita1_r": Ub_xita1_r, "U_xita1_r": U_xita1_r, "Ua_2xita1_r": Ua_2xita1_r, "Ub_2xita1_r": Ub_2xita1_r }) U_r_RH = self.data['r_RH'] * sqrt( (self.uncertainty['Ud_av'] / self.uncertainty['d_av'])**2 + (U_xita1_r / tan(self.data['r_xita1_average'])**2)) self.uncertainty.update({"U_r_RH": U_r_RH}) self.data['final2_r'] = Method.final_expression( self.data['r_RH'] * 1e6, U_r_RH * 1e4) Ua_2xita1_b = Method.a_uncertainty( self.data['list_b_2xita1']) # 这里容易写错,一定要用原始数据的数组 Ub_2xita1_b = 1.679e-4 Ua_xita1_b = Ua_2xita1_b / 2 Ub_xita1_b = Ub_2xita1_b / 2 U_xita1_b = sqrt(Ub_xita1_b**2 + Ua_xita1_b**2) self.uncertainty.update({ "Ua_xita1_b": Ua_xita1_b, "Ub_xita1_b": Ub_xita1_b, "U_xita1_b": U_xita1_b, "Ua_2xita1_b": Ua_2xita1_b, "Ub_2xita1_b": Ub_2xita1_b }) U_b_RH = self.data['b_RH'] * sqrt( (self.uncertainty['Ud_av'] / self.uncertainty['d_av'])**2 + (U_xita1_b / tan(self.data['b_xita1_average'])**2)) self.uncertainty.update({"U_b_RH": U_b_RH}) self.data['final2_b'] = Method.final_expression( self.data['b_RH'] * 1e6, U_b_RH * 1e4) Ua_2xita1_p = Method.a_uncertainty( self.data['list_p_2xita1']) # 这里容易写错,一定要用原始数据的数组 Ub_2xita1_p = 1.679e-4 Ua_xita1_p = Ua_2xita1_p / 2 Ub_xita1_p = Ub_2xita1_p / 2 U_xita1_p = sqrt(Ub_xita1_p**2 + Ua_xita1_p**2) self.uncertainty.update({ "Ua_xita1_p": Ua_xita1_p, "Ub_xita1_p": Ub_xita1_p, "U_xita1_p": U_xita1_p, "Ua_2xita1_p": Ua_2xita1_p, "Ub_2xita1_p": Ub_2xita1_p }) U_p_RH = self.data['p_RH'] * sqrt( (self.uncertainty['Ud_av'] / self.uncertainty['d_av'])**2 + (U_xita1_p / tan(self.data['p_xita1_average'])**2)) self.uncertainty.update({"U_p_RH": U_p_RH}) self.data['final2_p'] = Method.final_expression( self.data['p_RH'] * 1e6, U_p_RH * 1e4) RH = (self.simple_Rh(self.data['r_RH'], U_r_RH) + self.simple_Rh(self.data['b_RH'], U_b_RH) + self.simple_Rh(self.data['p_RH'], U_p_RH)) / ((1 / U_r_RH**2) + (1 / U_b_RH**2) + (1 / U_p_RH**2)) self.data['RH'] = RH U_RH = sqrt(1 / ((1 / U_r_RH**2) + (1 / U_b_RH**2) + (1 / U_p_RH**2))) self.data['U_RH'] = U_RH self.data['final2'] = Method.final_expression(RH * 1e6, U_RH * 1e4)