def ratioerror(self, shuntv, xv, yv, shunt, comr, nomexcitation, full_scale):
        """
        Calculates the measured ratio error. All parameters are lists of data from

        :param shuntv: shuntv: voltage measured across the shunt on the secondary monitoring the primary current
        :param xv: xv: real part of voltage across the common resistor
        :param yv: imaginary part of the voltage across the common resistor
        :param shunt: value of the secondary shunt
        :param comr: value of the common resistor
        :param nomexcitation: nominal excitation list, e.g. 10%, 20% ... 120%
        :return: a list of errors, a list of actual excitation levels and a list of the matching nominal excitations
        """

        # TODO consider a 'swap' flag for where the nominal reference ratio was actually on the UUT side
        e = []  # list of error e1 at each excitation level
        excite = []  # matching list of fractional excitation level
        nom_excite = []  # matched nominal excitation level
        for i in range(len(xv)):
            xvolt = xv[i] * gtc.ureal(1.0, self.sr830, self.df_sr830, label = 'sr830 '+ repr(xv[i]))  #type B
            xvolt = xvolt + gtc.ureal(0.0, self.cmnmode, self.df_cmnmode, label = 'common mode ' + repr(xvolt.x))
            yvolt = yv[i] * gtc.ureal(1.0, self.sr830, self.df_sr830, label='sr830 '+ repr(yv[i]))  # type B
            yvolt = yvolt + gtc.ureal(0.0, self.cmnmode, self.df_cmnmode, label='common mode '+ repr(yvolt.x))
            ecurrent = (xvolt + 1j * yvolt) / comr[i]  # difference current measured by SR830
            current = shuntv[i] / shunt[i]  # primary =  secondary current
            e_answer =  gtc.result((ecurrent/current), 'my label')  # key intermiediate result? decide later
            e.append(e_answer)
            excite.append(current / full_scale * 100)  # note this is a ureal
            nom_excite.append(
                min(nomexcitation, key=lambda x: abs(x - excite[i].x)))  # finds closest nominal excitation level
        return e, excite, nom_excite
Exemplo n.º 2
0
    def get_correction(self, meas):
        """
        Read calibration parameters from 'Calibrations' table determined by the
        measurement data in meas.

        :param meas: (Measurement obj) - single measurement data.
        :return: (Calibration obj) - Includes GTC.ureals of correction-factor
             and offset, calibration date and report no.
        """
        equip = self.equip_id
        quant = meas.quantity
        date = meas.timestamp

        line = self.readrow_from_calibration_table(equip, quant, 'factor',
                                                   date)
        val_fact = line['Value']
        unc_fact = line['Uncert']
        dof_fact = line['DoF']
        cal_date = line['Date']
        rep_no = line['Report No']
        fact = GTC.ureal(val_fact, unc_fact, dof_fact)

        line = self.readrow_from_calibration_table(equip, quant, 'offset',
                                                   date)
        val_offs = line['Value']
        unc_offs = line['Uncert']
        dof_offs = line['DoF']
        offs = GTC.ureal(val_offs, unc_offs, dof_offs)

        cal = Calibration(date=cal_date,
                          rep_no=rep_no,
                          factor=fact,
                          offset=offs)
        return cal
    def newcapsp(self, ypg, z, r2, z2, uut_ratio):
        """
        Calculates the parallel error minus the series error for a set of primary windings due to the change
        in potential distribution across the distributed capacitance from the primary windings to the screen.
        This version of the formula differs from the original published version. It also caclualtes the series/
        parallel - series error when k=4. This error is set to 0 if k does not equal 4.

        :param ypg: ypg is complex admittance from series primary to primary screen
        :param z: is the leakage impedance of the primary when all the sections are connected in parallel
        :param r2: the secondary burden impedance
        :param z2: leakage impedance of the secondary winding
        :param uut_ratio: [k, m, n] is the ratio windings of the uut
        :return: (parallel-series) error, (series/parallel - series) erro
        """
        k = uut_ratio[0]
        m = uut_ratio[1]
        n = uut_ratio[2]
        s_p_error = ypg / 3 *(k**2 - 1) * ((r2 + z2) * (m/n) ** 2 + z)
        s_p_error = s_p_error * gtc.ureal(1.0, self.sp_cap, self.df_sp_cap, label='sp_cap')  # type B factor

        if k == 4:  # 4 sections in series/parallel possible, note relies on exact integer ... isclose() needed?
            g = 2
            sp_s_error = ypg / 3 * (k ** 2 - g**2) * ((r2 + z2) * (m / n) ** 2 + z)
            sp_s_error = sp_s_error * gtc.ureal(1.0, self.sp_cap, self.df_sp_cap, label='sp_s_cap')  # type B factor
        else:
            sp_s_error =0
        return s_p_error, sp_s_error
    def get_test_result(self, a):
        """
        :param a: first row of test
        :return: list of (ultimately ureals) [complex error 1, complex error 2, resistance]
        """
        # first get relevant resistor
        resistor = self.perturbr[str(
            self.getblock([a + 1, a + 3, 12, 13])[0][0])]
        multiplier = float(self.getblock([a, a + 1, 7, 8])[0][0])

        errors = self.getblock([a, a + 2, 10, 12])
        error1 = self.tuple_to_complex(errors[0])
        u_resolutionR = gtc.ureal(
            0, self.arnie.resolutionR(error1.real, multiplier), 12,
            'resR' + repr(error1.real))
        u_correctionR = gtc.ureal(0, self.arnie.corrnR(error1.real,
                                                       multiplier), 12,
                                  'corrnR' + repr(error1.real))
        u_resolutionM = gtc.ureal(
            0, self.arnie.resolutionM(error1.imag, multiplier), 12,
            'resM' + repr(error1.imag))
        u_correctionM = gtc.ureal(0, self.arnie.corrnM(error1.imag,
                                                       multiplier), 12,
                                  'corrnM' + repr(error1.imag))

        error = error1.real + u_resolutionR + u_correctionR + 1j * (
            error1.imag + u_resolutionM + u_correctionM)
        error1 = error

        error2 = self.tuple_to_complex(errors[1])
        u_resolutionR = gtc.ureal(
            0, self.arnie.resolutionR(error2.real, multiplier), 12,
            'resR' + repr(error2.real))
        u_correctionR = gtc.ureal(0, self.arnie.corrnR(error2.real,
                                                       multiplier), 12,
                                  'corrnR' + repr(error2.real))
        u_resolutionM = gtc.ureal(
            0, self.arnie.resolutionM(error2.imag, multiplier), 12,
            'resM' + repr(error2.imag))
        u_correctionM = gtc.ureal(0, self.arnie.corrnM(error2.imag,
                                                       multiplier), 12,
                                  'corrnM' + repr(error2.imag))

        error = error2.real + u_resolutionR + u_correctionR + 1j * (
            error2.imag + u_resolutionM + u_correctionM)
        error2 = error

        the_burden = self.burdenZ(error1, error2, resistor)
        frequency_factor = gtc.ureal(0,
                                     self.maxfreq / 3.0,
                                     50,
                                     label='frequency')
        the_burden = the_burden + 1j * the_burden.imag * frequency_factor  # the addition is nominally zero

        return the_burden
