Ask Your Question

nwilson's profile - activity

2019-10-03 10:17:59 -0500 received badge  Nice Answer (source)
2018-07-28 13:29:22 -0500 commented question Does anyone know of any projects attempting to visualize the results of contingency analysis?
2018-07-28 13:28:51 -0500 answered a question Does anyone know of any projects attempting to visualize the results of contingency analysis?
2017-12-26 09:50:35 -0500 answered a question Question about retrieving ACC results using python

In your PTI\PSSE33\EXAMPLE folder, check out the accc_reports.py program. Check out their use of psarrays.accc_summary where they iterate through the element labels that correspond with the accc_solution function.

2017-04-28 17:09:57 -0500 commented answer get id from selected branch

mydoc = sliderPy.GetActiveDocument()
mydiagram = mydoc.GetDiagram()
mycomponents = mydiagram.GetComponents()
for comp in mycomponents:
  string = comp.GetMapString()

2017-04-28 17:02:21 -0500 answered a question Print individual contingencies to sliders

I don't think you can write a python script to print ACCC results on a slider for multiple contingencies. If you're looking to create a slider-like graphical report for different contingencies, you could write a python script that populates PowerPoint slides with labeled objects (lines that represent buses, branches) that are customized for each contingency. Here's something to get you going:

import win32com.client as win32

from time import sleep

msoRoundRectangle = 5   #5 is a rounded rectangle. https://msdn.microsoft.com/en-us/library/office/aa170976(v=office.11).aspx

def main():
    ppoint()

RANGE = range(3, 8)

def RGBtoInt(R,G,B):
    result = R*(256**2) + G*256 + B
    return result

def ppoint():
    app = 'PowerPoint'
    ppoint = win32.gencache.EnsureDispatch('%s.Application' % app)
    pres = ppoint.Presentations.Add()
    ppoint.Visible = True

    s1 = pres.Slides.Add(1, win32.constants.ppLayoutText)
    sleep(1)
    s1a = s1.Shapes[0].TextFrame.TextRange
    s1a.Text = 'Python-to-%s Demo' % app
    sleep(1)
    s1b = s1.Shapes[1].TextFrame.TextRange
    s1.Shapes.AddShape(msoRoundRectangle,900,20,50,30)
    s1.Shapes.AddShape(msoRoundRectangle,450,500,50,30)
    sleep(1)
    #connect "buses"
    #see https://msdn.microsoft.com/EN-US/library/office/ff840820.aspx
    myline = s1.Shapes.AddLine(925,35,475,515).Line
    #change line properties with LineFormat object: https://msdn.microsoft.com/en-us/library/office/ff194214.aspx
    myline.ForeColor.RGB = RGBtoInt(50,0,128)   #violet line color
    sleep(1)
    #warn(app)
    #pres.Save()     #saves to default location (My Documents). https://msdn.microsoft.com/en-us/library/office/ff745194.aspx
    pres.SaveAs("C:\\temp\\test")     #https://msdn.microsoft.com/en-us/library/office/ff746389.aspx
    ppoint.Quit()


if __name__ == '__main__':
    main()
2017-01-22 23:12:16 -0500 commented answer Interacting with PSSE GUI

This answer extracts the label information to identify buses. A better solution using the getmapstring function in sliderpy is shown in the "get id from selected branch" question.

2016-12-09 14:10:38 -0500 commented answer get id from selected branch

Thanks, works perfect. I added .split() to be able to cleanly reference each returned item.

2016-12-09 14:08:51 -0500 received badge  Supporter (source)
2016-12-08 16:35:42 -0500 received badge  Notable Question (source)
2016-12-08 16:35:42 -0500 received badge  Famous Question (source)
2016-12-08 16:35:42 -0500 received badge  Popular Question (source)
2016-12-07 10:40:20 -0500 asked a question get id from selected branch

Using slider.py, I've been reading the labels to identify selected bus numbers and branches. How do I get the branch id of a selected branch? This is especially pertinent when I have parallel branches.

