Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I needed to do something similar before. To avoid repeating the effort, I made a big function that can extract all things that can be extracted for 3-winding transformer windings. Be aware that the APIs in PSSE for 3-winding transformer and 3-winding transformer windings are different.

# 3-Winding Transformer Winding data
# this dictionary is sourced from PSSE's API doct, and there are
# descriptions that even I do not understand
CONST_DICT_3WTRF_WND_HEADER = {# int
                                'WNDBUSNUMBER'  : ['WNDBUSNUMBER',  'Number of the bus connected to this winding'],
                                'OTHER1NUMBER'  : ['OTHER1NUMBER',  'Number of another bus connected to this transformer'],
                                'OTHER2NUMBER'  : ['OTHER2NUMBER',  'Number of another bus connected to this transformer'],
                                'WNDNUM'        : ['WNDNUM',        'Winding number'],
                                'WIND1NUMBER'   : ['WIND1NUMBER',   'Winding 1 bus number'],
                                'WIND2NUMBER'   : ['WIND2NUMBER',   'Winding 2 bus number'],
                                'WIND3NUMBER'   : ['WIND3NUMBER',   'Winding 3 bus number'],
                                'NMETERNUMBER'  : ['NMETERNUMBER',  'Non-metered end bus number'],
                                'STATUS'        : ['STATUS',        'Winding status'],
                                'OWNERS'        : ['OWNERS',        'Number of owners'],
                                'OWN1'          : ['OWN1',          'First owner'],
                                'OWN2'          : ['OWN2',          'Second owner'],
                                'OWN3'          : ['OWN3',          'Third owner'],
                                'OWN4'          : ['OWN4',          'Fourth owner'],
                                'ICONTNUMBER'   : ['ICONTNUMBER',   'Controlled bus number'],
                                'TABLE'         : ['TABLE',         'Transformer impedance adjustment table number'],
                                'CODE'          : ['CODE',          'Transformer control mode for automatic adjustments'],
                                'NTPOSN'        : ['NTPOSN',        'Number of tap positions'],
                                'CW'            : ['CW',            'Winding data I/O code'],
                                'CZ'            : ['CZ',            'Impedance data I/O code'],
                                'CM'            : ['CM',            'Magnetizing admittance I/O code'],
                                'CZ0'           : ['CZ0',           'Leakage impedance data I/O code'],
                                'CZG'           : ['CZG',           'Grounding impedance data I/O code'],
                                'CNXCOD'        : ['CNXCOD',        'Connection code'],
                                'TPSTT'         : ['TPSTT',         'Winding 1 ratio limit code: -1 for low; 0 for regulating; 1 for high; -2 for locked'],
                                'ANSTT'         : ['ANSTT',         'Winding 1 angle limit code: -1 for low; 0 for regulating; 1 for high; -2 for locked'],

                                # float
                                'AMPS'          : ['AMPS',          'Branch current in amps (0.0 if bus base voltage is 0.0)'],
                                'PUCUR'         : ['PUCUR',         'Branch current in pu'],
                                'PCTRATE'       : ['PCTRATE',       'Percent winding bus current of default rating set'],
                                'PCTRATEA'      : ['PCTRATEA',      'Percent winding bus current of rating set A'],
                                'PCTRATEB'      : ['PCTRATEB',      'Percent winding bus current of rating set B'],
                                'PCTRATEC'      : ['PCTRATEC',      'Percent winding bus current of rating set C'],
                                'PCTMVARATE'    : ['PCTMVARATE',    'Percent winding bus MVA of default rating set'],
                                'PCTMVARATEA'   : ['PCTMVARATEA',   'Percent winding bus MVA of rating set A'],
                                'PCTMVARATEB'   : ['PCTMVARATEB',   'Percent winding bus MVA of rating set B'],
                                'PCTMVARATEC'   : ['PCTMVARATEC',   'Percent winding bus MVA of rating set C'],
                                'PCTCORPRATE'   : ['PCTCORPRATE',   'Percent winding bus current or MVA loading (according to the transformer percent loading units program option setting) of default rating set'],
                                'PCTCORPRATEA'  : ['PCTCORPRATEA',  'Percent winding bus current or MVA loading (according to the transformer percent loading units program option setting) of rating set A'],
                                'PCTCORPRATEB'  : ['PCTCORPRATEB',  'Percent winding bus current or MVA loading (according to the transformer percent loading units program option setting) of rating set B'],
                                'PCTCORPRATEC'  : ['PCTCORPRATEC',  'Percent winding bus current or MVA loading (according to the transformer percent loading units program option setting) of rating set C'],
                                'MAXPCTRATE'    : ['MAXPCTRATE',    'Larger of percent winding/star point bus current of default rating set'],
                                'MAXPCTRATEA'   : ['MAXPCTRATEA',   'Larger of percent winding/star point bus current of rating set A'],
                                'MAXPCTRATEB'   : ['MAXPCTRATEB',   'Larger of percent winding/star point bus current of rating set B'],
                                'MAXPCTRATEC'   : ['MAXPCTRATEC',   'Larger of percent winding/star point bus current of rating set C'],
                                'MXPCTMVARAT'   : ['MXPCTMVARAT',   'Larger of percent winding/star point bus MVA of default rating set'],
                                'MXPCTMVARATA'  : ['MXPCTMVARATA',  'Larger of percent winding/star point bus MVA of rating set A'],
                                'MXPCTMVARATB'  : ['MXPCTMVARATB',  'Larger of percent winding/star point bus MVA of rating set B'],
                                'MXPCTMVARATC'  : ['MXPCTMVARATC',  'Larger of percent winding/star point bus MVA of rating set C'],
                                'MXPCTCRPRAT'   : ['MXPCTCRPRAT',   'Larger of percent winding/star point bus current or MVA loading (according to the transformer percent loading units program option setting) of default rating set'],
                                'MXPCTCRPRATA'  : ['MXPCTCRPRATA',  'Larger of percent winding/star point bus current or MVA loading (according to the transformer percent loading units program option setting) of rating set A'],
                                'MXPCTCRPRATB'  : ['MXPCTCRPRATB',  'Larger of percent winding/star point bus current or MVA loading (according to the transformer percent loading units program option setting) of rating set B'],
                                'MXPCTCRPRATC'  : ['MXPCTCRPRATC',  'Larger of percent winding/star point bus current or MVA loading (according to the transformer percent loading units program option setting) of rating set C'],
                                'FRACT1'        : ['FRACT1',        'First owner fraction'],
                                'FRACT2'        : ['FRACT2',        'Second owner fraction'],
                                'FRACT3'        : ['FRACT3',        'Third owner fraction'],
                                'FRACT4'        : ['FRACT4',        'Fourth owner fraction'],
                                'RATE'          : ['RATE',          'Rating from default rating set'],
                                'RATEA'         : ['RATEA',         'Rating from rating set A'],
                                'RATEB'         : ['RATEB',         'Rating from rating set B'],
                                'RATEC'         : ['RATEC',         'Rating from rating set C'],
                                'RATIO'         : ['RATIO',         'Winding tap ratio in pu'],
                                'RATIOCW'       : ['RATIOCW',       'Winding tap ratio in units governed by CW'],
                                'ANGLE'         : ['ANGLE',         'Winding phase shift angle in degrees'],
                                'RMAX'          : ['RMAX',          'Winding ratio or angle upper limit (in pu if ratio)'],
                                'RMAXCW'        : ['RMAXCW',        'Winding ratio or angle upper limit (in units governed by CW if ratio)'],
                                'RMIN'          : ['RMIN',          'Winding ratio or angle lower limit (in pu if ratio)'],
                                'RMINCW'        : ['RMINCW',        'Winding ratio or angle lower limit (in units governed by CW if ratio)'],
                                'VMAX'          : ['VMAX',          'Controlled quantity upper limit (in pu if voltage)'],
                                'VMAXKV'        : ['VMAXKV',        'Controlled quantity upper limit (in units governed by CW if voltage)'],
                                'VMIN'          : ['VMIN',          'Controlled quantity lower limit (in pu if voltage)'],
                                'VMINKV'        : ['VMINKV',        'Controlled quantity lower limit (in units governed by CW if voltage)'],
                                'STEP'          : ['STEP',          'Winding ratio or angle step width (in pu if ratio)'],
                                'STEPCW'        : ['STEPCW',        'Winding ratio or angle step width (in units governed by CW if ratio)'],
                                'NOMV'          : ['NOMV',          'Winding nominal voltage in kv (0.0 for bus base voltage)'],
                                'SBASE'         : ['SBASE',         'Winding base MVA'],
                                'P'             : ['P',             'Active power flow at winding bus end (MW)'],
                                'Q'             : ['Q',             'Reactive power flow at winding bus end (MVar)'],
                                'MVA'           : ['MVA',           'Apparent power at winding bus end (MVA)'],
                                'MAXMVA'        : ['MAXMVA',        'Apparent power at winding bus or star point bus end, whichever is larger (MVA)'],
                                'PLOSS'         : ['PLOSS',         'Active power losses (MW)'],
                                'QLOSS'         : ['QLOSS',         'Reactive power losses (MVar)'],
                                'O_P'           : ['O_P',           'Active power flow at winding bus end (user unit)'],
                                'O_Q'           : ['O_Q',           'Reactive power flow at winding bus end (user unit)'],
                                'O_MVA'         : ['O_MVA',         'Apparent power at winding bus end (user unit)'],
                                'O_MAXMVA'      : ['O_MAXMVA',      'Apparent power at winding bus or star point bus end, whichever is larger (user unit)'],
                                'O_PLOSS'       : ['O_PLOSS',       'Active power losses (user unit)'],
                                'O_QLOSS'       : ['O_QLOSS',       'Reactive power losses (user unit)'],

                                # complex
                                'RXACT_RE'    : ['RXACT',    'Actual transformer resistance in pu'],
                                'RXACT_IM'    : ['RXACT',    'Actual transformer reactance in pu'],
                                'RXNOM_RE'    : ['RXNOM',    'Nominal transformer resistance in pu'],
                                'RXNOM_IM'    : ['RXNOM',    'Nominal transformer reactance in pu'],
                                'COMPRX_RE'   : ['COMPRX',   'Load drop compensation resistance in pu'],
                                'COMPRX_IM'   : ['COMPRX',   'Load drop compensation reactance in pu'],
                                'RXZERO_RE'   : ['RXZERO',   'Zero sequence winding leakage resistance in pu'],
                                'RXZERO_IM'   : ['RXZERO',   'Zero sequence winding leakage reactance in pu'],
                                'ZGRND_RE'    : ['ZGRND',    'Zero sequence winding grounding resistance in pu'],
                                'ZGRND_IM'    : ['ZGRND',    'Zero sequence winding grounding reactance in pu'],
                                'PQ_RE'       : ['PQ',       'P flow at winding bus end (MW)'],
                                'PQ_IM'       : ['PQ',       'Q flow at winding bus end (MVar)'],
                                'PQLOSS_RE'   : ['PQLOSS',   'P Losses (MW)'],
                                'PQLOSS_IM'   : ['PQLOSS',   'Q Losses (MVar)'],
                                'O_PQ_RE'     : ['O_PQ',     'P flow at winding bus end (user unit)'],
                                'O_PQ_IM'     : ['O_PQ',     'Q flow at winding bus end (user unit)'],
                                'O_PQLOSS_RE' : ['O_PQLOSS', 'Losses (user unit)'],
                                'O_PQLOSS_IM' : ['O_PQLOSS', 'Losses (user unit)'],


                                # string
                                'ID'           : ['ID',           'Circuit identifier'],
                                'WNDBUSNAME'   : ['WNDBUSNAME',   'Name of the bus connected to this winding'],
                                'WNDBUSEXNAME' : ['WNDBUSEXNAME', 'Extended bus name of the bus connected to this winding'],
                                'OTHER1NAME'   : ['OTHER1NAME',   'Name of another bus connected to this winding'],
                                'OTHER1EXNAME' : ['OTHER1EXNAME', 'Extended bus name of another bus connected to this winding'],
                                'OTHER2NAME'   : ['OTHER2NAME',   'Name of another bus connected to this winding'],
                                'OTHER2EXNAME' : ['OTHER2EXNAME', 'Extended bus name of another bus connected to this winding'],
                                'WIND1NAME'    : ['WIND1NAME',    'Winding 1 bus name'],
                                'WIND1EXNAME'  : ['WIND1EXNAME',  'Winding 1 bus extended bus name'],
                                'WIND2NAME'    : ['WIND2NAME',    'Winding 2 bus name'],
                                'WIND2EXNAME'  : ['WIND2EXNAME',  'Winding 2 bus extended bus name'],
                                'WIND3NAME'    : ['WIND3NAME',    'Winding 3 bus name'],
                                'WIND3EXNAME'  : ['WIND3EXNAME',  'Winding 3 bus extended bus name'],
                                'NMETERNAME'   : ['NMETERNAME',   'Non-metered bus name'],
                                'NMETEREXNAME' : ['NMETEREXNAME', 'Non-metered bus extended bus name'],
                                'XFRNAME'      : ['XFRNAME',      'Transformer name']
                            }