Exemplo n.º 5
0
    def get_test_result(self, a):
        """
        :param a: first row of test
        :return: list of (ultimately ureals) [complex error 1, complex error 2, resistance]
        """
        # first get relevant resistor
        resistor = float(self.data_store.getdata_block(self.datasheet, [a +1, a + 3 , 12, 13])[0][0])
        multiplier = float(self.data_store.getdata_block(self.datasheet, [a , a + 1 , 7, 8])[0][0])

        errors = self.data_store.getdata_block(self.datasheet, [a , a + 2 , 10, 12])
        error1 = self.tuple_to_complex(errors[0])
        u_resolutionR = gtc.ureal(0,self.arnie.resolutionR(error1.real, multiplier), 12, 'resR' + repr(error1.real))
        u_correctionR = gtc.ureal(0, self.arnie.corrnR(error1.real, multiplier), 12, 'corrnR' + repr(error1.real))
        u_resolutionM = gtc.ureal(0,self.arnie.resolutionM(error1.imag, multiplier), 12, 'resM' + repr(error1.imag))
        u_correctionM = gtc.ureal(0,self.arnie.corrnM(error1.imag, multiplier), 12, 'corrnM' + repr(error1.imag))

        error = error1.real + u_resolutionR + u_correctionR + 1j*(error1.imag + u_resolutionM + u_correctionM )
        error1 = error

        error2 = self.tuple_to_complex(errors[1])
        u_resolutionR = gtc.ureal(0, self.arnie.resolutionR(error2.real, multiplier), 12, 'resR' + repr(error2.real))
        u_correctionR = gtc.ureal(0, self.arnie.corrnR(error2.real, multiplier), 12, 'corrnR' + repr(error2.real))
        u_resolutionM = gtc.ureal(0, self.arnie.resolutionM(error2.imag, multiplier), 12, 'resM' + repr(error2.imag))
        u_correctionM = gtc.ureal(0, self.arnie.corrnM(error2.imag, multiplier), 12, 'corrnM' + repr(error2.imag))

        error = error2.real + u_resolutionR + u_correctionR + 1j * (error2.imag + u_resolutionM + u_correctionM)
        error2 = error

        the_burden = self.burdenZ(error1, error2, resistor)
        return the_burden
    def fit_ureals(self, coeffs, cov, dof, label):
        """
        Takes the coefficients, *coeffs*, and covariances, *cov*, together with
        degrees of freedom, *dof*, in the array output from *fit*  and returns a
        list of function coefficients as correlated GTC ureals.  The ureal is
        named with *label*.  If one of the uncertainties is zero, a set of unlinked
        ureals is created. This should only occur if a transformer has had all
        errors set to zero (e.g. no VT) or the input data has been fabricated to
        be a perfect fit.
        """
        uncert = []
        for i in range(len(coeffs)):
            uncert.append(np.sqrt(cov[i, i]))
        flag = 1 #assume no zero uncertainties
        for x in uncert:
            if x == 0.0:
                flag = 0
        if flag == 1:
            a = gtc.multiple_ureal(coeffs, uncert, dof, label)
            # and now set the correlations between all coefficients
            for i in range(len(coeffs)):
                for j in range(i):
                    gtc.set_correlation(cov[i, j]/np.sqrt(cov[i, i]*cov[j, j]), a[j], a[i])

        else: #have a zero uncertainty so create separate ureals
            print 'A fit has returned zero uncertainty for a function coefficient.  This should only occur if input data has been purposely set to a perfect fit.'
            a = []
            for i in range(len(coeffs)):
                a.append(gtc.ureal(coeffs[i], uncert[i], dof, label[i]))
        return a
    def magnetic_coupling(self, block1, block2, uut_ratio, Rs, rls, target_i2, individual):
        """
        Calculates the series error - parallel error for a set of primary windings.
        This method processes the data and calls on internal methods ishare, couple and magneticsp

        :param block1: the data block for calculating current sharing
        :param block2: the data block with coupling measurements
        :param uut_ratio: [k, m, n] ratio windings of the uut
        :param Rs:  secondary burden resistance
        :param rls:  secondary leakage impedance
        :param target_i2:  the i2 value used to normalise the volt drops, usually 1, i.e. 5 A through 0.2 ohm
        :param individual:  boolean when set to True the vdrops are measured across each individual winding
        :return: same as magneticsp, a complex error with no scaling
        """

        N = uut_ratio[2]/(uut_ratio[0] * uut_ratio[1])  # the ratio in series connection
        vdrop = []  # measured volt drop
        i2 = []  # measured secondary current voltage
        for x in block1:
            vdrop.append(x[2])
            i2.append(x[0])
        proportions = self.ishare(uut_ratio, Rs, rls, vdrop, i2, 1, individual)
        # data is label, shunt volts, X V, Y V, Sh V sd/100, X stdev V, Y stdev V, CT ratio, Shunt, Com R
        # k = len(block2) + 1  # one fewer measurements than sections
        # create lists of data
        shuntv = []  # gtc values
        xv = []  # gtc values
        yv = []  # gtc values
        ctratio = []  # duplicates of a constant?
        shunt = []  # secondary shunt duplicates of a fixed value
        comr = []  # common resistance duplicates of a fixed value

        for x in block2:
            shuntv.append(gtc.ureal(x[1], x[4], 100, label='shuntv ' + repr(x[0])))
            xv.append(gtc.ureal(x[2], x[5], 100, label='X V ' + repr(x[0])))
            yv.append(gtc.ureal(x[3], x[6], 100, label='Y V ' + repr(x[0])))
            ctratio.append(x[7])
            shunt.append(x[8])
            comr.append(x[9])

        # calculation of coupling
        coupling = self.couple(shuntv, xv, yv, ctratio, shunt, comr, uut_ratio)
        return self.magneticsp(coupling, proportions, uut_ratio)
    def magneticsp(self, couple, share, uut_ratio):
        """
        Calculates the series error minus the parallel error for a set of primary windings due to magnetic
        coupling differences between the windings. Note that the way coupling was measured forces the first couple
        element to be zero.

        :param couple: list of k-1 mutual couplings for k primary windings
        :param share: list of fractional share of current for k primary windings in parallel
        :param uut_ratio: list [k, m, n] of windings for transformer
        :return: two complex errors, no scaling to % or ppm
        """

        assert len(share) - len(couple) == 1, "sharing list should be one longer than coupling list"
        k = len(share)
        N = uut_ratio[2]/(uut_ratio[0] * uut_ratio[1])
        if k == 4:  # series/parallel available on Ta primaries
            x = (2-(share[0]+share[1]))/2  # x is offset required to make first two add to 2.0
            y = (2-(share[2]+share[3]))/2  # y is offset required to make last two add to 2.0
            sp_share = []
            sp_share.append(share[0] + x)
            sp_share.append(share[1] + x)
            sp_share.append(share[2] + y)
            sp_share.append(share[3] + y)

            sp_merror = 0  # summation for the serie/parallel magnetic error
            for i in range(1, k):  # the first element of share would have been multiplied by zero, so not needed
                sp_merror = couple[i - 1] * (sp_share[i]-1) + sp_merror
            sp_merror = N * sp_merror  # the sign of this is as derived in section A3 of E056.005, relies on aj defn
            sp_merror = sp_merror * gtc.ureal(1.0, self.sp_mag, self.df_sp_mag, label='s_sp_mag')  # type B factor
        else:
            sp_merror = 0  #i.e. there is no series/paralle connection

        merror = 0
        for i in range(1, k):  # the first element of share would have been multiplied by zero, so not needed
            merror = couple[i - 1] * (share[i] - 1) + merror
        merror = N * merror  #the sign of this is as derived in section A3 of E056.005 and depends on aj measurement
        merror = merror * gtc.ureal(1.0, self.sp_mag, self.df_sp_mag, label='sp_mag')  # type B factor

        return merror, sp_merror
    def oldcapsp(self, ypg, k, z4, r2, z2, uut_ratio):
        """
        Calculates the series error minus the parallel error for a set of primary windings due to the change
        in potential distribution on the capacitance from the windings to screen. INCORRECT old formula.

        :param ypg: ypg is complex admittance from series primary to primary screen
        :param k: the number of sections connected in series
        :param z4: the leakage impedance of the primary winding
        :param r2: the secondary burden impedance
        :param z2: leakage impedance of the secondary winding
        :param uut_ratio: [k, n, m] transformer ratio
        :return: error; should be a GTC ucomplex if inputs are experimental values
        """

        n = uut_ratio[2]/(uut_ratio[0] * uut_ratio[1])
        s_p_error = ypg / 6 * 1 / (k ** 2 - 1) * (z4 + (r2 + z2) / n ** 2)
        s_p_error = s_p_error * gtc.ureal(1.0, self.sp_cap, self.df_sp_cap, label = 'sp_cap')  # type B factor
        return s_p_error
