def calculate_values(self, room_temperature): y = [] yzero = [] for x in self.datdict: item_label = x['item'] + str(x['nom_freq']) + x['ubrange'] answer = ubridge.bridge_value(x['ubrange'], x['rdial'], x['xdial'], x['frequency'], 1, new_label=item_label) # next multiply the ubrdige values by factors relating to the uut if x['item'] != 'coax zero': # no uncertainty in the coax zero uut uuttemp = ureal(x['temperature'], x['tempu'], x['tempdf'], 'uuttemp' + x['item']) rtempco = ureal(x['uuttempcor'], x['uuttempcoru'], x['uuttempcordf'], 'rtempco' + x['item']) r_value = answer.real * (1 + mul2(rtempco, uuttemp - room_temperature)) xtempco = ureal(x['uuttempcox'], x['uuttempcoxu'], x['uuttempcoxdf'], 'xtempco' + x['item']) x_value = answer.imag / (2 * pi * x['frequency']) * ( 1 + mul2(xtempco, uuttemp - room_temperature)) else: assert x['item'] == 'coax zero', "label not 'coax zero' when it should be" r_value = answer.real x_value = answer.imag / (2 * pi * x['frequency']) # create lists of the ubridge values y.append( (x['item'], x['ubrange'], str(x['nom_freq']), r_value, x_value)) # all tuples of R-L or G-C, including coax zeros if x[ 'item'] == 'coax zero': # a list of just the coax zeros is also created, duplicating the entry in the full list yzero.append((x['ubrange'], str(x['nom_freq']), r_value, x_value)) return y, yzero
def get_R1(self, f, sheet, uncL, dofL): R1r = self.get_xl_cell(4, 8, sheet) R1i = self.get_xl_cell(4, 9, sheet) * f * 2 * math.pi R1_r = ureal(R1r, R1r * uncL[13] / 1000000, dofL[13], "Resistor (R1 real)") # use same uncertainty as for R2 R1_i = ureal(R1i, R1r * uncL[14] / 1000000 / (2 * f * math.pi), dofL[14], "Resistor (R1 imag)") return R1_r, R1_i
def get_Kstar(self, f, dRSet, sheet, uncL, dofL): Kraw = self.get_Kraw(dRSet, sheet) K_r = ureal(Kraw[0], Kraw[0] * uncL[0] / 1000000, dofL[0], "Divider Ratio (K real)") K_i = ureal(Kraw[0] * (f * Kraw[1] + Kraw[2]), Kraw[0] * uncL[1] / 1000000, dofL[1], "Divider Ratio (K imag)") return K_r, K_i
def get_beta(self, vd, v1, uncL, dofL): beta_r = ureal(vd, (vd * uncL[9] + uncL[22]) / 1000000, dofL[9], "Beta Ratio (beta real)") beta_i = ureal(-v1 * 0.0000030, vd * uncL[24] / 1000000 + 3.5e-7, dofL[24], "Beta Ratio (beta imag)") ## bet = vd-v1*0.0000030j # real part is cell U10 of PowerCalc, imag is from offset in WattFuncs calculate() macro. Also include offset as being proportional to V1. ## beta_u = ((vd*uncL[9]+uncL[22])/1000000, vd*1/1000000+3.5e-7) #imag uncertainty is 1 ppm of dial setting plus offset uncertainty from cell BI22 of "IVD offset SR830 readings May12.xls" ## return ucomplex(bet, beta_u, dofL[9], "Beta Ratio (beta)") return beta_r, beta_i
def get_alpha(self, wd, v1, uncL, dofL): alpha_r = ureal(wd, (wd * uncL[5] + uncL[21]) / 1000000, dofL[5], "Alpha Ratio (alpha real)") alpha_i = ureal(-v1 * 0.0000033, wd * uncL[23] / 1000000 + 5.7e-7, dofL[23], "Alpha Ratio (alpha imag)") ## alph = wd-v1*0.0000033j # real part is cell Q10 of PowerCalc, imag is from offset in WattFuncs calculate() macro. Also include offset as being proportional to V1. ## alpha_u = ((wd*uncL[5]+uncL[21])/1000000, wd*1/1000000+5.7e-7) #imag uncertainty is 1 ppm of dial setting plus offset uncertainty from cell BJ22 of "IVD offset SR830 readings May12.xls" ## return ucomplex(alph, alpha_u, dofL[5], "Alpha Ratio (alpha)") return alpha_r, alpha_i
def get_DetGain(self, f, sheet, uncL, dofL): DetG = self.get_xl_cell(4, 20, sheet) # cell AC10 of PowerCalc DetAPh = math.radians(self.get_DAmpPhse( f, sheet)) # cell AD10 of PowerCalc G_mag = ureal(DetG, DetG * uncL[17] / 1000000, dofL[17], "Detector Gain (G mag)") G_ph = ureal(DetAPh, uncL[18] / 1000000, dofL[18], "Detector Gain Phase (G phase)") #return UncertainComplex(DetAmpGain*cos(DetAmpPhse), DetAmpGain*sin(DetAmpPhse)) return G_mag, G_ph
def get_R1R2(self, f, sheet, uncL, dofL): R2R1r = self.get_xl_cell(4, 12, sheet) # cell S10 of PowerCalc R2R1i = self.get_xl_cell( 4, 13, sheet) * f * 2 * math.pi # cell T10 of PowerCalc R2R1_r = ureal(R2R1r, abs(R2R1r * uncL[7] / 1000000), dofL[7], "R2 R1 Ratio (R2/R1 real)") R2R1_i = ureal(R2R1i, abs(R2R1r * uncL[8] / 1000000), dofL[8], "R2 R1 Ratio (R2/R1 imag)") ## return ucomplex(complex(R2R1_re, R2R1_im), (abs(R2R1_re*uncL[7]/1000000), abs(R2R1_re*uncL[8]/1000000)), dofL[7], "R2 R1 Ratio (R2/R1)") return R2R1_r, R2R1_i
def get_R2(self, f, sheet, uncL, dofL): R2r = self.get_xl_cell(4, 10, sheet) R2i = self.get_xl_cell(4, 11, sheet) * f * 2 * math.pi R2_r = ureal(R2r, R2r * uncL[13] / 1000000, dofL[13], "Resistor (R2 real)") R2_i = ureal(R2i, R2r * uncL[14] / 1000000 / (2 * f * math.pi), dofL[14], "Resistor (R2 imag)") ## R_2 = complex(self.get_xl_cell('D', 10, sheet), self.get_xl_cell('D', 11, sheet)*f*2*math.pi) # cells Y10 and Z10 of PowerCalc ## R2_u = (R_2.real*uncL[13]/1000000, 10000*uncL[14]/1000000/(2*f*math.pi)) ## return ucomplex(R_2, R2_u, dofL[13], "Resistor (R2)") return R2_r, R2_i
def get_DetC(self, f, sheet, uncL, dofL): DCr = self.get_xl_cell(4, 17, sheet) DCi = self.get_xl_cell( 4, 16, sheet ) * f * 2 * math.pi * 1e-12 # cells AE10 and AF10 of PowerCalc ## DetC_u = (Det_C.real*uncL[19]/1000000,Det_C.imag*uncL[20]/1000000) DetC_r = ureal(DCr, DCr * uncL[19] / 1000000, dofL[19], "Detector Admittance (Yd real)") DetC_i = ureal(DCi, DCi * uncL[20] / 1000000, dofL[20], "Detector Admittance (Yd imag)") ## return ucomplex(Det_C, DetC_u, dofL[20], "Detector Admittance (Yd)") return DetC_r, DetC_i
def get_Y1(self, f, sheet, C1Tcrct, uncL, dofL): Y1r = self.get_xl_cell(4, 15, sheet) # cell W10 of PowerCalc Y1i = f * 2 * math.pi * C1Tcrct * 0.000001 # cell X10 of PowerCalc Y1_r = ureal(Y1r, Y1i * uncL[11] / 1000000, dofL[11], "Capacitor Admittance (Y1 real)") Y1_i = ureal(Y1i, Y1i * uncL[12] / 1000000, dofL[12], "Capacitor Admittance (Y1 imag)") ## g_1 = self.get_xl_cell('D', 15, sheet) # cell W10 of PowerCalc ## Y_1 = f*2*math.pi*C1Tcrct*0.000001 # cell X10 of PowerCalc ## C1_u = (Y_1*uncL[11]/1000000, Y_1*uncL[12]/1000000) # """!!! change from orignal excel template !!!""" ## return ucomplex(complex(g_1, Y_1), C1_u, dofL[12], "Capacitor Admittance (Y1)") return Y1_r, Y1_i
def calculate_enh_fact(T_kelvin, P_Pa): T = conv.float2GTC(T_kelvin) P = conv.float2GTC(P_Pa) if T.x < 273.15: medium = 'ice' else: medium = 'water' #calculate vapour pressure eT eT = conv.calculate_SVP(T, medium=medium) #initialize a,b coefficient A = np.zeros(4) B = np.zeros(4) if medium == 'ice': A[0] = -5.5898101e-2 A[1] = 6.7140389e-4 A[2] = -2.7492721e-6 A[3] = 3.8268958e-9 B[0] = -8.1985393e1 B[1] = 5.8230823e-1 B[2] = -1.6340527e-3 B[3] = 1.6725084e-6 elif medium == 'water': A[0] = -1.6302041e-1 A[1] = 1.8071570e-3 A[2] = -6.7703064e-6 A[3] = 8.5813609e-9 B[0] = -5.9890467e1 B[1] = 3.4378043e-1 B[2] = -7.7326396e-4 B[3] = 6.3405286e-7 a = ureal(0, 0) b = ureal(0, 0) #calculate a coefficient for i in range(4): a += A[i] * pow(T, i) # calculate b coefficient for i in range(4): b += B[i] * pow(T, i) b = exp(b) s1 = a * (1 - eT / P) s2 = b * (P / eT - 1) f = exp(s1 + s2) return f
def get_HPcrctn(self, sheet, uncL, dofL): HP3458corectn = self.get_xl_cell(4, 7, sheet) HP3458corectn_u = HP3458corectn * uncL[ 2] / 1000000 # 3458 type b uncertainty for GodsAC included here HP_crctn = ureal(HP3458corectn, HP3458corectn_u, dofL[3], "Divider Output Voltage (V1)") return HP_crctn
def lists2ureal(value_list,unc_list=[],k=2): for i,val in enumerate(value_list): try: d=unc_list[i] except: unc_list.append(0) result = [ureal(value_list_i, unc_list_i / k) for value_list_i, unc_list_i in zip(value_list, unc_list)] return result
def calculate_values(self, room_temperature, this_ubridge): """ Separates out all readings labelled 'coax zero' of which it is assumed that there is one and only one for each range used. These can subsequently be subtracted. :param room_temperature: :param this_ubridge: UNIVERSALBRIDGE object :return: a list of calculated values including the calculated zeros and a list of calculated zeros """ y = [] yzero = [] for x in self.datdict: this_label = x['item'] + str(x['nom_freq']) + x[ 'ubrange'] # str so e.g. 1k and 1000 both are strings answer = this_ubridge.bridge_value(x['ubrange'], x['rdial'], x['xdial'], x['frequency'], 1, new_label=this_label) # next multiply the ubrdige values by factors relating to the uut if x['item'] != 'coax zero': # no uncertainty in the coax zero uut uuttemp = ureal(x['temperature'], x['tempu'], x['tempdf'], 'uuttemp' + x['item']) rtempco = ureal(x['uuttempcor'], x['uuttempcoru'], x['uuttempcordf'], 'rtempco' + x['item']) r_value = answer.real * ( 1 + mul2(rtempco, uuttemp - room_temperature)) xtempco = ureal(x['uuttempcox'], x['uuttempcoxu'], x['uuttempcoxdf'], 'xtempco' + x['item']) x_value = answer.imag / (2 * pi * x['frequency']) * ( 1 + mul2(xtempco, uuttemp - room_temperature)) else: assert x[ 'item'] == 'coax zero', "label not 'coax zero' when it should be" r_value = answer.real x_value = answer.imag / (2 * pi * x['frequency']) # create lists of the ubridge values y.append( (x['item'], x['ubrange'], str(x['nom_freq']), r_value, x_value)) # all tuples of R-L or G-C, including coax zeros if x['item'] == 'coax zero': # a list of just the coax zeros is also created, duplicating the entry in the full list yzero.append( (x['ubrange'], str(x['nom_freq']), r_value, x_value)) return y, yzero
def get_ShuntByTrans(self, f, sName, sheet, transR, uncL, dofL): shuntraw = self.get_shuntraw(sName, sheet) shunt_r = ureal(shuntraw[0], shuntraw[0] * uncL[3] / 1000000, dofL[3], "Shunt Resistance (R3 real)") shunt_i = ureal(f * 2 * math.pi * shuntraw[1] * 0.000001, shuntraw[0] * uncL[4] / 1000000, dofL[4], "Shunt Resistance (R3 imag)") ## shnt = complex(shuntraw[0], f*2*math.pi*shuntraw[1]*0.000001) # cells O10 and P10 of PowerCalc worksheet ## Shunt = ucomplex(shnt,(shnt.real*uncL[3]/1000000, shnt.real*uncL[4]/1000000), dofL[3], "Shunt Resistance (R3)") Trans = ucomplex( complex(transR, 0), (transR * 2 / 1000000, 0), 6, "Shunt by Transformer Resistance (R3)" ) ######## ! zeros as placeholder for phase & uncertainty of Transformer ratio if transR > 1: return Shunt / Trans else: return shunt_r, shunt_i
def dict_to_ureal(self, unr_dict): """ Takes a dictionary created by ureal_to_dict and creates a GTC uncertain real. :param unr_dict: dictionary of parts of a GTC uncertain real. :return: GTC uncertain real """ return ureal(unr_dict['x'], unr_dict['u'], unr_dict['df'], label=unr_dict['label'])
def json_to_ureal(self, unr_json): """ Takes a json string as created by ureal_to_json and creates a GTC uncertain real. :param unr_json: a json string of a dictionary of parts of a GTC uncertain real. :return: GTC uncertain real """ unr_dict = loads(unr_json) return ureal(unr_dict['x'], unr_dict['u'], unr_dict['df'], label=unr_dict['label'])
def muirhead_tand(self, caps): """ assumes 10,000 rad/s and returns G/wC in mrad also assumes a 0.005 ohm standar uncertainty in series connection caps: is the list of jig_corrected muirhead capacitor values """ w = 1e4 seriesR = 0.005 tan_deltas = [] for i in range(len(caps)): seriesG = ureal(0, (w * caps[i][1].x) ** 2 * seriesR, 10, 'seriesG') calc_tand = atan((caps[i][0] + seriesG) / (caps[i][1] * w)) tan_deltas.append(calc_tand * 1e3) return tan_deltas
def muirhead_zeros(self, y_corrected): """ Returns list of muirhead capacitor values with jig zero subtracted Includes a 0.05 pF standard uncertainty in jig definition y_corrected: capacitance values that have had coaxial zeros subtracted """ jig_zero = ureal(0, 0.05e-12, 10, 'jig_zero') # 0.05 pF 1 sigma names = ['M1', 'M0.1', 'M0.01', 'M0.001', 'M0.0005'] muirhead_caps = [] for i in range(len(y_corrected)): if self.data_block[i][0] in names: for j in range(len(y_corrected)): if self.data_block[j][0] == self.data_block[i][0] + 'zero': # e.g. 'M1zero, 'M0.0005zero' print(repr(y_corrected[i][0])) thing = jig_zero + y_corrected[i][0] jig_corrected = ( y_corrected[i][0] - y_corrected[j][0], jig_zero + y_corrected[i][1] - y_corrected[j][1]) muirhead_caps.append(jig_corrected) return muirhead_caps
def get_csv_data(self, path): """ :param path: the csv file formatted to hold all the calibration dictionaries :return: four dictionaries caldata, acdc, tempcoeffs, stability, ivd The caldata dictionary contains the calibrated component values, acdc contains frequency dependence uncertainty, tempcoeffs has estimates of termperature coefficients, stability has uncertainties for time dependence and ivd has linearity estimates for the two main inductive voltage dividers. """ cal_file = open(path, mode='r') reader = csv.reader(cal_file) table = [] for row in reader: table.append(row) cal_file.close() Nr = len(table) caldata = {} acdc = {} tempcoeffs = {} stability = {} ivd = {} for r in range(2, Nr): # assumes 2 header rows dictionary = table[r][0] assert dictionary in [ 'caldata', 'acdc', 'tempcoeffs', 'stability', 'ivd' ], 'csv dictionary name not in list' key = table[r][1] value = ureal(float(table[r][2]), float(table[r][3]), float(table[r][4]), table[r][5]) if dictionary == 'caldata': caldata[key] = value elif dictionary == 'acdc': acdc[key] = value elif dictionary == 'tempcoeffs': tempcoeffs[key] = value elif dictionary == 'stability': stability[key] = value elif dictionary == 'ivd': ivd[key] = value return caldata, acdc, tempcoeffs, stability, ivd
from humidity import gen2500 from GTC import ureal gen = gen2500(uncertainty_mode=True) Ps_PSI = ureal(14.7, 7e-5, label='Ps') Ts_C = ureal(2, 0.01, label='Ts') Pc_PSI = ureal(14.65, 7e-5, label='Pc') Tc_C = ureal(31, 0.01, label='Tc') gen.set_values(Ps_PSI=Ps_PSI, Ts_C=Ts_C, Pc_PSI=Pc_PSI, Tc_C=Tc_C) gen.summary() print('RH=', gen.RH)
data_block[i].append(rU) # expanded uncertainty data_block[i].append(kr) # now for loss angle td = tandeltas[i].x utd = tandeltas[i].u ktd = k_factor(tandeltas[i].df) Utd = ktd * utd data_block[i].append(td) data_block[i].append(Utd) data_block[i].append(ktd) self.excel_obj.makeworkbook(data_block, 'muirhead') if __name__ == "__main__": calfile = r'ubdict_dec_2019.csv' room_temperature = ureal(20, 0.5, 10, 'temperature') # this should be the ambient temperature given in conditions # create the bridge object ubridge = ub.UNIVERSALBRIDGE(calfile, room_temperature) # temperature put here as it might be in common with the UUT block_descriptor = [9, 24, 1, 15] # this simply has to correctly match the spreadsheet.[9, 35, 1, 15] cap_set = UUT(ubridge, 'S22012.xlsx', 'pyUBreadings', block_descriptor, 'capResults.xlsx', 'pyUBresults') # note that a different temperature could be used for the UUT cap_answers, cap_zeros = cap_set.calculate_values(room_temperature) cap_zero_corrected = cap_set.subtract_zeros(cap_answers, cap_zeros) cmc_list = cap_set.cmc_check() ## cap_set.create_output(cap_zero_corrected, cmc_list) #creates capResults.xlsx with just C, G results a = cap_set.muirhead_zeros(cap_zero_corrected) for i in range(len(a)): print(a[i]) b = cap_set.muirhead_tand(a) for i in range(len(b)):
def set_values(self, Ps_PSI, Ts_C, Pc_PSI, Tc_C, flow=20, Ps_u_PSI=0, Ts_u_C=0, Pu_u__PSI=0, Tc_u_C=0, eta=1, eta_u=0): #print('Ts_C=',Ts_C) #write initial values to object self.Ps_input = Ps_PSI self.Ts_input = Ts_C self.Pc_input = Pc_PSI self.Tc_input = Tc_C self.flow = flow self.eta = eta self.eta_u = eta_u #convert initial values to proper format -! values in PSI and Celsius !!! self.Ps_GTC = Ps_PSI if conv.isGTC(Ps_PSI) else ureal( Ps_PSI, Ps_u_PSI, label='Ps') self.Ts_GTC = Ts_C if conv.isGTC(Ts_C) else ureal( Ts_C, Ts_u_C, label='Ts') self.Pc_GTC = Pc_PSI if conv.isGTC(Pc_PSI) else ureal( Pc_PSI, Pc_u_PSI, label='Pc') self.Tc_GTC = Tc_C if conv.isGTC(Tc_C) else ureal( Tc_C, Ts_u_C, label='Tc') self.eta_u_GTC = eta if conv.isGTC(eta) else ureal( eta, eta_u, label='eta') #conversion of units self.Ps_GTC = conv.PSI2Pa(self.Ps_GTC) self.Ts_GTC = conv.Celsius2Kelvin(self.Ts_GTC) self.Pc_GTC = conv.PSI2Pa(self.Pc_GTC) self.Tc_GTC = conv.Celsius2Kelvin(self.Tc_GTC) self.DewPoint = [] self.SVP_Ts_GTC = conv.calculate_SVP( self.Ts_GTC ) # saturation vapour pressure for temperature of saturator self.SVP_Tc_GTC = conv.calculate_SVP( self.Tc_GTC ) #saturation vapour pressure for temperature of chamber self.f_TsPs_GTC = conv.calculate_enh_fact( self.Ts_GTC, self.Ps_GTC ) # enhancement factor for saturator pressure and temperature self.f_TcPc_GTC = conv.calculate_enh_fact( self.Tc_GTC, self.Pc_GTC ) # enhancement factor for chamber pressure and temperature self.RH_GTC = conv.calculate_RH_from_PT(self.Ps_GTC, self.Ts_GTC, self.Pc_GTC, self.Tc_GTC, self.eta_u_GTC) self.DewPoint_GTC = conv.calculate_DewPoint2RH(self.RH_GTC, self.Tc_GTC) self.SVP_Ts = self.SVP_Ts_GTC.x self.SVP_Tc = self.SVP_Tc_GTC.x self.f_TsPs = self.f_TsPs_GTC.x self.f_TsPs = self.f_TsPs_GTC.x self.RH = self.RH_GTC.x self.DewPoint = self.DewPoint_GTC.x #print('self.SVP_Ts=', self.SVP_Ts) #print('self.SVP_Tc=',self.SVP_Tc) #print('self.f_TsPs=', self.f_TsPs) #print('self.f_TcPc=', self.f_TcPc) #print('self.RH_GTC=', self.RH_GTC) self.f_TcPc = [ ] #enhancement factor for chamber pressure and temperature self.f_TsPs = [ ] # enhancement factor for chamber pressure and temperature #self.RH = conv.calculate_RH_from_PT(self.Ps_GTC, self.Ts_GTC, self.Pc_GTC, self.Tc_GTC, self.eta_u_GTC) # Data for experiment self.N += 1 self.history.append(self.RH_GTC) self.mean = type_a.mean(self.history) self.std = type_a.standard_uncertainty( self.history) if self.N > 1 else 0
def __init__(self, uncertainty_mode=False): self.Ps_input = [] #Saturation pressure PSI self.Ts_input = [] #Saturation temperature C self.Pc_input = [] #Chamber pressure PSI self.Tc_input = [] #Chamber temperature C self.Ps = [] #Saturation pressure Pa self.Ts = [] #Saturation temperature K self.Pc = [] #Chamber pressure Pa self.Tc = [] #Chamber temperature K self.flow = 20 # air flow in liters/min self.eta = 1 #saturation efficiency coefficient self.k = 2 self.RH = [] self.DewPoint = [] self.SVP_Tc = [ ] #saturation vapour pressure for temperature of chamber self.SVP_Ts = [ ] # saturation vapour pressure for temperature of saturator self.f_TcPc = [ ] #enhancement factor for chamber pressure and temperature self.f_TsPs = [ ] # enhancement factor for chamber pressure and temperature #data for GTC uncertainty mode self.uncertainty_mode = uncertainty_mode # True if GTC uncertainty calculations available self.Ps_u = 0 #Saturation pressure standard uncertainty self.Ts_u = 0 #Saturation temperature standard uncertainty self.Pc_u = 0 #Chamber pressure standard uncertainty self.Tc_u = 0 #Chamber pressure standard uncertainty self.eta_u = 0 ##saturation efficiency coefficient standard uncertainty, 1%=0.01 self.Ps_GTC = ureal(0, 0) #Saturation pressure GTC number self.Ts_GTC = ureal(0, 0) #Saturation temperature GTC number self.Pc_GTC = ureal(0, 0) #Chamber pressure GTC number self.Tc_GTC = ureal(0, 0) #Chamber pressure GTC number self.RH_GTC = ureal(0, 0) #GTC number self.DewPoint_GTC = ureal(0, 0) #GTC number self.SVP_Tc_GTC = ureal( 0, 0 ) #saturation vapour pressure for temperature of chamber GTC number self.SVP_Ts_GTC = ureal( 0, 0 ) # saturation vapour pressure for temperature of saturator GTC number self.f_TcPc_GTC = ureal( 0, 0 ) #enhancement factor for chamber pressure and temperature GTC number self.f_TsPs_GTC = ureal( 0, 0 ) # enhancement factor for chamber pressure and temperature GTC number self.eta_u_GTC = ureal(0, 0) # reset data for experiment self.N = 0 # number of iterations self.history = [] self.mean = 0 self.std = 0 #initiate new object for storage VISA commands self.VISA = VISA()
def calculate_SVP(T_kelvin, method='wexler', medium='water'): #possible options method='wexler' or 'sonntag', medium='water' or 'ice' T = conv.float2GTC(T_kelvin) SVP = ureal(0, 0) # WEXLER WATER if (method == 'wexler') and (medium == 'water'): s06 = 0 # sum of gi*T^(i-2) for i=0:6 g = np.zeros(8) g[0] = -2.83657440e3 g[1] = -6.02807656e3 g[2] = 1.95426361e1 g[3] = -2.73783019e-2 g[4] = 1.62616980e-5 g[5] = 7.02290560e-10 g[6] = -1.86800090e-13 g[7] = 2.71503050 for i in range(7): s06 += g[i] * pow(T, i - 2) s7 = g[7] * log(T) #gi*ln(T) for i=7 s07 = s06 + s7 SVP = exp(s07) #WEXLER ICE elif (method == 'wexler') and (medium == 'ice'): s04 = 0 # sum of ki*T^(i-1) for i=0:4 k = np.zeros(6) k[0] = -5.8666426e3 k[1] = 2.2328702e1 k[2] = 1.39387003e-2 k[3] = -3.42624020e-5 k[4] = 2.7040955e-8 k[5] = 6.70635220e-1 for i in range(5): s04 += k[i] * pow(T, i - 1) s5 = k[5] * log(T) #ki*ln(T) for i=5 s05 = s04 + s5 SVP = exp(s05) #SONNTAG WATER elif (method == 'sonntag') and (medium == 'water'): s03 = 0 # sum of ki*T^(i-1) for i=0:3 g = np.zeros(5) g[0] = -6096.9385 g[1] = 21.2409642 g[2] = -2.711193e-2 g[3] = 1.673952e-5 g[4] = 2.433502 for i in range(4): s03 += g[i] * pow(T, i - 1) s4 = g[4] * log(T) #gi*ln(T) for i=4 s04 = s03 + s4 SVP = exp(s04) #SONNTAG ICE elif (method == 'sonntag') and (medium == 'ice'): s03 = 0 # sum of ki*T^(i-1) for i=0:3 k = np.zeros(5) k[0] = -6024.5282 k[1] = 29.32707 k[2] = 1.0613868e-2 k[3] = -1.3198825e-5 k[4] = -0.49382577 for i in range(4): s03 += k[i] * pow(T, i - 1) s4 = k[4] * log(T) #ki*ln(T) for i=4 s04 = s03 + s4 SVP = exp(s04) else: print( "Error - possible options for function method='wexler' or 'sonntag', medium='water' or 'ice'" ) SVP = SVP + ureal(0, 1, label='SVP_aprox') return SVP
def float2GTC(value): if conv.isGTC(value): return value else: return ureal(value, 0)
def isGTC(value): typeGTC = type(ureal(0, 0)) if type(value) == typeGTC: return True else: return False
T_Kelvin = conv.float2GTC(T_Kelvin) T_Celsius = conv.Kelvin2Celsius(T_Kelvin) #constants A1 = 17.625 B1 = 243.03 #Celsius numerattor = B1 * (log(RH / 100) + A1 * T_Celsius / (B1 + T_Celsius)) denominator = A1 - log(RH / 100) - A1 * T_Celsius / (B1 + T_Celsius) DewPoint = numerattor / denominator return DewPoint ########################################################3 Ps = ureal(14.7, 7e-5, label='Ps') Ts = ureal(2, 0.01, label='Ts') Pc = ureal(14.65, 7e-5, label='Pc') Tc = ureal(31, 0.01, label='Tc') eta = ureal(1, 0.001, label='eta') #RH=conv.calculate_RH_from_PT(Ps,Ts,Pc,Tc,verbose=True,eta=eta) #print('RH value=',RH.x,'U(f)=',2*RH.u) #Real data from generator gen = gen2500(uncertainty_mode=True) Ps_PSI = ureal(14.7, 7e-5, label='Ps') Ts_C = ureal(2, 0.01, label='Ts') Pc_PSI = ureal(14.65, 7e-5, label='Pc') Tc_C = ureal(31, 0.01, label='Tc')
def run(): m = [[ureal(5, 1), ureal(-1, 0.3), ureal(3, 1.3)], [ureal(1, 0.1), ureal(2, 0.8), ureal(-3, 1)], [ureal(-1, 0.5), ureal(2, 1.1), ureal(4, 0.3)]] b = [ureal(1, 0.2), ureal(2, 1.1), ureal(3, 0.4)] ma = uarray(m) ba = uarray(b) # vector * vector z = b[0] * 1 + b[1] * 2 + b[2] * 3 za = ba @ [1, 2, 3] assert equivalent(z.x, za.value()) assert equivalent(z.u, za.uncertainty()) # switch lhs and rhs z = 1 * b[0] + 2 * b[1] + 3 * b[2] za = [1, 2, 3] @ ba assert equivalent(z.x, za.value()) assert equivalent(z.u, za.uncertainty()) try: ba @ [1, 2] except ValueError: # Expect this error -> shapes (3,) and (2,) not aligned: 3 (dim 0) != 2 (dim 0) pass else: raise ValueError('this should not work -> ba @ [1, 2]') # vector * matrix z = [ 1 * m[0][0] + 2 * m[1][0] + 3 * m[2][0], 1 * m[0][1] + 2 * m[1][1] + 3 * m[2][1], 1 * m[0][2] + 2 * m[1][2] + 3 * m[2][2] ] za = [1, 2, 3] @ ma for i in range(3): assert equivalent(z[i].x, za[i].x) assert equivalent(z[i].u, za[i].u) try: [1, 2] @ ma except ValueError: # Expect this error -> shapes (2,) and (3,3) not aligned: 2 (dim 0) != 3 (dim 0) pass else: raise ValueError('this should not work -> [1, 2] @ ma') # matrix * vector z = [ m[0][0] * b[0] + m[0][1] * b[1] + m[0][2] * b[2], m[1][0] * b[0] + m[1][1] * b[1] + m[1][2] * b[2], m[2][0] * b[0] + m[2][1] * b[1] + m[2][2] * b[2] ] za = ma @ ba for i in range(3): assert equivalent(z[i].x, za[i].x) assert equivalent(z[i].u, za[i].u) try: ma @ np.arange(4) except ValueError: # Expect this error -> shapes (3,3) and (4,) not aligned: 3 (dim 1) != 4 (dim 0) pass else: raise ValueError('this should not work -> ma @ np.arange(4)') # matrix * matrix na = np.arange(10 * 10).reshape(10, 10) * -3.1 nb = np.arange(10 * 10).reshape(10, 10) * 2.3 nc = na @ nb ua = uarray(na.copy() * ureal(1, 0)) ub = uarray(nb.copy() * ureal(1, 0)) uc = ua @ ub assert nc.shape == uc.shape i, j = nc.shape for ii in range(i): for jj in range(j): assert equivalent(na[ii, jj], ua[ii, jj].x) assert equivalent(nb[ii, jj], ub[ii, jj].x) assert equivalent(nc[ii, jj], uc[ii, jj].x, tol=1e-10) # switch the ndarray and uarray order and also use a regular Python list for mix in [na @ ub, ua @ nb, na.tolist() @ ub, ua @ nb.tolist()]: assert mix.shape == nc.shape i, j = mix.shape for ii in range(i): for jj in range(j): assert equivalent(mix[ii, jj].x, nc[ii, jj], tol=1e-10) try: ma @ np.arange(4 * 4).reshape(4, 4) except ValueError: # Expect this error -> shapes (3,3) and (4,4) not aligned: 3 (dim 1) != 4 (dim 0) pass else: raise ValueError( 'this should not work -> ma @ np.arange(4*4).reshape(4,4)') # test a bunch of different dimensions test_dims = [ #[(), ()], [(0, ), (1, 3)], [(1, ), (1, 3)], [(4, ), (4, 3)], [(2, 4), (4, )], [(2, 4), (3, )], [(2, 4), (3, 2)], [(2, 4), (4, 2)], [(1, 2, 4), (1, 4, 2)], [(2, 2, 4), (1, 4, 2)], [(1, 2, 4), (2, 4, 2)], [(2, 2, 4), (2, 4, 2)], [(3, 2, 4), (3, 4, 2)], [(6, 2, 4), (3, 2, 2)], [(6, 2, 4), (3, 4, 8)], [(6, 2, 4), (6, 4, 8)], [(5, 3, 2, 4), (5, 3, 4, 2)], [(3, 2, 2, 4), (3, 9, 4, 2)], [(8, 3, 1, 2, 4), (8, 3, 9, 4, 2)], ] for s1, s2 in test_dims: na = np.arange(int(np.prod(np.array(s1)))).reshape(s1) nb = np.arange(int(np.prod(np.array(s2)))).reshape(s2) try: nc = na @ nb except: nc = None ua = uarray(na.copy() * ureal(1, 0)) ub = uarray(nb.copy() * ureal(1, 0)) try: uc = ua @ ub except: if nc is not None: raise AssertionError( 'The regular @ PASSED, the custom-written @ FAILED') else: if nc is None: raise AssertionError( 'The regular @ FAILED, the custom-written @ PASSED') assert np.array_equal( nc, uc), 'The arrays are not equal\n{}\n{}'.format(nc, uc)
def lists2ureal(value_list,unc_list=[],k=2): for i,val in enumerate(value_list): try: d=unc_list[i] except: unc_list.append(0) result = [ureal(value_list_i, unc_list_i / k) for value_list_i, unc_list_i in zip(value_list, unc_list)] return result #Dane ze świadectwa dla typu 5685 nr 1114 R0=ureal(x=2.5534637,u=0.0000041/2,label='R0') #print(Calculate_Wr(961.78)) #print(Calculate_temp_from_W(1.079488)) #Dane ze świadectwa t=[961.78,660.332,419.527,231.928] t_U=[0.0052,0.0040,0.0017,0.0015] Wt=[4.28556295,3.37543469,2.56855103,1.89259628] #Konwersja liczb do postaci ureal t=lists2ureal(t,t_U) Wt=lists2ureal(Wt) Wr=map(Calculate_Wr,t)