Ask Your Question

maccartm's profile - activity

2015-09-13 22:20:00 -0500 received badge  Famous Question (source)
2015-09-02 02:44:33 -0500 received badge  Notable Question (source)
2015-08-28 16:08:20 -0500 received badge  Popular Question (source)
2015-08-28 13:44:17 -0500 answered a question Get area interchange from 230kV lines only

My solution ended up using the initie command with the relevant area, and then using nxttie() to loop through each tie. First I would check if the bus was in the required area (123 in the example), then I would then check the bus using busdat to see if it was a 230 kV line. If it was, I made sure that I had the correct metered end, and then I would add the real part of brnflo to my running total, and this would give me the total in the end. Example code:

myArea = 987
toArea = 123
kV = 230.0
interchange230 = 0

ierr = psspy.initie(myArea)
ierr, ibus, jbus, ickt = psspy.nxttie()

while ierr == 0:
    ierr, ival = psspy.busint(jbus, 'AREA')
    if (ierr == 0) and (ival == toArea):
        ierr, rval = busdat(jbus, 'BASE')
        if (ierr == 0) and (rval == kV):
            ierr, ival = psspy.brnint(ibus, jbus, ickt, 'METER')
            if (ival == ibus):
                ierr, cmpval = psspy.brnflo(ibus, jbus, ickt)
                if (ierr == 0): 
                    interchange230 += cmpval.real
            else:
                ierr, cmpval = psspy.brnflo(jbus, ibus, ickt)
                if ierr == 0:
            i       interchange230 += -(cmpval.real)
2015-08-18 09:04:53 -0500 asked a question Get area interchange from 230kV lines only

As the title suggests, I'm looking for a method to find the area interchange on the 230kV lines.

When I enter ties area into the PSSE command prompt, and pass the required area number (call it 987 for this example), I receive a print out which looks something like the following:

   TO AREA  123   ABC
   X---- FROM AREA BUS ----X   X----- TO AREA BUS -----X
     BUS# X-- NAME --X BASKV     BUS# X-- NAME --X BASKV  CKT      MW      MVAR
   987123 BUS1        230.00*  123123 BUS4        230.00   1      13.9    -25.7
   987456 BUS2        230.00*  123456 BUS5        230.00   1     110.7    -14.5
   987789 BUS3        115.00*  123789 BUS6        115.00   1     -20.7     -3.0
   TOTAL FROM AREA 987 TO AREA 123                                -0.7    -48.3

Now, here's my question.

I know that I can use a command such as psspy.aritoj(987, 123). This will give me (-0.7 - 48.3j), a complex value representing the total net interchange between these areas. This is fine, and I use this at one point in my code.

The problem is that I am also interested in the interchange on the 230kV lines only: the value (124.6 - 40.2j) in this example. (If it makes a difference, all that I need is the real portion of the value, I do not need the entire complex number)

I've been searching around the API and can't seem to find anything to get this value. (it cannot simply be printed to the screen as the ties command does; I need it to be stored in a variable as well as it is to be used elsewhere in the script).

Is there any command which will get me this value?

Thanks for any help.

2015-06-10 10:50:56 -0500 answered a question Suppressing some PSSE output permanently suppresses all output

If anyone is interested, here is how I solved my problem (quite simple):

Whenever I want output to be suppressed, I make a call to redirect.psse2py(), and then I execute the PSSE functions in the with statement:

with silence():
    #do some PSSE stuff

Afterwards, when I want some output to go back to PSSE, I had to call redirect.py2psse(). When I made this question I didn't know such a function existed. This solved all problems.

2015-06-09 14:14:54 -0500 received badge  Organizer (source)
2015-06-09 14:12:29 -0500 asked a question Suppressing some PSSE output permanently suppresses all output

I've followed the procedure outlined in the "Silencing PSSE output" article from whit.com. However, after calling redirect.psse2py(), everything that should be output becomes suppressed as well; this includes items outside of the

with self.silence():
    #call some PSSE function

blocks. Does anyone have an idea for how to remedy this problem?

My program runs psspy.fnsl(...) in a loop a number of times, which should all be suppressed. After the loop, I want to do one final solve, with output displayed. I then call psspy.solved() and attempt to print a message based on what is returned. However, nothing is printed to the PSSE window.

Here is the code I use for my silence method (This is contained inside a class; my program uses Tkinter GUI's so most of the code is wrapped up in a "Window" class):

 
@contextmanager
def silence(self, fileObject = None):

    if fileObject is None:
        fileObject = open(os.devnull, 'w')

    oldOutput = sys.stdout

    try:

        sys.stdout = fileObject
        yield 

    finally:

        sys.stdout = oldOutput

*EDIT:

On subsequent runs, even text that comes before the redirect.psse2py() call will not be output to the PSSE window. I have a test statement print "redirecting output" on the line before the redirect call, and it will only print out on the very first run through of the program.

2015-06-09 14:06:19 -0500 received badge  Autobiographer
2015-05-06 10:15:55 -0500 received badge  Editor (source)
2015-05-06 10:01:27 -0500 asked a question Python(2.5) script using Tkinter causes PSSE32 to freeze on second run

Hello.

Incoming wall of text:

I'm having a problem with a script I wrote for PSSE v32 with Python v2.5 as the title suggests. The script is supposed to take in relevant generator data from an excel file. The spreadsheet is formatted as follows:

Bus#     Bus ID    Bus Name    PNRIS    PERIS   PMAX   Changes    Notes 
 #       'str'     'str'         #        #      #      'str'     'str'


"Changes" and "Notes" are not important for this question, I just want the specifics of the excel file to be clear. Basically its the information about a generator, followed by 3 different possible power values that it might be set to.

The script creates a subsystem with all of the relevant machines to be changed, and will set the PGen value of every machine in the subsystem to the user's selected power type. Choices are NRIS, NRIS + ERIS, ERIS, or PMAX. The power type selection is made using Tkinter, using 4 Radiobuttons.

On the first run through the program, everything runs exactly how it is supposed to run. However, if I try to run the script a second time within the same instance of PSSE (IE, without closing the program and reopening it), PSSE locks up. This occurs whether I attempt to run the script on the same .sav file, or if I open another case.

I understand that PSSE runs every subsequent Python script from where the previous one left off? I believe my problem has something to do with Tkinter. Earlier in the development process I encountered an error in which the second run *would* work, but the variable associated with the Radiobuttons would be stuck to whatever it was initialized as.

One additional piece of information; when I run this script, other toolbar Python scripts will still work correctly after running it. However, the following, which again utilizes Tkinter:


import Tkinter
from Tkinter import *

root = Tk()
v = IntVar()
v.set(1)
val = 0

def updateSelection():

    print v.get()

def main():

    Label(root, text = "Test").pack(anchor = W)
    Radiobutton(root, text = "1", command = updateSelection ,variable = v, value = 1).pack(anchor = W)
    Radiobutton(root, text = "2", command = updateSelection, variable = v, value = 2).pack(anchor = W)
    Button(root, text = "OK", command = root.destroy).pack(anchor = S)
    mainloop()
    print ("Final selection: " + str(v.get()))

main()

Will only print & return 1. Normally, if I run this script through PSSE using the toolbars, I can run it any number of times in a row and it will run as expected. The selection number is printed every time the selection changes, and "Final selection: #" is printed when OK is clicked. This may not be relevant, however, since it uses Tkinter I feel like it might be related to my problem.

I'm new to PSSE (starting using it one week ago today) so I could easily be missing something fundamental. I'm running the script from PSSE using the custom toolbar icons. I cannot attach my .py file, as I'm new to this site and thus do not have enough Karma. It ... (more)