How do I find an available bus number?
I am looking to add a bus to an existing network. Ignoring any numbering conventions my colleagues may have, how do I find a available bus number to use?
First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!
I am looking to add a bus to an existing network. Ignoring any numbering conventions my colleagues may have, how do I find a available bus number to use?
I just wrote this a couple hours ago for a similar problem. So it can probably be cleaned up:
def get_next_free_busnum():
"""
get the next free bus number
"""
# find largest bus number
ierr, all_buses = psspy.abusint(
sid=-1, # all buses in the case.
flag=2, # in-service and out-of-service buses
string=["NUMBER"]
)
# transpose from 2D array to 1D list.
all_buses = zip(*all_buses)[0]
busnum = max(all_buses) + 1
return busnum
I guess you could do something smart like:
busnum = min(set(range(15000)) - set(all_buses))
# where 15000 is highest busnum you want to use
This will return 0, which I'm not sure is a valid number or not.
I like your max + 1 approach.
you can set the range to begin at 1. range(1, 15000) your zero bus problem should go away.
If the intent is to just print out the available bus numbers in a text report, then you can use built in psspy.busn
.
Use this API to tabulate unused bus numbers within a specified bus number range (activity BUSN).
Batch command syntax:
BAT_BUSN BUSLO BUSHI
Python syntax:
ierr = busn(buslo, bushi)
Fortran syntax:
CALL BUSNAPI(BUSLO, BUSHI, IERR)
where:
Integer BUSLO Is the low limit of bus number range (input; 1 by default).
Integer BUSHI Is the high limit of bus number range (input; 999,997 by default).
Integer IERR Is the error code (output).
IERR = 0 no error occurred.
IERR = 1 invalid starting bus number.
IERR = 2 starting bus number is greater than ending bus number.
IERR = 3 prerequisite requirements for API are not met.
Ok, first you need to know what buses exist in the system already. Then work out a bus that fits into one of the gaps.
ierr, buses = psspy.abusint(-1, flag=2, string="NUMBER")
# convert to a simple set of buses
taken_buses = set(zip(*buses)[0])
# now find the first available gap between 1 and 10,000:
# 10,000 - or any suitably high number.
available_bus = None
for bus in range(1, 10000):
if bus not in taken_buses:
available_bus = bus
break
print "You can use bus=%d if you want." % available_bus
You did say that you don't care about colleagues conventions.. They probably won't like that :)
Nice, i didn't know about the -1 subsystem trick.
Asked: Mar 23 '12
Seen: 2,508 times
Last updated: Sep 26 '16
Save .raw case after updating the transformer limits in python
psspy can't run with another case without any exception
Bus number too long, workaround
Conversion of uexc.flx flecs code to uexc.for fortran code
Convert transformer impedance input data
What is the API for generating the .qv files?
Avoid "call change_var" writting.
Can I extract updated values after running DC Loadflow (DCLF_2)?
How to output STATE and DSTATE by PSS/E dynamic simulation used Python command?
Both Chip's (the selected answer) and JervisW's answers solve my problem. Thanks guys!