2016-08-17 09:20:56 -0500 received badge  Taxonomist
2016-05-09 21:12:33 -0500 marked best answer WxPython crashing PSSE

I'm running the code below using the run macro button on the toolbar in PSSE 32. It runs fine the first time. I close the window and run it again. When I close it this time, PSSE says it has encountered an error and needs to close. It seems as if the first time, there was something left running that conflicts with the second request. Is there something I need to do to effectively close the python script? Some sort of garbage collection?

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, (550, 350))

        system_events_list = ['Bridger Fault', 'Salt Solar Outage', 'Hunter Fault']

        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
        hbox3 = wx.BoxSizer(wx.HORIZONTAL)

        panel = wx.Panel(self, -1)
        self.system_events = wx.ListBox(panel, 26, wx.DefaultPosition, (170, 130), system_events_list, wx.LB_SINGLE)
        self.system_events.SetSelection(0)
        btn = wx.Button(panel, wx.ID_CLOSE, 'Close')
        hbox1.Add(self.system_events, 0, wx.TOP, 40)
        hbox3.Add(btn, 0, wx.ALIGN_CENTRE)
        vbox.Add(hbox1, 0, wx.ALIGN_CENTRE)
        vbox.Add(hbox3, 1, wx.ALIGN_CENTRE)
        panel.SetSizer(vbox)

        self.Bind(wx.EVT_BUTTON, self.OnClose, id=wx.ID_CLOSE)
        self.Bind(wx.EVT_LISTBOX, self.OnSelect, id=26)

    def OnClose(self, event):
        self.Close()

    def OnSelect(self, event):
        index = event.GetSelection()
        system_event = self.system_events.GetString(index)

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, 'listbox.py')
        frame.Centre()
        frame.Show(True)
        return True

app = MyApp(0)
app.MainLoop()
2015-09-02 09:34:07 -0500 answered a question How to list which buses are connected to THIS bus?

You can use the psspy.nxtbus function to find the next bus. Here's some code that may help:

ierr = psspy.inibus(startbus) if ierr < 1: while 1 == 1: ierr, foundbus, longbusname = psspy.nxtbus(startbus) if ierr < 1: buslist.append(foundbus) else: break

2015-07-10 15:56:14 -0500 answered a question Sizing of a fixed shunt capacitor

Sounds like you just need to get the bus voltage for a bus. To get the voltage in pu for bus 153, use the following code:

ierr, busvoltage = psspy.busdat(153,'PU')
2015-04-28 09:01:55 -0500 received badge  Editor (source)
2015-04-28 09:01:04 -0500 answered a question branch loading

The brnflo method will return MW and MVAR for a branch with sign according to first bus to second bus. The branch ID must always be in single quotes.

ierr, branchflow = psspy.brnflo(12,13,'1')

To see the result, use print branchflow. To see just the MW, use print branchflow.real. To see just the MVAR, use print branchflow.imag

2015-01-30 07:29:08 -0500 received badge  Famous Question (source)
2015-01-28 08:55:35 -0500 received badge  Notable Question (source)
2015-01-28 00:50:22 -0500 received badge  Popular Question (source)
2015-01-26 13:28:54 -0500 asked a question Respond to GUI load flow results

The goal is for a user to have a notification if certain conditions exist after running a load flow in the gui. Could you open the gui with python and monitor a bus while the user uses the gui to modify system configurations and run load flows? Or can the gui start a script whenever is opened? Can a python script monitor load flow results initated through the gui? If the condition was found, the python code (or wxpython) would notify the user and create a report.

If not, a WxPython program that resembles the gui could be created so that all gui actions are accesible but that sounds like a lot of work. Anyone created a PSSE gui clone in WxPython?

2014-07-08 09:37:37 -0500 answered a question How to make a conditional statement based on PSSE output file?

Here's code that reads the PSSE output file and evaluates the data for a specific condition.