Exemplo n.º 10
0
def urealext(value_list, unc_list=0.0, k=2, array_label='X', df=GTC.inf):
    # INPUT variables:
    # for value_list are:
    #       <class 'list'>
    #       <class 'numpy.ndarray'>
    #       <class 'int'>
    #       <class 'float'>
    # for unc_list are:
    #       <class 'list'>
    #       <class 'numpy.ndarray'>
    #       <class 'int'>
    #       <class 'float'>
    # for k are:
    #       <class 'int'>
    #       <class 'float'>
    # for value_name are:
    #       <class 'string'>

    if isinstance(value_list, int) or isinstance(value_list, float):  # check if list is single value
        value_list = [[value_list]]
        n_rows = 1
        n_cols = 1
    else:
        # find size of value_list
        n_rows = len(value_list)
        n_cols = len(value_list[0])

    if df == 'N':
        df = n_rows * n_cols - 1

    realnumber_list = [[0 for x in range(n_cols)] for x in range(n_rows)]

    for i in range(n_rows):
        for j in range(n_cols):
            label = array_label + str(i) + '_' + str(j)
            if isinstance(unc_list, int) or isinstance(unc_list, float):
                unc_std = unc_list / k
            else:
                unc_std = unc_list[i][j] / k
            realnumber_list[i][j] = GTC.ureal(x=value_list[i][j], u=unc_std, label=label, df=df)
    unc_array = GTC.la.uarray(realnumber_list)

    return unc_array
    def ctcompare(self, datablock, fullscale, targetexcitation, settings):
        """
        Takes a set of CT error measurements as a block and returns the calculated ratio errors. Older spread sheets
        did not include gain and reserve settings for the SR830, hence the boolean settings

        :param datablock: shunt Volts, X V, Y V, Sh V sd/100, X stdev V, Y stdev, blank, Shunt, Gain, Reserve, Com R.
        :param fullscale: the value of current, A, that equates to 100% excitation
        :param targetexcitation: the set of nominal % excitation levels at which measurements were made
        :param settings: a boolean set to True if gain and reserve colunmns available
        :return: a list of errors, a list of actual excitation levels and a list of the matching nominal excitations
        """

        assert settings in [True, False], "settings must be True for range and gain information, otherwise False"
        shuntv = []  # gtc values
        xv = []  # gtc values
        yv = []  # gtc values
        shunt = []  # secondary shunt duplicates of a fixed value
        gain = []  # SR830 range
        reserve = []  # reserve, 1 for on?
        comr = []  # common resistance, list will likely be duplicates of a fixed value

        for x in datablock:
            if settings == False:
                shunt.append(x[7])
                comr.append(x[8])
                shuntv.append(
                    gtc.ureal(x[0], x[3], 100, label='shuntv ' + str(x[0] / x[7] / fullscale)))  # use current as label
                xv.append(gtc.ureal(x[1], x[4], 100, label='X V ' + str(x[0] / x[7] / fullscale)))
                yv.append(gtc.ureal(x[2], x[5], 100, label='Y V ' + str(x[0] / x[7] / fullscale)))
            elif settings == True:
                gain.append(x[6])
                reserve.append(x[7])
                shunt.append(x[8])
                comr.append(x[9])
                shuntv.append(
                    gtc.ureal(x[0], x[3], 100, label='shuntv ' + str(x[0] / x[8] / fullscale)))  # use current as label
                xv.append(gtc.ureal(x[1], x[4], 100, label='X V ' + str(x[0] / x[8] / fullscale)))
                yv.append(gtc.ureal(x[2], x[5], 100, label='Y V ' + str(x[0] / x[8] / fullscale)))

        e, excite, nom_excite = self.ratioerror(shuntv, xv, yv, shunt, comr, targetexcitation, fullscale)
        return e, excite, nom_excite