CONST_DICT_3WTRF_WND_REAL = {
                                'RXACT_RE'    : ['RXACT',    'Actual transformer resistance in pu'],
                                'RXNOM_RE'    : ['RXNOM',    'Nominal transformer resistance in pu'],
                                'COMPRX_RE'   : ['COMPRX',   'Load drop compensation resistance in pu'],
                                'RXZERO_RE'   : ['RXZERO',   'Zero sequence winding leakage resistance in pu'],
                                'ZGRND_RE'    : ['ZGRND',    'Zero sequence winding grounding resistance in pu'],
                                'PQ_RE'       : ['PQ',       'P flow at winding bus end (MW)'],
                                'PQLOSS_RE'   : ['PQLOSS',   'P Losses (MW)'],
                                'O_PQ_RE'     : ['O_PQ',     'P flow at winding bus end (user unit)'],
                                'O_PQLOSS_RE' : ['O_PQLOSS', 'Losses (user unit)']
                            }

CONST_DICT_3WTRF_WND_IMAG = {
                                'RXACT_IM'    : ['RXACT',    'Actual transformer reactance in pu'],
                                'RXNOM_IM'    : ['RXNOM',    'Nominal transformer reactance in pu'],
                                'COMPRX_IM'   : ['COMPRX',   'Load drop compensation reactance in pu'],
                                'RXZERO_IM'   : ['RXZERO',   'Zero sequence winding leakage reactance in pu'],
                                'ZGRND_IM'    : ['ZGRND',    'Zero sequence winding grounding reactance in pu'],
                                'PQ_IM'       : ['PQ',       'Q flow at winding bus end (MVar)'],
                                'PQLOSS_IM'   : ['PQLOSS',   'Q Losses (MVar)'],
                                'O_PQ_IM'     : ['O_PQ',     'Q flow at winding bus end (user unit)'],
                                'O_PQLOSS_IM' : ['O_PQLOSS', 'Losses (user unit)']
                            }

