Created
August 20, 2011 01:54
-
-
Save jtrain/1158488 to your computer and use it in GitHub Desktop.
An easy method for getting attribute information from the PSSE subsystem data retrieval api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import groupby | |
from operator import itemgetter | |
attr_type = itemgetter(0) | |
import psspy | |
def subsystem_info(name, attributes, sid=-1, inservice=True): | |
""" | |
Returns requested attributes from the PSS(r)E subsystem API | |
for the given subsystem id and subsystem element name. | |
e.g. to retrieve bus attributes "NAME", "NUMBER" and "PU" | |
subsystem_info('bus', ["NAME", "NUMBER", "PU"]) | |
where the 'bus' `name` argument comes from the original | |
PSS(r)E subsystem API naming convention found in Chapter 8 of the | |
PSS(r)E API. | |
abusint # bus | |
amachint # mach | |
aloadint # load | |
Args: | |
inservice [optional]: True (default) to list only information | |
for in service elements; | |
sid [optional]: list only information for elements in this | |
subsystem id (-1, all elements by default). | |
""" | |
name = name.lower() | |
gettypes = getattr(psspy, 'a%stypes' % name) | |
apilookup = { | |
'I': getattr(psspy, 'a%sint' % name), | |
'R': getattr(psspy, 'a%sreal' % name), | |
'X': getattr(psspy, 'a%scplx' % name), | |
'C': getattr(psspy, 'a%schar' % name), } | |
result = [] | |
ierr, attr_types = gettypes(attributes) | |
for k, group in groupby(zip(attr_types, attributes), key=attr_type): | |
func = apilookup[k] | |
strings = list(zip(*group)[1]) | |
ierr, res = func(sid, flag=1 if inservice else 2, string=strings) | |
result.extend(res) | |
return zip(*result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment