PSSE Python Training Material
PSSE Python Training Material
PSSE Python Training Material
Introduction
2
Please …
As a
courtesy to
everyone,
please
silence your
phone
3
Basic Skills Required
• Electrical Engineering.
• Power system analysis, operation, planning, and control.
• Algorithm flowchart development.
• Ability to use mathematical expression
• Basic programming skills.
• Critical thinking.
• Good computer skills.
4
Materials Covered …
• Module 1: Introduction to Python, Introduction to PSS/E, Why Python
with PSS/E (Interface Python with PSS/E)?
• Module 2: Steady-State Analysis, Power System Planning and
Operation Applications, Important Modules to add-on, Node Breaker
Topology
• Module 3: Python Operations on PSS/E Files (Automation Started..)
• Module 4: Dynamic-State Analysis, Power System Dynamics, Python
Operations to Control Dynamic Simulation.
• Module 5: Advanced Python Topics and Applications, Basic Idea of
User-Defined Models, Basic Idea of GUI Development.
5
Training Main Goals
• To review basic skills in PSS/E operation
• To train power system engineers to run PSS/E more
efficiently and maximize the benefit of using the
software.
• To train power system engineers on basic skills in
programming and in particular in python
• To make use of available resources
• To allow for further advanced usage of Python-
PSS/E
6
Training is interactive and practice
based
• During the training, your are encouraged to:
• Ask questions that may be of general interest
• Relate your experiences to our discussion topics
• Raise points of interests that we all can work on
• Discuss special experience with the rest of trainees.
• Practice:
• We will have many practices along our training.
• Every trainee should have PSS/E and a dongle
• We should have internet access to download necessary libraries.
7
Daily Schedule
8
Day 1 Schedule
Time Topics
8:00 – 8:30 Welcome and Introduction
8:30 – 10:00 Introduction to Python
10:00 – 10:15 Break
10:15 – 12:00 Introduction to PSS/E
12:00 – 1:15 Break (Prayer and Lunch)
1:15 – 2:30 Interface Python with PSS/E
9
Day 2 Schedule
Time Topics
PSSE – Transmission Planning and Operation,
8:00 – 10:00
Steady – Steady State Applications
10:00 – 10:15 Break
10:15 – 12:00 Python Operation, Contingency Analysis
12:00 – 1:15 Break (Prayer and Lunch)
1:15 – 2:30 Node Breaker Topology, Important Python Modules
10
Day 3 Schedule
Time Topics
8:00 – 10:00 Single/Subsystem Data Retrieval
10:00 – 10:15 Break
10:15 – 12:00 Data Import/Export, Reporting.
12:00 – 1:15 Break (Prayer and Lunch)
1:15 – 2:30 PSS/E Integration with MS suits, and SC Application
11
Day 4 Schedule
Time Topics
8:00 – 10:00 Power System Dynamics, Dynamic Simulation
10:00 – 10:15 Break
Data Retrieval from Dynamic Models, Dynamic
10:15 – 12:00
Simulation using Python
12:00 – 1:15 Break (Prayer and Lunch)
Monitoring, Controlling, and Plotting Dynamic
1:15 – 2:30
Simulation Results, PSS/E Execution Automation
12
Day 5 Schedule
Time Topics
8:00 – 10:00 Looping Scripts through Power Network Elements
10:00 – 10:15 Break
PSS/E Standard Input Files, Advanced Python
10:15 – 12:00
Topics/Applications
12:00 – 1:15 Break (Prayer and Lunch)
Interacting with Operating System, Introduction to
1:15 – 2:30 User-Defined Model, Introduction to GUI,
References, and Last Words!
13
Developed by
Thamer Alquthami, PhD, CEM, CEA,
CMVP
Associate Professor
Electrical Engineering
Department/Faculty of Engineering
King Abdulaziz University
Jeddah, Saudi Arabia
tquthami@gmail.com
14
15
PSS/E - Python
Module 1
16
Agenda
• Programming Languages • Introduction to PSS/E
• Python Language Overview • PSS/E – Python Modules
• Installation & Interpreter • Interface with PSS/E
• Standard and add-on • Other PSS/E – Python
modules Modules
• Variables and Data Structures • Third – Party Python
• Control Flow Statements Modules
• Input/Output Processing
17
Programming Languages
• High Level
• Structured – Object
Oriented
• Open Source
• Large Free Libraries
• Easy
• Runs on Different OS
• Help is Online
• Elegant for UI
18
Python Language Overview
• Different basic data types: numbers, strings, lists,
and dictionaries.
• Python supports object-oriented programming
with classes and multiple inheritance.
• Code can be grouped into modules and packages.
• Cleaner error handling: it supports raising and
catching exceptions.
• Data types are strongly and dynamically typed.
• Python contains advanced programming features
such as generators and list comprehensions.
• Python's automatic memory management frees
you from having to manually allocate and free
memory in your code
https://wiki.python.org/moin/BeginnersGuide 19
Installation Python
20
https://wiki.python.org/moin/Python2orPython3
Python Shell (Interpreter)
• Python comes with a standard Shell
(IDLE)
• Not interactive
• Has many disadvantages
• Many other shells are existed:
• Ipython – Excellent and supported
• Reinteract – old
• Bpython – updated
• Ipython is recommended if you
want to use a shell
• Editor in this case could be a notepad
• Comes with Anaconda
21
Practice!
>>> print('Hello SEC Operation Team')
Hello SEC Operation Team
>>> def TestFunction():
... print 'this is a function'
...
>>> TestFunction
<function TestFunction at 0x0523D0B0>
>>> TestFunction()
this is a function
22
Integrated Development
Environment (IDE) – Code Editors
• So many with different
applications
• Free/licensed.
• Has ipython (interactive)
• Best to work with if you
need to write complex
code
• Ex: Spyder. It comes with
Anaconda distribution
https://www.anaconda.com/downlo
ad/
https://wiki.python.org/moin/IntegratedDevelopmentEnvironments 23
IDE – Matlab Vs Python
24
Standard (Built-in)
• Standard Python installation comes with built-in (Examples)
• string – Common String Operations
• re – Regular expression operators
• math – Mathematical functions
• csv – CSV file reading and writing
• datetime – Basic data and time types
• random – Generate pseudo-random numbers
• itertools – Functions creating iterators for efficient looping
• collections – High performance container datatypes
• os – operating system interfaces
• theading – higher level threading interface
• pdb – The python standard debugger
• profile & cProfile – Profiling tools
• test – Regression tests package
25
Practice!
• Install Anaconda and run it. Or install Ipython
by itself and run it.
• List installed modules
>>> help('modules’)
>>> help('modules math’)
>>> help(‘math’)
• Run Several Built-in libraries # This is a test file
print ('Hello SEC National Grid Operation Team')
>>> help('math.cos’)
>>> m.cos(0) x = 50;
>>> m.cos(1) import sys y = 100;
>>> m.cos(m.pi)
for i in sys.path: z = x*y;
print(i) print 'Z = %i' % z
26
Python Add-on Modules
• A Module is a python file has Python
statements, definitions, and functions.
• With Python, we can put such
definitions in a file, and use them in a
script, or in an interactive instance of
the interpreter. Such a file is a module.
• We can create a long program using
modules.
• Modules can have group of functions
• Addressed by modulename.function()
27
Practice!
• Define a small program
myMath.py module
• Notice
• Function order
• Module help
• Help text of each function
• Items are imported using from or
import
• from module import
function
• function()
• import module
• module.function()
28
Python Packages
• Organized files, codes, modules in a
hierarchical shape
• Big software is divided into many
packages
• A Package may contain sub-
packages, modules
• os, math, sys are not packages. They
are all modules
29
Python Packages
• Most of published python packages
are indexed online and found at
https://pypi.org/
30
Variables and Data Structures
(General)
• Python line structure
• Backward slash
• Triple dash
• Python Comments
• # this is a comment
• Docstrings as shown before
• Indentation is important
• Many statement in one line. Q = 6; f = 7;
31
Variables and Data Structures
(General)
• Python Identifiers (Don’t use them)
and def False import not True
as del finally in or try
assert elif for is pass while
break else from lambda print with
class except global None raise yield
continue exec if nonlocal return
32
Data Structures (Numbers)
• Type function is important !
33
Data Structures (String)
• Sequence of Characters
• Python does not have a char data type.
• Very flexible
• Single and double quotations. End with
what you started with
• Display part of a string
• Python String Formatting
• % Operator: use % operator to format a
string or values in a string. Use %s where
you want a value to appear and put %
operator and identifiers after the string
• String Concatenation
34
35
Data Structures: List
• A list is a collection of different
values with different types.
• Slicing
• Length → len()
• Reassigning
• Multidimensional List
36
Data Structures: Tuples &
Dictionaries
• Tuples Like a list but not immutable
• Accessing & slicing
• Immutable
37
Data Structures: Boolean & Sets
• A Boolean values can be True or False
• A set can have a list of values. It is
defined with a curly braces and does
not support indexing.
38
Data Structures: Conversion
• int(): converts into an integer
• float(): converts into a float
• str(): converts into a string
• bool(): converts into a Boolean
• set(): converts values into a set
• list(): converts value into a list
• tuple(): converts value into a tuple
39
Python Operator
41
Practice!
42
Control Flow Statements
If statement
• If Statement: • If and else if statement:
if statement: if statement:
execute statement execute statement
• Indentation
• If else statement: elif statement: is important
execute statement • Sub if
if statement:
elif statement:
execute statement
execute statement
else:
else:
execute statement
execute statement 43
Control Flow Statements
Looping – for loop
for variable in sequence: For loops
statement
else: (optional-after finishing the loop it is executed)
statement sequencing
• Sequence:
• range() function
• Iterating on lists
• len() of a list codes
• for loop can be nested.
44
Control Flow Statements
Looping – while loop
while (condition): while loops
statement
else: (optional-after finishing the loop it is executed) False
statement condition
True
• while loop can be nested.
codes
45
Control Flow Statements
Loop control statement
• Break statement: it stops executing and moves to the first statement
after the look
• Continue statement: it skips all statement after ‘continue’. Then, it
shifts to the next item in the sequence.
• Pass statement: It is used when a statement is required syntactically
but you do not want any command or code to execute.
• All can be used with for or while loops.
46
Practice!
• If Condition
47
Practice!
• For Loop
48
Practice!
• While loop • Break
• Continue
• Pass
49
Input/Output Processing
• Very important feature • Use: os.chdir(‘C:\\...’) put path inside
where you want your files are.
• You can create, open, write, close a os.chdir('C:\\Users\\WIN 10\\Desktop’)
file. ls this allows you to see all files in
• First determine the path/change it the path
50
Input/Output Processing
• The key function is • The file can be handled as
open(filename,mode)
“t” – text
function. “b” – binary
• Four modes are available:
“r” – read • To open a file for (reading or
“a” – append writing)
“w” – write
“x” – create “+” – update the file
51
Practice!
52
Practice!
• To remove a file
import os
if os.path.exists(“myfile.txt"):
os.remove(" myfile.txt")
else:
print("The file does not exist")
53
Python – Function
• Block of organized and reusable code
• It is used to perform a single, related action.
• Built in function & user-defined function
• Syntax
def functionname( parameters ):
"function_docstring"
function_suite
return [expression]
54
Python – Function Practice
55
Introduction to PSS/E
• 40+ year industry “tool of reference” and data format for transmission studies.
• PSS/E is used in for electric transmission system analysis, operation and planning.
• Used by transmission planners, operations planners, consultants, and others.
• In over 115 countries worldwide.
• Fast and robust power flow solution for network models up to 200,000 buses.
• Lightning-fast steady-state contingency analysis.
• PV/QV analysis with plot generation.
• Full-featured Python API.
• Balanced and unbalanced fault analysis, contingency analysis.
• Modern graphical user interface.
• Comprehensive Library model (including FACTS devices, wind turbines).
• Code-based, user-written model building.
• Powerful, easy-to-use integrated plot facility.
56
PSS/E Program Overview
PSS/E Suite
Tools Bar
Tree View
Network Network
Spreadsheet Data Single line
View Diagram
Tree Tabs
Output
Data Window
Category
Status
Bar 58
PSS/E – Python Modules
• Be aware! In PSSE documentation we use module’s name and then
function – Ex
case: is a function to open a psse case in python.
Usage:
psspy.case(caseFileName)
Not:
case(caseFileName)
59
Interface with PSS/E
• Add PSSE-Python Modules path to Python
Environment
• Import sys module
• Find your psse python module path
• Use sys.path.append function to append system
environment with psse-python path
• Use os.environ['PATH'] = os.environ['PATH'] + ';’ +
pssp-python path
• Change default python directory to your
directory
• Import os module
• Use os.getcwd() to get the current directory
• Use os.chdir(str) to change to your working
directory
• Use os.listdir(str) to list all files or “ls” 60
In Practice
Define path
Import psspy
Initialize PSSE 62
Initialize through Ipython
63
Python in Windows
• Add Python to Windows Environmental Variables
• Go to system information
• Press Advanced system settings
64
Python in Windows
• Go to Advanced
• Press Environmental Variables
65
Because Anaconda
is already installed
66
PSS/E – Python Modules
1. psspy module: main API and has most api functions (Ch: 1-8)
2. pssarrays, pssexcel, excelpy, gicdata are data retrieval
modules (Ch: 9)
3. poly_print, pv_print, qv_print, setfullviewscale,
setfullviewgrapharea are modules interact with displays and
files associated with PSSE GUI (Ch: 10)
4. pssplot module manipulates plots in the screen (Ch: 11)
5. Non-Engineering Functions: alert, prompt, etc. (Ch: 12)
6. Event Study Modules (Ch: 13)
7. Other modules:
1. createusrdllw: Create a user dll for dynamics simulation. Combines
the traditional compile and cload4 processes in a more user-friendly
way.
2. excelexportw: Provides tools to export psse results to Excel, e.g., pv,
qv, and acc files.
3. n11analysisw: A prototype implementation of an N-1-1 analysis.
4. Plot2wordw: Provides tools to create Word documents from plots.
67
Other PSS/E – Python Modules
68
69
Third – Party Python Modules
• There are almost modules
• Machine Learning
• GUI
• Database
• Analysis
• Health
• Advanced Math
• Websites
• Software
• Gaming
• Advanced Plotting
• Web scraping
70
PSS/E - Python
Module 2
71
Agenda
• PSSE – Transmission Planning • Contingency Analysis
and Operation • N-1, N-1-1, N-2 Examples
• Power Flow Concept – • Node Breaker Topology
Applications and control
• Scipy & Numpy Modules
• Opening a Case
• Build a New Case
• Case Components: Busses,
Branches, and Machines
• Extract Data from Saved Case
72
PSSE – Transmission Planning and
Operation
Power System Planning, Stability,
PSS/E prog Operation, and Control
• Power flow and related network
functions
• One-line diagram
• Optimal power flow
• Fault Analysis
• Dynamic Simulation
• Linear Network Analysis
• Transmission Pricing and Open Access
• Network Equivalencing
• Program Automation
73
Power System
• A power system consists of typically:
• Generators
• Step-up/down transformers
• Transmission Lines
• Different types of load
• FACTS devices (SVC, STATCOM, …)
• Series and shunt devices (Capacitors,
Reactors,…)
• Buses (substations)
• Protection and Control Devices
• Communication (SCADA, Cloud)
74
Power System – Substations Rep.
• Bus Type Codes
Bus Type Description
Load bus: No generator connected, a disconnected generator may be located
Type 1
at the bus. Voltage control available only by transformers, generators at other
PQ Bus
buses, or static shunt device switching.
Type 2 Generator bus: Generator is both present and connected. Voltage may be
PV Bus controlled by the connected generator.
Swing bus: Voltage fixed in magnitude and phase. Generator must be present
Type 3
and is assumed to be connected.
Isolated bus: Present in system model but with all branches terminating on it
Type 4 out of service and no generator connected. Type 4 buses are ignored in all
solutions, output, and area or zone totalizations.
Same as Type 1, but located on the boundary of an area for which an
Type 5 equivalent is to be constructed. Type 5 buses are retained by the equivalent
construction process while Type 1 buses are deleted. 75
Power System – Generator Modeling
(Steady State)
Zsource=
• It is simply modeled by a voltage source R+jXL
behind impedance (𝑅 + 𝑗𝑋𝐿 ) with implicit
or explicit transformer impedance and Terminal
tap. Vsourse Voltage
77
Power System – Generator Modeling
(Steady State)
78
Power System – Transmission Line
• Overhead (OHTL) and Under-ground cable (UGC)
• Elements: R, X, and B
• Can be expressed in Ω or pu
• Zero impedance Lines can be used to model very
short lines, connection between buses,…
• PI equivalent circuit is used in OHTL PI equivalent circuit
• For UGC,
• Capacitance is high as conductor and sheath are close
to each other.
• Due to charging power, the length is very critical
parameter
79
UGC
Power System – Transformer
• Inductive equipment (R, XL).
• Capacitance is usually ignored except
for high frequency events (Lightning
strikes).
• Capacitance is used in
• Inter-turn (Low voltage different)
• Across transformer bushings (High
spacing)
• Magnetically coupled circuits between
windings (two or three)
80
Power System – Transformer
(Two & Three-Windings)
81
Power System – Load
• PSS/E Load Models are:
• Constant MVA (Constant Power): resistance can be adjusted to increase the
current inversely with voltage (Electronics devices with regulators)
• Constant Current: resistance can be adjusted with respect to voltage (Battery)
• Constant Admittance (Constant Resistance): current changes in proportion
with voltage (Heaters)
• Composite Load
82
Power Flow Analysis
• Steady-state analysis of a given power network
whose objective is to find all buses (nodes)
voltages (Magnitude and Phase), branch currents,
and real and reactive power flows in the network
under a given load conditions.
• The power system must operate:
• with no overloading of system components
(transmission lines, transformers)
• maintain acceptable voltage limits at all buses, and
• maintain generator reactive power outputs within an
acceptable limits.
• Power Flow Results are:
• Voltage magnitude and phase of all system buses
• Active and reactive power at all system branches
• Reactive power output of any generator that is not
already specified.
83
Power Flow Analysis
• Power Flow Problem is • PSS/E has the following
nonlinear and requires an algorithm built-in:
iterative method for solution. • Guise-Seidal
• Power Flow Algorithms: • Modified Guise-Seidal
• Newton-Raphson • Fully coupled Newton-Raphson
• Guise-Seidal • Decoupled Newton-Raphson
• Fast-Decoupled • Fixed slope Decoupled Newton
Raphson
• DC power flow
84
Power Flow Input/Output in PSS/E
Input Output
• The following are the basic known input data for
power flow calculations: • The magnitude of the voltage at every bus where
• Transmission line impedances and charging this is not specified in the input data.
admittances. • The phase of the voltage at every bus.
• Transformer impedances and tap ratios.
• The reactive power output of each plant for
• Admittances of shunt-connected devices such as which it is not specified.
static capacitors and reactors.
• Load-power consumption at each bus of the • The real power, reactive power, and current flow
system. in each transmission line and transformer.
• Real power output of each generator or generating
plant.
• Either voltage magnitude at each generator bus or
reactive power output of each generating plant.
• Maximum and minimum reactive power output
capability of each generating plant.
85
Opening a Case
• First go the directory where your files
& startup file is
E:\SEC-PSSE-Python-Training\Training
Materials\codes
• Execute ‘startup.py’
86
Opening a Case
• psspy.case(caseFileName)
• Case file should be in the directory
• Or specify the location
• For ex:
casefilename = ‘C:\Program Files
(x86)\PTI\PSSE33\EXAMPLE\savnw.sav’
87
Power Flow – Applications and
Control
Method PSS/E Function
Guise-Seidal SOLV()
Modified Guise-Seidal MSLV()
Fully coupled Newton- FNSL()
Raphson
Decoupled Newton- NSOL()
Raphson
Fixed slope Decoupled FDNS()
Newton Raphson
89
Extract Data from Saved Case:
Summery
• List all buses psspy.alph(0,1)
• List power flow data
psspy.list(0,1,opt,0)
• Opt (case summery,plant data,
branch data, …)
90
Extract Data from Saved Case:
Busses
• Buses psspy.list(0,1,2,0)
91
Extract Data from Saved Case:
Branches
92
Extract Data from Saved Case:
Machines
93
Extract Data from Saved Case:
CASPY Module
• CASPY is a module that can create
an object, which is the case file.
• From this object, you can return
arrays of data.
• The object will have many
dictionaries contain information
about the case file.
• The object is created using:
• Savecase (Case sensitive)
94
Extract Data from Saved Case:
CASPY Module
95
Contingency Analysis
• We use linear network functions to prepare files used to develop the
distribution factor file setup (DFAX) in order to conduct contingency
analysis.
• DFAX file can be used with other activities Calculating Distribution Factors
(OTDF), Linearized Network Contingency (DCCC), Transmission Transfer
Limit Analysis (TLTG), …
• Sometimes, it may be easier to conduct it the hard way.
• To setup DFAX, we need the following inputs:
• Subsystem Description Data file; relevant subsystems of the working case are
specified in this *.sub file.
• Monitored Element Data file; network elements to be monitored for problems are
specified in this *.mon file.
• Contingency Description Data file; contingencies to be tested are specified in this
*.con file.
96
Contingency Analysis
psspy.dfax_2([1,1,0],r"""E:\SEC-PSSE- Create DFAX File
Python-Training\Training
Materials\codes\savnw.sub""",r"""E:\SEC- SUB MON CON
PSSE-Python-Training\Training
Materials\codes\savnw.mon""",
r"""E:\SEC-PSSE-Python-Training\Training DFAX
Materials\codes\savnw.con""",r"""E:\SEC-
PSSE-Python-Training\Training
Materials\codes\savnw.dfx""")
psspy.otdf(r"""E:\SEC-PSSE-Python- Tabulates
Training\Training Distribution
Materials\codes\savnw.dfx""")
Factors
97
Contingency Analysis
• psspy.accc_with_dsp_3(
0.5,[0,0,0,1,1,2,0,0,0,0,0],r""" Run AC
EAST""",r"""E:\SEC-PSSE- Contingency
Python-Training\Training
Materials\codes\savnw.dfx"" Analysis
",r"""E:\SEC-PSSE-Python-
Training\Training
Materials\codes\output.acc"
"","","","")
98
Contingency Analysis
Create DFAX File
Perform ACCC
99
N-1, N-1-1, N-2 Examples
N-1: Transmission Line
psspy.case(r"""E:\SEC-PSSE-Python-Training\Training
Materials\codes\savnw.sav""")
psspy.fnsl([0,0,0,1,1,0,99,0]) N-1-1: Transmission Line & Transformer
psspy.branch_chng(151,152,r"""1""",[0,_i,_i,_i,_i,_i],[_ psspy.case(r"""E:\SEC-PSSE-Python-Training\Training
f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f]) Materials\codes\savnw.sav""")
psspy.fnsl([0,0,0,1,1,1,99,0]) psspy.fnsl([0,0,0,1,1,0,99,0])
psspy.branch_chng(151,152,r"""1""",[0,_i,_i,_i,_i,_i],[_f,_f,
N-2: Transmission Lines _f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f])
psspy.case(r"""E:\SEC-PSSE-Python-Training\Training psspy.fnsl([0,0,0,1,1,1,99,0])
Materials\codes\savnw.sav""") psspy.two_winding_chng_4(3001,3002,r"""1""",[0,_i,_i,_i,
psspy.fnsl([0,0,0,1,1,0,99,0]) _i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_
psspy.branch_chng(151,152,r"""1""",[0,_i,_i,_i,_i,_i],[_ f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f],["",""])
f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f]) psspy.fnsl([0,0,0,1,1,1,99,0])
psspy.branch_chng(151,152,r"""2""",[0,_i,_i,_i,_i,_i],[_
f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f])
psspy.fnsl([0,0,0,1,1,1,99,0])
100
Node Breaker Topology (not available
in PSS/E 33 and older)
• Bus-Branch Model: represent each substation with a single bus (node) with
nominal voltage level.
• Substation configuration
• 1 ½ breaker, double breaker, ring bus, etc.
• It is not represented directly
• To account for a large number of contingencies, manual modification is
created to account for bus and breaker contingencies.
• A better solution is node breaker modeling technique.
• It requires remodeling stations into node-breaker topology from the normal
Power flow bus-Branch configuration.
• Note that
• Bus-branch model to node-breaker conversions require creation and maintenance of a
mapping of each station into its constituent elements.
• The conversion is merely a reduction of zero-impedance elements into the resultant
buses 101
Node Breaker Topology: Ex 1
How is outage of Line
A modeled?
• Planning Model
• Open Line A
• Actual System
• Open breakers a1, a2, and b1
• Assuming all breakers have same
status as original configuration
from which planning case was
created, then this is a correct
simulation in planning case
102
Node Breaker Topology: Ex 1 (What
is Breaker a4 is out for Maintenance)
Bus-Branch
Model
Node-Breaker
Model 105
PSS/E and Node-Breaker
Substation/Node/Bus Mapping
106
PSS/E and Node-Breaker
Branch Mapping
Bus-Branch Model
Node-Breaker Model
Connection Record Format for All Device Types: (I, ID, NI)
108
PSS/E and Node-Breaker: Mapping Ex
109
PSS/E and Node-Breaker
Node-Breaker
menu
Create 1 ½
substation
110
PSS/E and Node-Breaker
psspy.station_build_config(152
,2,r"""test 2""",4)
psspy.growstation(2)
111
Scipy, Numpy, Matplotlib, Sympy &
pandas Modules
• What is SciPy? SciPy is a free and open-source Python library used for
scientific computing and technical computing. SciPy contains modules for
optimization, linear algebra, integration, interpolation, special functions, FFT,
signal and image processing, ODE solvers and other tasks common in science
and engineering.
• What is NumPy? NumPy is a library for the Python programming language,
adding support for large, multi-dimensional arrays and matrices, along with
a large collection of high-level mathematical functions to operate on these
arrays.
• What is Matplotlib? it is a plotting library for the Python programming
language and its numerical mathematics extension NumPy.
• What is Sympy? it is a Python library for symbolic computation.
• What is Pandas? It is a software library written for the Python programming
language for data manipulation and analysis.
112
Scipy & Numpy Modules
113
PSS/E - Python
Module 3
114
Agenda
• Retrieve PSS/E System Data & Steady State Results
• Export System Data & Results to Microsoft Excel
• Data Import from Microsoft Excel/Notepad into PSS/E
• System Data & Results Custom Reporting
• PSS/E Integration with MS suites (Excel, Word, Access)
• Short Circuit Applications and Control
115
Data Retrieval
• Data Retrieval from PSS/E case is
the first step toward further
analysis
• Chapter 7, 8, and 9 in API include
• Single Element Retrieval Functions
• Subsystem Retrieval Functions
• Results data Retrieval Functions
• No way to record these routines
116
Data Retrieval:
Single Elements (API Ch.7)
• These functions retrieve data belong ardat(): Return Area Totals: Load,
Gen, Loss,…
to: bus, branch, area, zone, FACTS,
shunt, plant output, load quantities,…
• Retrieve results: Power flow, case
solved, system mismatch
brndat(): Return Real Branch Data:
• Some famous functions: ardat(),
Rate (A,B,C), Length,…
brndat(), busdat(), busexs(), solved(),
sysmsm(), sysmva(),
117
Data Retrieval:
Single Elements (API Ch.7)
busdat(): Return Real Bus Values (pu, sysmva(): Return total system base (MVA)
KV, Angle, …)
118
Data Retrieval:
Subsystem (API Ch.8)
• Subsystem data retrieval routines are used to get data
from PSS/E Engine for elements (buses, branches,
etc.) in a subsystem.
• Divided by elements (Buses, plants, machines, load,
shunts, …)
• These APIs are grouped into families with each family
containing up to six APIs:
Returns number of
Returns an array of Returns an array of one or
array entries required
one or more sets of more sets of Real data
aBusCount,
Integer data values values
aMachCount …
Returns information on
Returns an array of Returns an array of
the data types related to
one or more sets of one or more sets of
specified STRING values
Complex data values Character data values 119
aBusTypes(), aMachTypes()
Data Retrieval:
Subsystem (API Ch.8)
• Some examples of Subsystem Data Retrieval
aBusCount(): Returns number of array entries required
aBusInt(): Returns an array of integer values for
subsystem buses
aBusReal(): Returns an array of real values for
subsystem buses.
aBusCplx(): Returns an array of complex values for
subsystem buses
aBusChar(): Returns an array of character values for
subsystem buses.
aBusTypes(): Returns an array of character values
indicating the data types
120
Results Retrieval/Export: (API Ch.9)
• These routines are concerned with retrieving results from PSS/E
engine.
• You can post process the output of these routines and create custom.
• They are not member of psspy module
• PSSARRAYS module
• PSSEXCEL module
• EXCELPY module
• GICDATA module (Geomagnetically Induced Current)
121
Results Retrieval/Export: (API Ch.9)
• PSSARRAYS module: provides
Python functions to retrieve
PSS/E solution results in
arrays.
• 17 useful routines.
ACCC_SUMMARY(): Returns AC Contingency monitored
element labels, contingency labels etc.
ACCC_SUMMARY_REPORT(): Generates text report of
lists returned by accc_summary
122
Results Retrieval/Export:
• PSSEXCEL module: provides
Python functions to export
PSS/E data or solution results
to Excel spreadsheets.
• 4 routines
123
Results Retrieval/Export:
• Another way to export data is using
• excelexportw module
124
Results Retrieval/Export:
• EXCELPY module: provides Python functions
to interface with Excel.
• This module is used to create, populate and
format Excel workbooks from Python.
125
Practice!
• Get data and export them to Excel
126
Practice!
• Read from excel sheet using excelpy
127
Results Retrieval/Export:
• GICDATA module: provides functions to create GIC data file required
in GIC analysis.
• This module has functions to create GIC data file applicable to a
specific Power Flow Network Case
128
PSS/E Integration with MS suites
(Excel, Word, Access)
• WORDPY module: This module is mainly created to add plot files
(.eps, .png, .wmf etc.) created by PSSPLT/PSSPLOT to existing or new
Word files.
• Use PSSPLT to create .eps files, and PSSPLOT to create .wmf files. Then
use this Python module to create Word document from those files.
129
Short Circuit Calculations
• The goal of SC analysis is to ensure CBs
ratings can withstand any type of fault
currents.
• It is based on a symmetrical component
system representation.
• Positive sequence ,model of the system is
used in the fault analysis.
• Fault Types: Balanced Faults (3-phase) and
unbalanced faults(SLG, LLG,L-L, Open Line)
• Worst case, 3-phase directly at the bus.
• Majority of faults are Unbalanced.
130
Short Circuit Calculations
• Symmetrical component system representation is a mathematically
based technique that is used to analyze fault currents.
• It is used to generate three balanced subsystems (Positive, Negative,
and Zero) sequences.
• Phase (actual balance/unbalance) = Positive + Negative + Zero
131
Sequence Impedance
• The impedance encountered by the symmetrical components
depends on the type of power system equipment, i.e., generator,
transformer or transmission line.
• Zero sequence impedances of overhead lines depends on the
presence of ground wires, tower footing resistance and grounding.
• The line capacitance of overhead lines is ignored in short-circuit
calculations.
132
Short Circuit Modeling
• SC calculations in PSS/E
is complied with IEC
60909, 2001 standard
133
Short Circuit Applications and
Control
PSSE
It is intended for the more routine
detailed analysis of complicated work of examining simple ground
unbalanced situations faults at a large number of system
locations
RESQ Reads fault analysis data into working case. RESQ Reads fault analysis data into working case.
SQLI Lists fault analysis data from working case. SQLI Lists fault analysis data from working case.
SQEX List fault analysis data at a bus. SQEX List fault analysis data at a bus.
SQCH Changes fault analysis data in working case. SQCH Changes fault analysis data in working case.
Prepares detailed positive-, negative-, and zero-sequence Converts generators to t+ sources using impedance, ZSORCE,
SEQD CONG to characterize generators.
network models for interconnection and solution.
Converts generators to t+ sources using impedance, ZPOS, to
Interconnects and solves three sequence networks under CONG,SQ characterize generators.
SCMU
unbalanced conditions.
Automatically sequences fault analyses over all buses in a 134
SCOP Detailed output of unbalanced system conditions. ASCC specified subsystem, for L-G and three-phase faults only.
Short Circuit Applications and
Control
• SEQD(): Prepare sequence networks (Positive,
negative, and zero) for unbalanced fault
calculations.
• SCMU(): Solve the sequence networks under
unbalanced condition.
• SCOP(): Shows output of all (branch currents, bus
voltages, apparent impedances/admittances)
• FLAT(): Classical Fault Analysis
• IECS(): Calculates Fault Currents according to IEC
60909 Standard
135
Short Circuit Applications and
Control
• IECS(): Calculates Fault Currents according to IEC
60909 Standard
• SC calculation assumptions are:
• Fault→IEC60909FaultCalculation
• Shunt option: Set shunt to zero in pos. sequence
• Line charging: Set line charging to zero in all sequences
• Set tap ratios to Unity
• Breaker contact parting time in seconds (according to
voltage level)
• SelectvoltagefactorC→specified→1.1
• The breaker contact parting time in seconds (brktime):
• 380kV:33ms(2cycles)
• 230/132/115/110kV:33ms(2cycles)
• 33/13.8kV:50ms(3cycles)
136
PSS/E - Python
Module 4
137
Agenda
• Plotting dynamic simulation results
• Principles of Power System
Dynamics • Use of various Modules (bsntools,
dyntools, sliderpy, wordpy)
• Introduction of Dynamic • Automating PSS/E execution with
Simulation using PSS/E maximum flexibility through Python
• Retrieving/Manipulating Dynamic scripts
Model data
• Dynamic simulation using python
• Monitoring a specific channel
during Dynamic simulation and Duval 500KV bus
59.95
59.9
0 0.5 1 1.5 2 2.5
Time (sec)
3 3.5 4 4.5 5
138
Principles of Power System
Dynamics
• Saudi Power Grid consists of many individual
elements connected together to form a large,
complex and dynamic system.
• This network is capable of generating, transmitting,
and distributing electrical energy over a very large
geographical area.
• It is an interconnected system of many operating
areas and GCC countries, which would cause
dynamical interactions.
• Dynamic interaction is mainly caused by:
• Changing power demand: small scale (Small Signal) or
• Disturbances: Fault, loss of load, loss of generating unit.
• Due to change, the system states are perturbed and
undergo transient until anther stable system states
are reached.
139
Power System Stability
• Power system stability is the ability of
an electric power system, for a given
initial operating condition, to regain a
state of operating equilibrium after
being subjected to a physical
disturbance, with most system
variables bounded so that practically
the entire system remains intact
140
Power System Stability
• Rotor angle stability refers to the ability of synchronous machines of an
interconnected power system to remain in synchronism after being subjected to a
disturbance.
• Rotor angle instability occurs due to angular swings of some generators leading to
their loss of synchronism with other generators.
• Depend on the ability to maintain/restore equilibrium between electromagnetic
torque and mechanical torque of each synchronous machine.
• At equilibrium, input mechanical torque equals output electromagnetic torque of
each generator. In case of any disturbance, the above equality doesn’t hold leading
to acceleration/deceleration of rotors of machines.
• It is useful to characterize rotor angle stability to:
• Small-disturbance (or small-signal) - damping of oscillations – Linearization of system equations
is acceptable – 10-20 seconds
• Large-disturbance - short circuit - Linearization of system equations is NOT acceptable – 3-5
seconds
141
Power System Stability
• Voltage stability refers to the ability of a power system to maintain steady
voltages at all buses in the system after being subjected to a disturbance
from a given initial operating condition.
• A system is voltage instable if for at least one bus in the system, the voltage
magnitude decreases as reactive power injection is increased.
• Large scale effect of voltage instability leads to voltage collapse. It is the
process by which the sequence of events accompanying voltage instability
leads to a blackout or abnormal low voltages in a significant part of the
power system.
• The driving force for voltage instability is usually loads.
• It can be characterized by:
• Small-disturbance - small perturbations such as incremental changes in system load
• Large-disturbance - system faults or loss of generation
142
Power System Stability
• Frequency stability refers to the ability of a power system to maintain
steady frequency following a severe system upset resulting in a
significant imbalance between generation and load.
• Frequency instability leads to tripping of generating units or loads or
both.
• Could be short term or
• Long term phenomenon
P. Kundur et al., "Definition and classification of power system stability IEEE/CIGRE joint task force on stability terms and definitions,"
in IEEE Transactions on Power Systems, vol. 19, no. 3, pp. 1387-1401, Aug. 2004. 143
PSS/E Data Structure in Dynamic
Modeling
• Constants: parameters that do not vary during the simulation.
• State Variables: quantities for which the instantaneous values are determined by
differential equations.
• Algebraic Variables: quantities for which the values at any instant can be determined if all
state variables and constants are known.
• Input Variables: quantities for which the values at any instant are specified by logic
outside of the dynamic simulation.
• In addition, there are four large general purpose storage arrays:
• CON: Contains constants.
• STATE: Contains state variables.
• VAR: Contains algebraic variables.
• ICON: Contains integer quantities which may be either constants or algebraic variables.
Corresponding to each ICON is an entry in the CHRICN array which may contain character
quantities.
Refer to Table 19.1 (Dynamic Simulation Arrays)
144
PSS/E Generator Dynamic Models
• Generator Models are classified as the following:
• Machine/Generator Models
• Speed Turbine/Governor Models
• Excitation System Models
• Power System Stabilizer (PSS)
Models
• Models Refer to Model Library
& PAV 2.
145
PSS/E Generator Dynamic Models
• Generator/Machine Models
• GENCLS: Classical Generator
Model
• Constant Voltage behind
transient reactance
Transient OR
Subtransient
Reactance
146
PSS/E Generator Dynamic Models
• GENROU is used at SEC. 1 2
5
147
PSS/E Turbine/Governor Dynamic
Models
• Model Library Ch.7 & PAG V2 Ch.17
• PSS/E models represent principle
effects inherent in conventional
steam turbine, gas turbine, nuclear,
and hydro plants.
GAST Gas turbine-governor model
GAST2A Gas turbine-governor model
GGOV1 GE general purpose turbine-governor model
HYGOV Hydro turbine-governor model
HYGOV2 Hydro turbine-governor model
IEEEG1,G2,G3 1981 IEEE type 1, 2, 3 turbine-governor model
TGOV1 Steam turbine-governor model
148
PSS/E Turbine/Governor Dynamic
Models
1 2
6
149
PSS/E Excitation System Dynamic
Models
• Model Library Ch.6 & PAG V2 Ch.16
• The excitation system in all cases consists of
• a high power source of direct current,
• an intermediate power level controlling circuit, and
• an instrument power level voltage regulator.
• Mainly two different excitation systems:
• DC excitation systems: old
• AC excitation systems: New
ESDC1A 1992 IEEE type DC1A excitation system model
ESST4B IEEE type ST4B potential or compounded source-controlled rectifier exciter
EXAC1A Modified type AC1 excitation system model
EXPIC1 Proportional/integral excitation system model
EXST1 1981 IEEE type ST1 excitation system model
EXST2 1981 IEEE type ST2 excitation system model
150
SEXS Simplified excitation system model
PSS/E Excitation System Dynamic
Models
1
2
5 151
PSS/E PSS Dynamic Models
• Model Library Ch.3 & PAG V2 Ch.16.7
• Excitation systems with high transient gain
and small time constants tend to reduce the
damping of generator rotor angle oscillations.
• So, supplementary stabilizing signals are
needed.
153
PSS/E Dynamic Simulation
• The objective in performing a dynamic simulation
of a physical system is to determine the response
of the system to prescribed stimuli.
• At an instant in time T, it is known "where you
are". From "where you are" and the differential
equations describing the behavior of the system,
it can be determined "where you’re going". Then
"go there", advance time to T+t (where t is the
time step or integration step), and run it again.
• To run dynamic simulation in PSS/E, you need to
have a knowledge of dynamic modeling structure.
154
Data Space Allocation in PSS/E
• Specific arrays are used to link
model internally and with other
models.
• Refer to table 19.1 in POM
155
PSS/E Dynamic Simulation
Procedure
• the system model for dynamic simulation calculations in
PSS®E is comprised of:
1. The power flow working case. A standard power flow case STRT()
must be augmented by the machine impedance
characteristic data MBASE, ZSORCE, XTRAN and GENTAP,
and the load and generator representations must be
converted from their power flow modeling to that required
by the dynamic simulation activities
2. Dynamics data working memory which includes:
a) the constants associated with equipment models from the
PSS®E Model Library and user-written models which are to be
used in modeling the system; and
b) the model connection table arrays defining the model RUN()
connection and data array entries associated with plant-related,
load-related, line relay, auxiliary signal, FACTS devices, dc line,
and switched shunt models.
3. A set of connection subroutines, CONEC and CONET, which
link together equipment models and their data with
network elements. 156
PSS/E Dynamic Simulation Flow
157
PSS/E Dynamic Simulation
159
Practice!
• Open .sav, .dyr
This function
• ierr, ival = will return CON
psspy.mdlind(101,'1','GEN','CON’) index
161
Dynamic Simulation using Python
Practice!
Results Folder
162
Dynamic Simulation using Python
Practice! Results Folder
File is being
executed
163
Monitoring a specific channel during
Dynamic simulation and taking decision
based on its value
• This is can be done through two ways:
1. User-defined model: use conec & conet files to create .dll file.
2. Hard code in python: Tedious and not professional.
• If the event time is know: first determine it and run the simulation to that point of time
• If the event time is not known:
run the simulation for one time step
check for the event
rerun for one more time step
164
Plotting dynamic simulation results
• Plotting can be done using the Interface (GUI)
• pssplot module can be invoked via python but interface should be
displayed. Otherwise, pssplot functions wont work.
• Another way of plotting PSSE results is to use other mean of plotting
programs of .xlsx or .txt files generated after the results are done.
• Program: matlab, matplotlib: plot lib. that very similar to matlab – very
powerful
165
Matplotlib
• Python 2D plotting
package – object oriented
library.
• Produces publication
quality figures.
• pyplot is a module
provides functions pretty
similar to Matlab.
166
Use of various Modules (bsntools,
dyntools, sliderpy, wordpy)
• bsntools: it is a bus renaming module
• dyntools: Tools for processing channel output files, including export
to Excel.
• sliderpy: Provides functions to directly manipulate diagram elements
• wordpy: Provides Python functions to interface with Microsoft Word.
167
Automating PSS/E execution with
maximum flexibility through Python
scripts
• Project Last 2 hours of Thursday Session
• Use any .sav & .dyr of a network you have
• Develop a vector of events for load increment at a specific bus:
by 50%, 100%, 200%, 400%, 800%
• Start the simulation, apply the event, then run for up to 20 sec.
• Record results for buses voltages and branches P&Q for every
event
• Produce excel files or text files and plot the results in .emf
format.
• Then produce word file with all figures in it
168
PSS/E - Python
Module 5
169
Agenda
• Create looping scripts though a
network element
• PSS/E Input Files
• Advanced python applications
• Advanced python features
• Interacting with host operating
system
• User-defined Model
• Build simple GUI application using
wxpython
• References
• Last words
170
PSS/E Input Files
• PSS/E can deal with several
forms of input/output files
• By far:
• Python files
• .dll files (user defined models)
are most used to control PSS/E
operation
171
Advanced Python
Applications/Topics
• Data science, analytics, and machine learning
• NumPy, Pandas, Seaborn , Matplotlib , Plotly , Scikit-
Learn , Machine Learning, Tensorflow
• Operation Research
• scipy.optimize, cplex, gurobi, statistical models,
forecasting
• Power Systems
• Pypsa, Mosaik is a simulation compositor for Smart
Grid simulations, Cyme
• Communication & Internet
• Twilio SMS, email, twitter
172
Advanced python features
• Python has advanced features.
• Not every language have them.
• These features are usually used for advanced applications,
programs, and packages.
• We will discuss: iterators, generators, and decorators
173
iterators
• What’s happening behind for loop example
• Iterators: it has a next method, which, when
called, returns the next item in the sequence,
and when there’s nothing to return, raises
the StopIteration exception.
174
generators
• A third way to create iterator objects is to call a
generator function.
• It is a function that produces a sequence of
results instead of a single value.
• A generator is a function containing the
keyword yield.
• When next is called, the function is executed
until the first yield. Each
encountered yield statement gives a value
becomes the return value of next. After
executing the yield statement, the execution of
this function is suspended.
175
decorators
• Since functions and classes are objects, they
can be passed around.
• Since they are mutable objects, they can be
modified.
• The act of altering a function or class object
after it has been constructed but before it is
bound to its name is called decorating.
@decorator
def function():
pass
def function():
pass
176
function = decorator(function)
Interacting with host operating
system OS Module
• The os module in python provides functions for interacting with the
operating system.
• Get current directory: os.getcwd(), os.path.abspath(‘.’)
• Get files at directory: os.listdir(‘.’)
• Change to ‘path’: os.chdir(path), like cd path in ipython
• Remove file path: os.remove(path)
https://docs.python.org/2/library/os.html
177
Interacting with host operating
system sys Module
• System version: sys.version
• Get all loaded modules: sys.modules
• Get all added paths: sys.path
• Exit from interpreter: sys.exit
https://docs.python.org/2/library/sys.html
178
User-Defined/Written Model
• You need: Intel Visual Fortran Compiler 12 or more
• Check PSS/E Installation Guide
179
User-Defined/Written Model
• POM 1.3: Extending PSS/E with user DLLs – including new model dll in
PSS/E loading path.
• POM 1.4: Create dll file
• POM 4.10: six user model calling routines, USRXXX, USRLOD, USRREL,
USRAUX, USRDCL, and USRFCT are required for the calling of user-written
plant, load, line relay, auxiliary signal, dc line, and FACTS device models,
respectively
• POM Ch.15.1.1 p. 1172 - CONEC & CONET Models (Format) in .dyr file
• POM Ch.19.1.1 Program Structure
• POM Ch.19.9 Example of CONEC & CONET file model
• POM Ch.21: Model Writing
• PAG V2 Ch.23: Codes for most of transfer function blocks.
180
Build simple GUI application
• Several Packages are available
• wxPython
• PyQT
• PyGUI
• Tkinter – Standard GUI package.
• PySide
https://wiki.python.org/moin/GuiProgramming
181
References
• PSS/E Documentation
• Python online documentation - https://docs.python.org/2/index.html
• Python books: python in a nutshell, learning python, …
• Power system books: modeling and analysis.
• https://psspy.org/psse-help-forum/questions/
• https://stackoverflow.com/
182
Last
Words!
183