Exemplo n.º 12
0
def isGTC(value):
    typeGTC = type(GTC.ureal(0, 0))
    if type(value) == typeGTC:
        return True
    else:
        return False
Exemplo n.º 13
0
def float2GTC(value):
    if isGTC(value):
        return value
    else:
        return GTC.ureal(value, 0)
Exemplo n.º 14
0
import GTC as gtc
x = gtc.ureal(0.0, 0.1, 5)
y = gtc.ureal(0.0, 0.2, 10)
a = x * y
print(a.u)
b = gtc.function.mul2(x, y)
print(b)

ab = gtc.result(a * b, label='result')
print(ab.label, ab)
Exemplo n.º 15
0
        max_sd = 0.00007754
        return sd * reading

    def auxP(self, reading):
        """
        uncertainty in the correction factor for auxiliary phase
        """
        max_sd = 0.0003270
        return sd * reading


if __name__ == "__main__":
    print 'Testing that the module works as intended.'
    arnie = ARNOLD('a', 'b')
    #in GTC terms we add the corrections
    res_corrn_e = GTC.ureal(0, arnie.resolutionR(-0.682, 1), 5,
                            'swire_resolution').u
    scale_corrn_e = GTC.ureal(0, arnie.corrnR(-0.682, 1), 5,
                              'swire_correction').u
    res_corrn_p = GTC.ureal(0, arnie.resolutionM(0.032, 0.1), 5,
                            'mutual_resolution').u
    scale_corrn_p = GTC.ureal(0, arnie.corrnM(0.032, 0.1), 5,
                              'mutual_correction').u

    print res_corrn_e, '%'
    print scale_corrn_e, '%'
    print res_corrn_p, 'crad'
    print scale_corrn_p, 'crad'