#dyntools contains the CHNF class for extracting channel data from .out files
#the dyntools library comes with PSSE
from dyntools import CHNF as ChanFile

threshold = 5   #set this to desired limit

#outfiles is a list of outfile paths
outfiles = ["c:\\results\\myout1.out","c:\\results\\myout2.out"]    #example

chnfall = ChanFile(outfiles)
#loop through outfiles
for outfile, clist in chnfall.chanid.iteritems():
    #loop through channels of each outfile
    for channelnum, channelname in clist.iteritems():
        #the last channel is the 'time' channel. We're ignoring it
        if channelnum <> 'time':
            print "Channel " + str(channelnum) + channelname
            if channelname == "gen1volt":
                #extract channel data from channel.
                #The CHNF class converts outfile names to lower case. Use the lower() function
                yvals = chnfall.chandata[outfile.lower()][channelnum]
                ymax = max(yvals)
                if ymax > threshold:
                    print "Threshold exceeded"
                    #perform action as a result of exceeded threshold
2014-06-12 12:03:31 -0500 asked a question Plot dynamic results with multiple scales

I'm trying to plot dynamic results to a Word document using the dyntools library where the channels have different voltage scales. The optnchn parameter allows a yscale but it's not clear how to specify yscales for different channels. If optnchn is omitted, the default scales are used. Plotting the defaults does show that the chart has multiple scales (although only one scale is labeled). I would like channel 301 to have a scale of 0 to 1.5 and channel 2 to have a scale from 50 to 150.

import dyntools

chnf =dyntools.CHNF(C:\dynresults.out)

docfile    = ('C:\savnw_response.doc')
show       = True
overwrite  = True
caption    = True
align      = 'center'
captionpos = 'below'
height     = 0.0
width      = 0.0
rotate     = 0.0

optnfmt  = {'rows':3,'columns':1,'dpi':300,'showttl':True}

optnchn  = {1:{'chns':[301,2],'yscale':[0,1.5]}
               }
ierr = chnfobj.xyplots2doc(optnchn,optnfmt,docfile,show,overwrite,caption,align,
                        captionpos,height,width,rotate)
2014-04-30 17:34:04 -0500 answered a question where can I find information about psspy?

PSSE comes with an API manual that contains all the psspy functions. Search for API.pdf in your PTI installation folder. Mine is found at C:\Program Files (x86)\PTI\PSSE32\DOCS\PSSEAPI.

2014-04-11 17:23:02 -0500 commented question Contingency A, B & C

I guessing it's the results using Rate A, Rate B, and Rate C for the equipment.

2014-02-13 19:26:14 -0500 received badge  Enlightened (source)
2014-01-09 18:32:05 -0500 received badge  Good Answer (source)
2014-01-09 09:45:52 -0500 received badge  Nice Answer (source)
2014-01-06 16:43:51 -0500 received badge  Necromancer (source)
2014-01-06 16:43:51 -0500 received badge  Teacher (source)
2014-01-06 11:27:17 -0500 answered a question Interacting with PSSE GUI

It can be done using the sliderPy library

import sliderPy

def main():
    mydoc = sliderPy.GetActiveDocument()
    mydiagram = mydoc.GetDiagram()
    mycomponents = mydiagram.GetComponents()
    print str(len(mycomponents)) + " components found"
    i = 0
    for mycomponent in mycomponents:
        if mycomponent.IsSelected() == True:
            print 'Type: ' + str(mycomponent.GetComponentType())
            mylabels = mycomponent.GetOwnedLabels()
            print str(len(mylabels)) + ' labels found'
            j = 1
            for mylabel in mylabels:
                print 'Label ' + str(j) + ': ' + mylabel.GetText()
                print '\n'
                j += 1
        i += 1
        #if i == 10: break

    print str(i) + ' items searched'

if __name__ == '__main__':
    main()
2013-12-31 22:28:09 -0500 received badge  Student (source)