On 05/28/2013 06:00 AM, Debbie wrote:
Hi there,
I am new to Python,

Welcome. Could you tell us a little about yourself, such as whether you've experience in a few other languages, or if Python is your first programming experience? Also, what version of Python (presumably 2.7 or 2.6) and what OS ?

and wondering if you could help me with python based coding for the IPSA (Power 
system analysis software). I have a electrical distribution network with 
generators, buses and loads, on which I am performing the load flow analysis 
every 1 hour for a period of 1 year.

The code to perform instantaneous load/power flow analysis is given below. I 
need to modify it such that I can perform this load flow analysis every 1 hour 
for a period of 1 year. Please help.

from ipsa import *

I have no idea what functionality is in ipsa, so this whole message is a guess. First question is whether the ReadFile() below and the DoLoadFlow() read the whole year's data, or data for a particular hour. And if the latter, how do you get the next set of data?



ipsasys = IscInterface()
net = ipsasys.ReadFile("refinery.iif")
bok = net.DoLoadFlow();
if bok:
     busbars = net.GetBusbars()
     print "Load Flow results:"
     print ""
     print "BusName     Vmag(kV)"
     print "===================="
     for bus in busbars.itervalues():
         name = bus.GetName()
         vm = bus.GetVoltageMagnitudekV()
         res = "%-8s  %10.5f" % (name, vm)
         print res
else:
     print "Load Flow failed!"

Regards,
Debbie


First you want to make a function to print out a particular hour's data. That might turn out to be something like:

def one_hour(net):
    busbars = net.GetBusbars()
    print "Load Flow results:"
    print ""
    print "BusName     Vmag(kV)"
    print "===================="
    for bus in busbars.itervalues():
        name = bus.GetName()
        vm = bus.GetVoltageMagnitudekV()
        res = "%-8s  %10.5f" % (name, vm)
        print res

(Just pasted from your code, I added in the probable parameter to the definition)

Now your main function might be something like:


def main(filename):
    ipsasys = IscInterface()
    net = ipsasys.ReadFile(filename)

    #if net gets you data for one hour, figure out how
    #to get the data for the whole year, in the form
    #of a list or an iterator called nets

    bok = net.DoLoadFlow();
    if bok:
        for net in nets:
            one_hour(net)

    else:
        print "Load Flow failed!"


#and your top-level code is:
main("refinery.iif")


As to ordering in the source file, put the import first:
   from ipsa import *

then your function definitions one_hour() and main(), then
your top-level code.

--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to