"""
>pythonw -u "arnold.py"
Testing that the module works as intended.
0.001 %
coeff=GTC.la.matmul(invA,B)
print('\ncoeff=',coeff)

a=coeff[0][0]
b=coeff[1][0]
c=coeff[2][0]

print('\nCalculated coefficients:\n')
print('a coeff=',a.x,'u=',a.u)
print('b coeff=',b.x,'u=',b.u)
print('c coeff=',c.x,'u=',c.u)

#### STEP 3-   TEMPERATURE CALCULATION FROM RESISTANCE MEASURED
#resistancec from measurement

R0=GTC.ureal(100,0.000002,label='R0') #Triple point of water resistance
Ri=[102,189,300] # measured resistances
R=GTCext.urealext(value_list=Ri, unc_list=0.0005, k=2, array_label='R', df=GTC.inf)
print('\nR0=',R0)
print('\nR=',R)
Wt=R/R0 # calculating reference function for measured resistances
print('\nW(t)=',Wt)



Wt1=GTCext.python_list_transposition(Wt-1)

pow2=lambda
#Wt2=GTC.pow(Wt1,2)
#Wt3=GTC.pow(Wt1,3)
Exemplo n.º 17
0
        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)
    GTC.set_correlation(0.303221134084321, a5, a6)
    
    this_core_gtc = [a1,a2,a3,a4,a5,a6]
    this_CT_gtc = modelCT.CT(this_core_gtc)
Exemplo n.º 18
0
            this_error.append(complex_error.real*100)
            this_phase.append(complex_error.imag*100)
        print this_error
        print this_phase
        line1 = plt.plot(x_axis,this_error)
        line2 = plt.plot(x_axis,this_phase)
        plt.show()



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)
Exemplo n.º 19
0
import ITS90 as ITS
import GTC
import GTCext
import numpy as np

#definition od SPRT object
term1 = ITS.PRT(model='5685', numer='1114')

#example values of T and W
T = GTC.ureal(29.764663066392302, 0.005, label='temp')
W = GTC.ureal(1.11813889, 1.982113655829038e-05, label='W')

print(ITS.Conv_kelvin2celsius(T))
ITS.Calculate_Wr(T, verbose=True)
ITS.Calculate_temp_from_W(W, verbose=True)

value_list = [[1, 2, 3, 4], [5, 6, 7, 8]]
#value_list=1

#unc_list=[[0.1,0.2,0.3,0.4],[0.01,0.02,0.03,0.04]] #osobna niepwenośc dla każdej wartości
unc_list = 0.1  # jedna niepewnośc dla wszystkich wartości

value_list = np.array(value_list)
unc_array = GTCext.urealext(value_list, unc_list, k=2, array_label='temp')

print('value_list=\n', value_list)
print('unc_list=\n', unc_list)
print('unc_array=\n',
      unc_array)  # tutaj jest wytworzona macierz liczb z niepewnoscią
print('sin(unc_array)=\n', GTC.sin(unc_array))  #tutaj można zrobic ich sinus
    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
    }  # dictionary of values of perturbing resistors
    # analyse data from Excel sheet
    myburden = BURDEN('S22008_py_Burden_5AmpRatio Template V5.0_draft.xlsm',
                      'ForPython', [1, 128, 1, 17], check_r)
    mydata = myburden.datalist
    print('starting run')
    test_sets = [
        4, 6, 11, 13, 18, 25, 27, 32, 34, 39, 41, 46, 48, 53, 55, 60, 62, 67,
        69, 74, 76, 81, 83, 88, 90, 95, 97, 102, 104, 109, 111, 116, 118, 123,
        125
Exemplo n.º 21
0
    def analysis(self):
        """
        Main analysis function. Reads averages and standard deviations to create GTC,ureal objects, by using the find_center function to determine starting and end points of a set.
        These are first sent to the split_set function to be seperated out for the different instruments, then each segment is sent to a ratio computation function which
        returns the gain ratio and lineariy ratio for that set.
        """
        end_point = float(self.read_cell(3, 3))
        continue_analysis = True  #flag for continuing to read through the data table
        start_row = int(float(self.read_cell(
            3, 1))) - 1  #wx starts at zero, initial starting row

        while continue_analysis == True:
            center, last_row = self.find_center(start_row)
            print(start_row, center, last_row)
            if last_row > len(
                    self.data
            ):  #last row is outside the table, last set is incomplete or not there at all
                print("last set not found")
                continue_analysis = False
            else:
                S_settings = [
                    float(self.read_cell(i, self.S_setting_col))
                    for i in range(start_row, last_row + 1)
                ]
                X_settings = [
                    float(self.read_cell(i, self.X_setting_col))
                    for i in range(start_row, last_row + 1)
                ]

                GTC_list = [
                    GTC.ureal(float(self.read_cell(row, self.mean_col)),
                              float(self.read_cell(row, self.std_col)),
                              float(self.read_cell(row, self.DoF_col)) - 1)
                    for row in range(start_row, last_row + 1)
                ]

                #get split up segments, then compute ratios individually and print then repeat.
                m_top, m_bottom, x_top, x_bottom, s0, s1 = self.split_set(
                    GTC_list, S_settings)

                x_ratios = self.x_ratio(x_top, s0, s1) + self.x_ratio(
                    x_bottom[::-1], s0, s1)
                m_ratios = self.m_ratio(m_top, s0, s1) + self.m_ratio(
                    m_bottom[::-1], s0, s1
                )  #join arrays of the three ratios, linearity, gain, fit ??

                ratios = x_ratios + m_ratios

                print("m ratios" + str([x.x for x in m_ratios]))
                print("x ratios" + str([x.x for x in x_ratios]))

                #print the ratios to the sheet
                self.PrintCol([x.label for x in ratios], start_row + 1,
                              self.mean_col + 5, self.sh_results)
                self.PrintCol(["Ratio"] + [x.x for x in ratios], start_row,
                              self.mean_col + 6, self.sh_results)
                self.PrintCol(["STDEV"] + [x.u for x in ratios], start_row,
                              self.mean_col + 7, self.sh_results)
                self.PrintCol(["Effct. DoF"] + [x.df for x in ratios],
                              start_row, self.mean_col + 8, self.sh_results)

                #check if there is a next section:
                if last_row >= float(self.read_cell(3, 3)) - 1:
                    continue_analysis = False

                else:
                    start_row = last_row + 1
    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
Exemplo n.º 23
0
    def analysis(self):

        """
        Main analysis function. Reads averages and standard deviations to create GTC,ureal objects, by using the find_center function to determine starting and end points of a set.
        These are first sent to the split_set function to be seperated out for the different instruments, then each segment is sent to a ratio computation function which
        returns the gain ratio and lineariy ratio for that set. Additionally the ratios are converted to parts per million and stored in a separate location. 
        """

        if self.wb == None:
            return
        
        end_point = float(self.read_cell(3,3))
        continue_analysis = True #flag for continuing to read through the data table
        start_row = int(float(self.read_cell(3,1)))-1 #wx starts at zero, initial starting row

        printing_row = 1 #The first row to start printing columns to.
        
        while continue_analysis ==True:
            center,last_row = self.find_center(start_row)
            print(start_row,center,last_row)
            if last_row>len(self.data): #last row is outside the table, last set is incomplete or not there at all
                print("last set not found")
                continue_analysis = False
            else:
                cols = []
                
                S_settings = [float(self.read_cell(i,self.S_setting_col)) for i in range(start_row,last_row+1)]
                X_settings = [float(self.read_cell(i,self.X_setting_col)) for i in range(start_row,last_row+1)]

                GTC_list = [GTC.ureal(float(self.read_cell(row,self.mean_col)),float(self.read_cell(row,self.std_col)),float(self.read_cell(row,self.DoF_col))-1) for row in range(start_row,last_row+1)]
                
                #get split up segments, then compute ratios individually and print then repeat.
                m_top,m_bottom,x_top,x_bottom,s0,s1 = self.split_set(GTC_list,S_settings)
                
                x_ratios = self.x_ratio(x_top,s0,s1)+self.x_ratio(x_bottom[::-1],s0,s1)
                m_ratios = self.m_ratio(m_top,s0,s1)+self.m_ratio(m_bottom[::-1],s0,s1)

                #join arrays of the three ratios, linearity, gain, fit ??
                x_ranges = self.x_range(center)+self.x_range(center)
                m_ranges = self.m_range(center)+self.m_range(center)
                
                x_readouts = [self.read_cell(center,2)] + [self.read_cell(center,2)]+ [self.read_cell(center,2)]+ [self.read_cell(center,2)]
                m_readouts = [self.read_cell(center,2)] + [self.read_cell(center,2)]+ [self.read_cell(center,2)]+ [self.read_cell(center,2)]                
                step_size = [float(self.read_cell(center,4))+float(self.read_cell(center+1,4))]+[float(self.read_cell(center,4))+float(self.read_cell(center+1,4))]+[float(self.read_cell(center,4))+float(self.read_cell(center+1,4))]+[float(self.read_cell(center,4))+float(self.read_cell(center+1,4))]

                ratios = x_ratios+m_ratios
                ranges = x_ranges+m_ranges
                readouts = x_readouts + m_readouts
                step_sizes = step_size+step_size
                #print the ratios to the sheet
                cols.append(["Label"]+[x.label for x in ratios])
                cols.append(["Ratio"]+[x.x for x in ratios])
                cols.append(["STDEV"]+[x.u for x in ratios])
                cols.append(["Effct. DoF"]+[x.df for x in ratios])
                cols.append(["Range"]+[x for x in ranges]) 
                cols.append(["Max/Min V Setting"] + [x for x in readouts])
                cols.append(["Step Size"]+[x for x in step_sizes])                
                
                self.print_cols(cols,printing_row,self.sh_results)
                printing_row += len(ratios) + 1
                self.results.append(cols)
                #check if there is a next section:
                if last_row>=float(self.read_cell(3,3))-1:
                    continue_analysis = False

                else:
                    start_row = last_row+1
        continue_analysis_ratios = True
        while continue_analysis_ratios == True:
            sets = int(0.5*len(self.results))
            rows = []
            rows.append(["Source Gain Ratios"]+["Positive"]+['']+["Negative"])
            rows.append(["Range"]+["Mean(ppm)"]+["Std Dev(ppm)"]+["Mean(ppm)"]+["Std Dev(ppm)"])
            
                         
            
            # Generate Gain Ratios in correct form using calculated ratios for the Source 
            for i in range(0, sets):
                mean_posi = (abs(self.results[2*i][1][2]) - 1 + abs(self.results[2*i][1][4])-1)/2 * 1000000
                std_dev_posi = (self.results[2*i][2][2] + self.results[2*i][2][4])/2 * 1000000
                mean_neg = (abs(self.results[2*i+1][1][2]) - 1 + abs(self.results[2*i+1][1][4])-1)/2 * 1000000
                std_dev_neg = (self.results[2*i+1][2][2] + self.results[2*i+1][2][4])/2 * 1000000
                g_ratio = str(float(self.results[2*i][5][2]))+" : "+str(float(self.results[2*i][6][2]))  
                
                rows.append([g_ratio]+[mean_posi]+[std_dev_posi]+[mean_neg]+[std_dev_neg])
                
                # x2 and x2+1
            
            rows.append([" "])
            rows.append(["Meter Gain Ratios"]+["Positive"]+['']+["Negative"])
            rows.append(["Range"]+["Mean(ppm)"]+["Std Dev(ppm)"]+["Mean(ppm)"]+["Std Dev(ppm)"])
            
                         
            # Generate Gain Ratios in correct form using calculated ratios for the Meter 
            for i in range(0, sets):
                mean_posi = (abs(self.results[2*i][1][6]) - 1 + abs(self.results[2*i][1][8])-1)/2 * 1000000
                std_dev_posi = (self.results[2*i][2][6] + self.results[2*i][2][8])/2 * 1000000
                mean_neg = (abs(self.results[2*i+1][1][6]) - 1 + abs(self.results[2*i+1][1][8])-1)/2 * 1000000
                std_dev_neg = (self.results[2*i+1][2][6] + self.results[2*i+1][2][8])/2 * 1000000
                g_ratio = str(float(self.results[2*i][5][6]))+" : "+str(float(self.results[2*i][6][6]))  
                
                rows.append([g_ratio]+[mean_posi]+[std_dev_posi]+[mean_neg]+[std_dev_neg])

                                
            lin_ratios = []
            lin_ratios.append(["Source Linearity Ratios"]+["Positive"]+['']+["Negative"])
            lin_ratios.append(["Range"]+["Mean(ppm)"]+["Std Dev(ppm)"]+["Mean(ppm)"]+["Std Dev(ppm)"])
            
            
            for i in range(0, sets):
                mean_posi = (abs(self.results[2*i][1][2]) - 1 + abs(self.results[2*i][1][4])-1)/2 * 1000000
                std_dev_posi = (self.results[2*i][2][2] + self.results[2*i][2][4])/2 * 1000000
                mean_neg = (abs(self.results[2*i+1][1][2]) - 1 + abs(self.results[2*i+1][1][4])-1)/2 * 1000000
                std_dev_neg = (self.results[2*i+1][2][2] + self.results[2*i+1][2][4])/2 * 1000000
                g_ratio = str(float(self.results[2*i][5][2]))+" : "+str(float(self.results[2*i][6][2]))  
                
                lin_ratios.append([g_ratio]+[mean_posi]+[std_dev_posi]+[mean_neg]+[std_dev_neg])
                
                # x2 and x2+1
            
            lin_ratios.append([" "])
            lin_ratios.append(["Meter Linearity Ratios"]+["Positive"]+['']+["Negative"])
            lin_ratios.append(["Range"]+["Mean(ppm)"]+["Std Dev(ppm)"]+["Mean(ppm)"]+["Std Dev(ppm)"])
            
                         
            # Generate Gain Ratios in correct form using calculated ratios for the Meter 
            for i in range(0, sets):
                mean_posi = (abs(self.results[2*i][1][6]) - 1 + abs(self.results[2*i][1][8])-1)/2 * 1000000
                std_dev_posi = (self.results[2*i][2][6] + self.results[2*i][2][8])/2 * 1000000
                mean_neg = (abs(self.results[2*i+1][1][6]) - 1 + abs(self.results[2*i+1][1][8])-1)/2 * 1000000
                std_dev_neg = (self.results[2*i+1][2][6] + self.results[2*i+1][2][8])/2 * 1000000
                g_ratio = str(float(self.results[2*i][5][6]))+" : "+str(float(self.results[2*i][6][6]))  
                
                lin_ratios.append([g_ratio]+[mean_posi]+[std_dev_posi]+[mean_neg]+[std_dev_neg])

            
                # x2 and x2+1
                
            self.gain_ratios.append(rows)
            self.print_rows(rows,1,self.sh_gain_ratios)
            self.print_rows(lin_ratios,1,self.sh_lin_ratios)
            continue_analysis_ratios = False
        """
        A GTC calculated ureal *target* has its uncertainty reported against
        lists of labels in *labels*. Labels identify uncertainty inputs to
        target.  This facilitates reporting of uncertainties due to separate
        metering components.  There is no error checking so the onus is entirely
        on the programmer to choose relevant lists of labels for parameters.  A
        list of summed variance by label group is returned.
        """
        n = len(labels)# expect a list of lists
        total = []
        for i in range(n):
            total.append(0.0) # the uncertainty for each list will be summed
        for l, u in gtc.reporting.budget(target, trim = 0.0):
            for i in range(n):
                if l in labels[i]:
                    total[i] = total[i] + u**2
        return total




if __name__ == "__main__":
    print 'Testing components'
    model = MODEL('tran') # contains all fitting functions
    print model.line([1, 2], [3, 4])

    alpha = gtc.ureal(0.0e-6, 1.0e-6, 9)
    t = gtc.ureal(20.0, 0.5, 9)
    t0 = 20.0
    print model.influence1(t, t0, alpha).u