Move buses in slider diagrams
Is it possible to move points on a slider diagram using Python? I want to have my slider diagram automatically created for me.
The grow bus functionality draws them in such a mess!
First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!
Is it possible to move points on a slider diagram using Python? I want to have my slider diagram automatically created for me.
The grow bus functionality draws them in such a mess!
Why would you want to manipulate a slider diagram through python? You could plot your own diagram with matplotlib. That would remove the hassles of searching for the appropriate API (if there are any??). I am trying something similar but struggling to put together some compact bit of code for retrieving the loadflow solution data using the API. Currently I read a text file of the loadflow solution and use it to plot a diagram with matplotlib.
I must reiterate that my current solution is to work outside PSSE. The solution consists of the following steps:
Note: I am not a professional programmer and I an not sure that this is easier to do than manipulating slider diagrams. But this is definitely another way of presenting your load flow results.
On to the tedious part that is Step 3. This involves mapping the bus number to its abbreviated name, display name and its co-ordinates in the paper space.
rncpg = [51,32] # mapping of bus to position in paper space
parupg = [227,97]
mthnpg = [247,144]
mthnrb = [220,155]
busMark = [
[45400, rncpg, 'Ranchi(PG)'], # mapping of bus to it abbreviated name and display name
[45401, parupg, 'Parulia(PG)'],
[45403, mthnpg, 'Maithon(PG)'],
[44400, mthnrb, 'MaithonRB']
]
Getting a presentable layout will require a lot of trial and error. A diagram can say more than a thousand words. But getting it right can be a real pain in the ....
you can minimize the trail and error by using python(machine language script)
Now to Steps 1 & 2:
Copy the loadflow solution (bus based reports without wide format output option) from the output bar and save it in text file format.
Read file with a python script and parse using regular expressions as follows:
import numpy as np
import matplotlib.pyplot as plt
import re, string
text_file = open("loadflow.txt", "r")
a = text_file.read()
text_file.close()
b = re.sub('\r\n', '', a)
lines = re.split('BUS', b)
genDat = []
for line in lines:
if re.search('GENERATION', line):
genDat.append(re.search('^\s*(\d{5}).*(?:TO)\s*(\d{5})(?:\s*\S*){2}\s*(\d)\s*([0-9]+(?:\.[0-9]*)?)', line).groups())
genDat = [list(i) for i in genDat]
That bit of code picks all the generation data for me. I use similar bits for extracting the load and line data.
Now finish it off with a flourish. Generate the plot with your favorite application. Here is one way to do it.
fig = plt.figure()
ax = fig.add_subplot(111)
for bus, (x, y), name in busMark:
marker = ax.plot(x, y, 'ko')
plt.text(x, y, name, fontsize=6)
ax.set_xlim(0,285)
ax.set_ylim(0,180)
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
ax.set_title('load flow plot')
plt.show()
fig.set_size_inches(11.22,7.08)
extent = ax.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
fig.savefig("loadflow.png", bbox_inches=extent)
I have limited myself to the bus markings but this should adequate to convey the general procedure. I am sure I am not the only guy working on this diagram problem. Let us know about your ideas.
Aah, those numbers, what do they signify? I wish there were more critics tearing down the method and pointing out demerits - like my boss who on being presented with a printout of the load flow plot passed the following comment - 'this no good, buses not in geographical positions'.
I was contemplating a quick left to his jaw when .... this idea bulb starts blinking and .... wait.... that bloke did have something there - why not put the data on a google map? But that I guess will have to wait till I can retrieve the load flow solution through the psse API.
I realize this post is a bit late, but it may help someone. Try using the slider.py module. This module is included with your PSSE download. If you contact Siemens PSSE technical support they will provide you with the documentation and some examples of how to use this module. One of the examples shows how to create your own diagram, including how to place a bus in a certain location.
for small number of buses, this code creates a slider within PSSe, though it does not set the proper X,Y coordinates:
#slider3.py
'''
Load a case (bus numbering assumes savnw.sav is loaded)
Open a new (blank) diagram
run this code
'''
def DrawBusesSLD(buslist):
n_buses=len(buslist)
buses=[]
for i in range(n_buses):
buses.append(buslist[i][0])
for i in range(n_buses):
psspy.growbus(buslist[i][0],buslist[i][1], buslist[i][2])
# main:
busdata=[
[203, 0, 0],
[204, 2, 0], #not drawn due to being a dummy bus in a multisection line
[205, 2, 2],
[206, 0, 2]
]
DrawBusesSLD(busdata)
# encoding: utf-8
# module sliderPy
# no doc
# imports
import Boost.Python as __Boost_Python
# Variables with simple values
ACLineSegment = 0
Arc = 4
Branch = 2
Breaker = 3
Busbar = 1
BusbarSection = 2
BusEventAccessPoint = 24
BusNode = 0
BusNodeLeft = 26
BusShunt = 13
CenterAlign = 0
Circle = 5
CircularBusbar = 20
ConnectionPort = 50
ConnectivityNode = 1
Contour = 11
Dash = 61680
DashDot = 3848
DashDotDot = 61576
DCLine = 12
Disconnector = 12
Dot = 34952
Ellipse = 6
EnergyConsumer = 7
EventAccessPoint = 23
FACTSBranch = 26
FACTSRadial = 27
FACTSSeries = 15
FACTSShunt = 14
FitToPage = 2
FixedShunt = 5
Floater = 4
Fuse = 11
GeneratingUnit = 8
Generic = 0
GNEShunt = 6
Ground = 14
GroundDisconnector = 28
HiddenAlways = 1
Image = 8
InvalidAlignment = 3
InvalidComponentType = 12
InvalidPrintMode = 4
InvalidSymbolDefID = -1
InvalidSymbolType = 7
InvalidVisibility = -1
Jumper = 24
KneePoint = 1
Label = 9
LeftAlign = 1
Line = 2
Link = 3
Load = 2
Machine = 4
ManualDisconnector = 21
MeasurementFloater = 15
MeasurementGeneric = 16
MiddleAbove = 8
MiddleBelow = 9
ModelAccessPoint = 22
MotorDisconnector = 20
MultiPage = 1
MultiTermDLine = 17
MultiTermDLineEnd = 18
MutualCoupling = 29
Node = 5
NullPosition = -1
PieChart = 21
Planning = 3
Polygon = 10
Port1Above = 0
Port1Below = 1
Port2Above = 2
Port2Below = 3
Radial = 3
Rectangle = 7
RectifierInverter = 13
Reporting = 25
RightAlign = 2
SeriesCapacitor = 17
SeriesReactor = 18
ShuntCapacitor = 6
ShuntReactor = 9
Solid = -1
StaticVarCompensator = 22
StationSupply = 23
Substation = 10
Switch = 4
Symbol = 0
ThreeWindTransformer = 19
Transformer = 5
Triangle = 16
TWTransformer = 11
UnspecifiedDiagramType = 0
VisibleAlways = 0
VSCDCLine = 19
Worldview = 2
WYSIWYG = 0
ZoomDependent = 2
# functions
def ExtractBValue(p_int, *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__
"""
ExtractBValue( (int)arg1) -> int :
unsigned long ExtractBValue(unsigned long color)
Returns the blue component of the specified COLORREF value
C++ signature :
unsigned long ExtractBValue(unsigned long)
"""
pass
def ExtractGValue(p_int, *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__
"""
ExtractGValue( (int)arg1) -> int :
unsigned long ExtractGValue(unsigned long color)
Returns the green component of the specified COLORREF value
C++ signature :
unsigned long ExtractGValue(unsigned long)
"""
pass
def ExtractRValue(p_int, *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__
"""
ExtractRValue( (int)arg1) -> int :
unsigned long ExtractRValue(unsigned long color)
Returns the red component of the specified COLORREF value
C++ signature :
unsigned long ExtractRValue(unsigned long)
"""
pass
def GetActiveDocument(): # real signature unknown; restored from __doc__
"""
GetActiveDocument() -> SldDocument :
SldDocument GetActiveDocument()
Returns the active SldDocument object
C++ signature :
class CPyWrapperDoc GetActiveDocument()
"""
return SldDocument
def GetExportDirectory(): # real signature unknown; restored from __doc__
"""
GetExportDirectory() -> str :
string GetExportDirectory()
Returns the current export file directory
C++ signature :
class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > GetExportDirectory()
"""
return ""
def GetImportDirectory(): # real signature unknown; restored from __doc__
"""
GetImportDirectory() -> str :
string GetImportDirectory()
Returns the current import file directory
C++ signature :
class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > GetImportDirectory()
"""
return ""
def GetImportFile(): # real signature unknown; restored from __doc__
"""
GetImportFile() -> str :
string GetImportFile()
Returns the current import file path
C++ signature :
class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > GetImportFile()
"""
return ""
def RGB(p_int, *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__
"""
RGB( (int)arg1, (int)arg2, (int)arg3) -> int :
unsigned long RGB(int r, int g, int b)
Returns the specified COLORREF value
C++ signature :
unsigned long ...
(more)I have created for myself simple solution for automatic creation of sld diagram containing necessary buses placed in the right places. Save following gif file and change extension from gif to zip, inside there are one excel file and one python file. Excel template is for preparing list of buses containing x and y coordinates for each bus. On "buses" sheet put bus numbers in the cells where approximately they should appear on your sld file. Then run macro "PreapreForPython" (to do that you will probably need to enable Developer tab). than copy-paste from another sheet list of buses into python just after "buses=" line. Than open in psse blank sld and run that python script. All buses will be more or less in right places. Of course this thing could be improved, feel free to do that, just don't forget to put better solution here :)
Hi, Could you share the code again? The link doesn't work now. I am struggling using python to drwa the SLD.
Asked: 2012-01-20 02:48:25 -0500
Seen: 8,227 times
Last updated: Jul 16 '19
I haven't seen anything helpful, anyone else have some clues here?