frequency = 53.0 # Hz, the frequency of calibration capacitance = 197.39e-12 # farad, capacitance from 20 turn primary to screen ypg_admit = 1j * 2 * math.pi * frequency * capacitance k = 4 # number of sections on the primary # z4 has not been measured and is instead estimated as being P1 resistance value divided by 5, but a retain high full leakage impedance z4 = ( 0.374 / 5.0 + 1j * 0.035 ) / k # ohm, primary leakage impedance from Y51, Z51 of 'Calc 50 Hz' in CTCAL2 z3 = 0.2699 + 1j * 0.0021 # ohm, secondary leakage impedance from Z19, AA51 of 'Calc 50 Hz' in CTCAL2 r2 = 0.2 # ohm, secondary burden impedance ratio = [4, 5, 100] # 100 / 25 # ratio of series connection cap_error2a, cap_error2a_sp = build.calrun.newcapsp( ypg_admit, z4, r2, z3, ratio) print('capacitance error2a = ', cap_error2a) cap2a = gtc.ucomplex(0 + 0j, (abs(cap_error2a.real), abs(cap_error2a.imag)), label='cap2a') # use this estimate as an uncertainty # Note that there is a factor of 5 difference in the nominal excitation levels of Tc and Ta # Use simple 2-point extrapolation and interpolation to get the 0.2% to 25% values for P2ap P2ap_fifth = build.calrun.one_fifth( t3, target_excitation) # interpolated P2ap at one fifth excitation P2as_fifth = [] for x in P2ap_fifth: P2as_fifth.append( x - cap2a - magnetic2a ) # corrects each point e_series = e_par - cap_sp - mag_sp # finally assign error to the 5:1 transformer e6 = [] # this will be the final Tc error for i in range(len(e6_53)): e6.append(
#check that adding a standard deviation roughly doubles the residual sum square chi_square = fitfun(a) print 'best fit=', chi_square bb = [a[0] + sa0, a[1]] print 'with r sd added =', fitfun(bb) / chi_square cc = [a[0], a[1] + sa1] print 'wih l sd added =', fitfun(cc) / chi_square print 't-test', a[0] / sa0, a[1] / sa1 dd = [a[0] + sa0, a[1] + sa1] print 'wih r and l sd added =', fitfun(dd) / chi_square #now use GTC with ucomplex zs = GTC.ucomplex(a[0] + 1j * a[1], (hessian[0, 0] * sum_square, hessian[0, 1] * sum_square, hessian[1, 0] * sum_square, hessian[1, 1] * sum_square), 138) ## zs = GTC.ucomplex(a[0]+1j*a[1],(math.sqrt(hessian[0,0]*sum_square),math.sqrt(hessian[1,1]*sum_square)),138) excite = 60 core = this_CT.coreZ(excite, 50) print print 'calculate error with zH' complex_error = this_CT.error_z(core, zs, zH) * 100 print repr(complex_error) print complex_error.u print print 'calculate error with zB' complex_error2 = this_CT.error_z(core, zs, zB) * 100 print repr(complex_error2) print complex_error2.u
print('magnetic2a ', magnetic2a) frequency = 53.0 # Hz, the frequency of calibration capacitance = 197.39e-12 # farad, capacitance from 20 turn primary to screen ypg_admit = 1j * 2 * math.pi * frequency * capacitance k = 4 # number of sections on the primary # z4 has not been measured and is instead estimated as being P1 resistance value divided by 5, but a retain high full leakage impedance z4 = ( 0.374 / 5.0 + 1j * 0.035 ) / k # ohm, primary leakage impedance from Y51, Z51 of 'Calc 50 Hz' in CTCAL2 z3 = 0.2699 + 1j * 0.0021 # ohm, secondary leakage impedance from Z19, AA51 of 'Calc 50 Hz' in CTCAL2 r2 = 0.2 # ohm, secondary burden impedance ratio = [4, 5, 100] # 100 / 25 # ratio of series connection cap_error2a, cap_error2a_sp = build.calrun.newcapsp(ypg_admit, z4, r2, z3, ratio) print('capacitance error2a = ', cap_error2a, cap_error2a_sp) cap2a = gtc.ucomplex(0 + 0j, (abs(cap_error2a.real), abs(cap_error2a.imag)), label='cap2a') # use this estimate as an uncertainty # Note that there is a factor of 5 difference in the nominal excitation levels of Tc and Ta # Use simple 2-point extrapolation and interpolation to get the 0.2% to 25% values for P2ap P2ap_fifth = build.calrun.one_fifth( t3, target_excitation) # interpolated P2ap at one fifth excitation P2as_fifth = [] for x in P2ap_fifth: P2as_fifth.append( x - cap2a - magnetic2a) # corrects each point e_series = e_par - cap_sp - mag_sp # finally assign error to the 5:1 transformer e6 = [] # this will be the final Tc error for i in range(len(e6_53)): e6.append( P2as_fifth[i] -
sum7 = this_CT.table_analysis(a[0], a[1], zH, x,a7,b7) sum8 = this_CT.table_analysis(a[0], a[1], zB, x,a8,b8) sum9 = this_CT.table_analysis(a[0], a[1], zH, x,a9,b9) sum10 = this_CT.table_analysis(a[0], a[1], zF, x,a10,b10) total = sum1 + sum2 + sum3 + sum4 + sum5 + sum6 + sum7 + sum8 + sum9 + sum10 return total result = minimize(fitfun,[0.05,0.001])#, method = 'Nelder-Mead')#need to start with good guess hessian = result.hess_inv #inverse Hessian is estimate of variance/covariance matrix sum_square = result.fun#final rss #scaling the inverse hessian by multiplying by the residuals sa0 = math.sqrt(hessian[0,0]*sum_square) sa1 = math.sqrt(hessian[1,1]*sum_square) a = result.x ## zs = GTC.ucomplex(a[0]+1j*a[1],(hessian[0,0]*sum_square,hessian[0,1]*sum_square,hessian[1,0]*sum_square,hessian[1,1]*sum_square),138) zs = GTC.ucomplex(a[0]+1j*a[1],(hessian[0,0]*sum_square,hessian[1,1]*sum_square),df=138,label='zs') #use fitted impedance coefficients to define behviour of core impedance #should look at GTC output when model inputs have uncertainty from the fits a1 = GTC.ureal(11.7204144319303,0.346683597109428,df=34,label ='a1',dependent = True) a2 = GTC.ureal(-0.0273771774408702,0.0136282110753501,df=34,label ='a2',dependent = True) a3 = GTC.ureal(29.7364068940134,0.695696459888704,df=34,label ='a3',dependent = True) GTC.set_correlation(-0.826126693986887, a1, a2) GTC.set_correlation(-0.881067593505553, a1, a3) GTC.set_correlation(0.551078899199967, a2, a3) a4 = GTC.ureal(3.90272331971033,0.0859519946028212,34,label ='a4',dependent = True) a5 = GTC.ureal(0.000243735060998679,0.0000527749402101903,34,label ='a5',dependent = True) a6 = GTC.ureal(5.8544055409592,0.501146466659668,34,label ='a6',dependent = True) GTC.set_correlation(-0.679730943215757, a4, a5) GTC.set_correlation(-0.562016044432279, a4, a6)
if __name__ == "__main__": #use fitted impedance coefficients to define behviour of core impedance this_core = [11.7204144319303, -0.0273771774408702, 29.7364068940134, 3.90272331971033, 0.000243735060998679, 5.8544055409592] this_CT = CT(this_core) #should look at GTC output when model inputs have uncertainty from the fits a1 = GTC.ureal(11.7204144319303,0.346683597109428,34,label ='a1',dependent = True) a2 = GTC.ureal(-0.0273771774408702,0.0136282110753501,34,label ='a2',dependent = True) a3 = GTC.ureal(29.7364068940134,0.695696459888704,34,label ='a3',dependent = True) GTC.set_correlation(-0.826126693986887, a1, a2) GTC.set_correlation(-0.881067593505553, a1, a3) GTC.set_correlation(0.551078899199967, a2, a3) a4 = GTC.ureal(3.90272331971033,0.0859519946028212,34,label ='a4',dependent = True) a5 = GTC.ureal(0.000243735060998679,0.0000527749402101903,34,label ='a5',dependent = True) a6 = GTC.ureal(5.8544055409592,0.501146466659668,34,label ='a6',dependent = True) GTC.set_correlation(-0.679730943215757, a4, a5) GTC.set_correlation(-0.562016044432279, a4, a6) GTC.set_correlation(0.303221134084321, a5, a6) this_core_gtc = [a1,a2,a3,a4,a5,a6] this_CT_gtc = CT(this_core_gtc) print GTC.log(a1) x = GTC.ureal(100,1) answer = this_CT_gtc.coreZgtc(x, 50) error = repr(answer.real) print error burden = GTC.ucomplex((0.186 + 0.12j),(0.0001,0.0001)) print(this_CT.burdenZgtc(burden, 5.0))
return output if __name__ == "__main__": #use fitted impedance coefficients to define behviour of core impedance this_core = [ 11.7204144319303, -0.0273771774408702, 29.7364068940134, 3.90272331971033, 0.000243735060998679, 5.8544055409592 ] this_CT = modelCT.CT(this_core) # a convenience CT w = 2 * math.pi * 50 # angular mains frequency # perturbing resistors values from S22008_burden_support.xlsx ohm10 = gtc.ucomplex((10.0112386 + 1j * w * 1724.3e-9), (0.0005995 / 2.0, 52e-9 / 2.0), 50, label='10 ohm') ohm50 = gtc.ucomplex((50.0046351 + 1j * w * 2590.5e-9), (0.0050221 / 2.0, 426.2e-9 / 2.0), 50, label='50 ohm') ohm100 = gtc.ucomplex((100.0048255 + 1j * w * -4140.8e-9), (0.0057092 / 2.0, 520.1e-9 / 2.0), 50, label='100 ohm') ohm1000 = gtc.ureal(1000, 0.01, 12, label='1000 ohm') #not measured on UB check_r = { '10': ohm10, '50': 50.0, '100': 100.0, '1000': 1000.0
def buildup(self, excite, e1, e2, e3, e4, e5a, e5b, mag1a, mag2a, mag3a, mag1b, mag2b, capa, capb): """ Assembles all the measurement results so that final ratio errors can be calculated. It is assumed that all input error values are signed as an error in Ta after using the signcheck method :param excite: the list of % excitation levels at which the errors apply :param e1: Ta 5:5 self cal of P1as :param e2: 20:5 P1ap vs P1bs :param e3: 100:5 P1bp vs P1ap :param e4: 100:5 P2ap vs P2bs :param e5: 100:5 P1bp vs P3as :param mag1a: magnetic series parallel error for P1a :param mag2a: magnetic series parallel error for P2a :param mag3a: magnetic series parallel error for P3a :param mag1b: magnetic series parallel error for P1b :param mag2b: magnetic series parallel error for P2b :param capa: capacitive series parallel erro for P1a :param capb: capacitive series parallel error for P1b :return: list of errors for p1as, p1ap, p2ap, p3as, p1bs, p1bp, p2bs """ # TODO should the measured errors already be fully corrected, or should some corrections occur in this method? #P1as, 5:5 in series polarity = 1 # SR830 readings normalised to be 'error' when Ta is the UUT p1as = [] for x in e1: ans = x * polarity ans = ans + gtc.ucomplex(0 + 0j,(self.ct_x_stability, self.ct_y_stability),self.df_ct_x_stability, label = 'ct_stability_p1as') ans = ans * gtc.ureal(1.0, self.brdn1a, self.df_brdn1a, label="burden1a") ans = ans * gtc.ureal(1.0, self.brdn2a, self.df_brdn2a, label="burden2a") p1as.append(ans) # as measured, modified by polarity p1ap = [] for x in p1as: ans = x + mag1a + capa ans = ans + gtc.ucomplex(0 + 0j,(self.ct_x_stability, self.ct_y_stability),self.df_ct_x_stability, label = 'ct_stability_p1ap') ans = ans * gtc.ureal(1.0, self.brdn1b, self.df_brdn1b, label = "burden1b") ans = ans * gtc.ureal(1.0, self.brdn2b, self.df_brdn2b, label="burden2b") p1ap.append(ans) polarity = -1 # as Tb is being calibrated p1bs = [] for i in range(len(p1ap)): ans = p1ap[i] + e2[i] * polarity ans = ans + gtc.ucomplex(0 + 0j,(self.ct_x_stability, self.ct_y_stability),self.df_ct_x_stability, label = 'ct_stability_p1bs') p1bs.append(ans) p1bp = [] for i in range(len(p1bs)): ans = p1bs[i] + capb + mag1b ans = ans + gtc.ucomplex(0 + 0j,(self.ct_x_stability, self.ct_y_stability),self.df_ct_x_stability, label = 'ct_stability_p1bp') p1bp.append(ans) polarity = 1 # as Ta is being calibrated p2ap = [] for i in range(len(p1bp)): ans = p1bp[i] + e3[i] * polarity ans = ans + gtc.ucomplex(0 + 0j,(self.ct_x_stability, self.ct_y_stability),self.df_ct_x_stability, label = 'ct_stability_p2ap') p2ap.append(ans) polarity = -1 # as Tb is being calibrated p2bs = [] for i in range(len(p2ap)): ans = p2ap[i] + e4[i] * polarity ans = ans + gtc.ucomplex(0 + 0j,(self.ct_x_stability, self.ct_y_stability),self.df_ct_x_stability, label = 'ct_stability_p2bs') p2bs.append(ans) polarity = 1 # as Ta is being calibrated p3as_a = [] for i in range(len(p2bs)): ans = p2bs[i] + e5a[i] * polarity ans = ans + gtc.ucomplex(0 + 0j,(self.ct_x_stability, self.ct_y_stability),self.df_ct_x_stability, label = 'ct_stability_p3as_a') p3as_a.append(ans) polarity = 1 # as Ta is being calibrated p3as_b = [] for i in range(len(p1bp)): ans = p1bp[i] + e5b[i] * polarity ans = ans + gtc.ucomplex(0 + 0j,(self.ct_x_stability, self.ct_y_stability),self.df_ct_x_stability, label = 'ct_stability_p3as_b') p3as_b.append(ans) return p1as, p1ap, p2ap, p3as_a, p3as_b, p1bs, p1bp, p2bs