Ask Your Question
0

Code to count elements in SAV easier

asked 2019-11-06 04:53:15 -0500

drsgao gravatar image

This function is inspired by the subsystem_info function.

It bascially allows you get the element counts in the SAV programmatically easier. There is a feature in the GUI allows you to do very similar thing. I wrote this as an exercise.

Code:

def intGetCount(str_type, int_sid, int_flag, **kwarg):
    '''
    This function returns the element counts in a PSSE SAV file.

    This function uses the "getattr()" from Python to group the counting
    functions in "psspy". Consult PSSE documentation for how to set
    the subsystem ID and flag for each type of elements.

    Parameters
    ----------
    str_type : str
        Type of the target element. This is also used to get the right
        function in "pssspy".

        Here are some examples, consult PSSE documentation for all elements.

        * "bus" -- buses
        * "genbus" -- plant/generator buses
        * "mach" -- machines/generators
        * "loadbus" -- load buses
        * "load" -- loads
        * "fxshntbus" -- fixed shunt buses
        * "fxshunt" -- fixed shunts
        * "brn" -- branches
        * "trn" -- 2-winding transformers
        * "tr3" -- 3-winding transformers
        * "wnd" -- 3-winding transformer windings
        * "area" -- areas

    int_sid : int
        Bus subsystem ID.

    int_flag : int
        A flag indicating what subsystem buses to include.

    kwarg: named arguments accepted by the actual count functions
        This is to allow calling functions with more than just the sid
        and flag arguments, e.g., "awndcount()".

        You must used named arguments for these. Check the PSSE
        APIs for the named arguments.

    Returns
    -------
    int_count : int
        The count of the given element.

    Raises
    -------
    ValueError
        If the given element string results in None to be found in "psspy".
    '''

    # force throwing exception
    psspy.throwPsseExceptions = True

    str_type = str_type.lower()

    str_type = 'a%scount' % (str_type)

    func = getattr(psspy, str_type, None)

    if not func:

        raise ValueError("Module '%s' has no attribute '%s'" % ('psspy', str_type))

    else:

        pass

    # ignore the error since already forced throwing exceptions
    _, int_count = func(sid=int_sid, flag=int_flag, **kwarg)

    return int_count

Example usage (after the usual init and case, of course):

int_bus_count = intGetCount('bus', -1, 2)

print('Bus Count = %d' % int_bus_count)

int_3w_trf_wcount = intGetCount('wnd', int_sid=-1, int_flag=3, owner=1, ties=3)

print('3-winding transformer windings = %d' % int_3w_trf_wcount)

Feedbacks are welcome.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-11-21 05:07:57 -0500

yunzhi cheng gravatar image

Interesting. Psse has some api to obtain data (such as gen, line) per subsystem basis. After that, it is easy to count the number of devices by looking at length of the array.

edit flag offensive delete link more

Comments

You can. But why. The "psspy" module already has count functions. Also, Python has no array. Unless you are talking about numpy array.

drsgao gravatar imagedrsgao ( 2019-11-21 08:29:52 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: 2019-11-06 04:53:15 -0500

Seen: 415 times

Last updated: Nov 21 '19