def tupGet3WTrfWndData(str_in, int_flag=3, int_sid=-1, **kwarg):
    '''Get 3-winding transformer winding data. Return as tuple.

    This is a wrapper function for "psspy.awndtypes()",
    "psspy.awndint()", "psspy.awndreal()", "psspy.awndchar()" and
    "psspy.awndcplx()".

    The 1st element is a list containing the data.
    The 2nd element is a string describing the data (can be used as header string).

    Parameters
    ----------
    str_in : string
        The string command to get the data.
        Note that the description would be returned as the 2nd element of the tuple.

    int_flag : int
        What kind of elements to include.

    int_sid: int
        The bus subsystem to be used.

        Default = -1; i.e., all buses.

    **kwarg :
        Other parameters accepted by "psspy.awndint()", "psspy.awndreal()", "psspy.awndchar()" and
        "psspy.awndcplx()".

    Returns
    -------
    list_temp: list
        The data as a list.

    str_return : str
        The description of the input string command.'''

    if not str_in:

        raise ValueError('A non-empty string value must be provided.')

    else:

        pass

    # to upper case
    str_in = str_in.upper()

    # check type, need to know which function to call
    int_ierr_type, str_temp = psspy.awndtypes(CONST_DICT_3WTRF_WND_HEADER[str_in][0])

    # to upper case
    str_type = str_temp[0].upper()
    # print(str_in)
    # print(str_type)

    # if error, rasie Value Error
    if (int_ierr_type != 0):

        raise ValueError('The input string to call up the plant bus data is wrong.'
                         + '\n'
                         + 'Error code = ' + int_ierr_type
                        )

    else:

        pass

    int_ierr = 1
    list_temp = []

    if (str_type != 'X') and (str_type != '?'):

        # call the integer function
        if (str_type == 'I'):

            int_ierr, list_temp = psspy.awndint(string=CONST_DICT_3WTRF_WND_HEADER[str_in][0], flag=int_flag, sid=int_sid, **kwarg)

        elif (str_type == 'R'):

            int_ierr, list_temp = psspy.awndreal(string=CONST_DICT_3WTRF_WND_HEADER[str_in][0], flag=int_flag, sid=int_sid, **kwarg)

        elif (str_type == 'C'):

            int_ierr, list_temp = psspy.awndchar(string=CONST_DICT_3WTRF_WND_HEADER[str_in][0], flag=int_flag, sid=int_sid, **kwarg)

    elif (str_type == 'X') and (str_type != '?'):
    # else:

        int_ierr, list_temp_complex = psspy.awndcplx(string=CONST_DICT_3WTRF_WND_HEADER[str_in][0], flag=int_flag, sid=int_sid, **kwarg)

        if str_in in CONST_DICT_3WTRF_WND_REAL:

            for i in list_temp_complex[0]:

                list_temp.append(i.real)

            list_temp = [list_temp]

        elif str_in in CONST_DICT_3WTRF_WND_IMAG:

            for i in list_temp_complex[0]:

                list_temp.append(i.imag)

            list_temp = [list_temp]

    if (int_ierr != 0):

        raise ValueError('String input wrong. Error code: ' + str(int_ierr))

    # flatten it
    list_temp = list_temp[0]

    str_return = CONST_DICT_3WTRF_WND_HEADER[str_in][1]

    return list_temp, str_return