See discussions, stats, and author profiles for this publication at: https://www.researchgate.
net/publication/255685748
Python for Power Systems Computation
Conference Paper · April 2013
CITATIONS READS
0 4,639
2 authors:
Prabakaran Santhanam Prabakaran s.
Valliammai Engineering College SASTRA University
1 PUBLICATION 0 CITATIONS 4 PUBLICATIONS 3 CITATIONS
SEE PROFILE SEE PROFILE
Some of the authors of this publication are also working on these related projects:
refrigeration View project
All content following this page was uploaded by Prabakaran Santhanam on 16 May 2014.
The user has requested enhancement of the downloaded file.
Proceedings of 3rd National Conference on Emerging Technologies in Electrical and Electronics Engineering (NCEEE-2013)
26th April 2013
Python for Power Systems Computation
Prabakaran. S
M.E., Power Systems Engineering, Valliammai Engineering College, Chennai, India
[email protected] Abstract—Power Systems computation which were being Octave[14]. Python is inherently object oriented. Almost
computed so far using MATLAB, OCTAVE and other closed everything is an object: strings, lists, dictionaries, tuples,
software packages could be solved using Python. There are functions, classes, and more. The implied usefulness is that
various open source tools available which along with Python these things each have their own members and methods that
could be used to solve complex power system problems. Python
encapsulate its functionality and information. To get
with simple and easy to learn syntax along with its power of
being a general purpose scripting language enables engineers and functionalities of MATLAB and Octave in Python, the NumPy,
researchers to solve complex problems interactively. They could SciPy and Matplotlib packages should be used. Scipy is a
develop their own software package either an open source or package that has the goal of providing all the other
even commercial software without any permissions from Python. functionality of MATLAB, including those in the MATLAB
A test case was conducted using an IEEE 14-bus system in which toolboxes. There are also a handful of IDE's available for
the small signal stability analysis is performed using Python and Python, most of which are for free.
it is compared with MATLAB and OCTAVE. Because Python is open and free, it is very easy for other
parties to design packages or other software tools that extend
Index Terms—Python, tools, power system computations, open
source, NumPy, SciPy, Matplotlib, CVXOPT.
Python. It is possible to create applications using any of the
major GUI libraries[1] (TK, WX, GTK, QT ...), use OpenGL,
I. INTRODUCTION drive your USB port, etc. Another example is Pyrex/Cython to
In general, Power System design, analysis and control enhance the speed of algorithms by converting Python to C
involve complex mathematical computations exhibiting code, and py2exe and the like to create a standalone application
exhaustive nature. Because of its exhaustive nature it became a from the source. Also the system programming languages are
hardball for scientists and engineers to solve power system not much faster than efficient scientific scripting languages.
problems, even using computer. This is the reason that most of However, scripting languages do not perform
the power system engineers and researchers use a commercial directly heavy mathematical operations, butcall efficient
software package like MATLAB which is a closed software FORTRAN or C-based libraries. The proposed system for
package. studying a Power System through Python (open software
However, there are also freely-distributed projects but package) is shown in Fig. 1. Thus, the main conclusion is that
whose source code is not provided or, if provided, is the interfaces that link scripting languages with external
too complicated to be mastered in a reasonable time. As it can compiled libraries are quite efficient.
be promptly observed, closed software packages embed and II. AVAILABLE TOOLS FOR POWER SYSTEM COMPUTATION
mask the most interesting parts, i.e., the modelling and
computer implementation phases. There are at least two There are a large number of modules of the libraries
important drawbacks in this approach. The first one is that the available to Python for Power System computations. Also,
user has to accept the hypotheses and simplifications used by there is an advanced Python shell, IPython[2], developed
the authors of the software package. The other one is that the specifically for scientific computing.
user often ignores the hypotheses and simplifications used by Below are the most potential modules including NumPy[8],
the authors of the software package. A byproduct drawback is SciPy[10], Matpltotlib[11], CVXOPT[12], Pylon,
also the absent or reduced possibility of modifying the PyPower[13], Minpower[3] that are standard libraries which
equations and of replacing the algorithms used by the could be used for Power System computations.
software package. A. NumPy
Clearly, the main advantage of using a closed software
The Numeric Python extensions (NumPy) is a set of
packages is to save time. For well-assessed and repetitive
extensions to the Python programming language which allows
operations, such as most industry applications, it is also the
correct approach. On the other hand, the educational weakness
of closed software is evident. The user gives up the possibility
of thinking in exchange for setting up input data and
adjustments. It has to be noted that setting up a set of
data without having the control or the full knowledge of the
model can lead to unpredictable results.
Python is a safely, dynamically and strongly typed open
source language which can be competitive with MATLAB and
ISBN 978-81-926837-2-0
202
Proceedings of 3rd National Conference on Emerging Technologies in Electrical and Electronics Engineering (NCEEE-2013)
26th April 2013
easily describe numerical problems using high-level code,
thereby opening the door to scientific code that is both
transparent and easy to maintain.
B. SciPY
SciPy is a collection of mathematical algorithms and
convenience functions built on the Numpy extension for
Python. It adds significant power to the interactive Python
session by exposing the user to high-level commands and
classes for the manipulation and visualization of data. With
SciPy, an interactive Python session becomes a data-
processing and system-prototyping environment rivaling
sytems such as MATLAB, IDL, Octave, R-Lab, and SciLab.
The additional power of using SciPy within Python,
however, is that a powerful programming language is also
available for use in developing sophisticated programs and
specialized applications. Scientific applications written in
SciPy benefit from the development of additional modules in
numerous niche‘s of the software landscape by
developers across the world. Everything from parallel
programming to web and data-base subroutines and classes
have been made available to the Python programmer. All of
this power is available in addition to the mathematical libraries
in SciPy.
Fig. 1. Approach for studying a system using Python SciPy makes it easy to integrate C code, which is essential
Python programmers to efficiently manipulate large sets of when algorithms operating on large data sets cannot be
objects organized in grid-like fashion. These sets of objects are vectorized. The universality of Python, the language in
called arrays, and they can have any number of dimensions: which SciPy was written, gives the researcher access to a
one dimensional arrays are similar to standard Python broader set of non-numerical libraries to support GUI
sequences, two-dimensional arrays are similar to matrices from development, interface with databases, manipulate graph
linear algebra. structures, render 3D graphics, unpack binary files, etc.
Anything that can be done in NumPy could also be done in Python‘s extensive support for operator overloading makes
standard Python – we just may not be alive to see the program SciPy‘s syntax as succinct as its competitors, MATLAB,
finish. A more subtle reason for these extensions however is Octave, and R. More profoundly, we found it easy to rework
that the kinds of operations that programmers typically want to research code written with SciPy into a production application,
do on arrays, while sometimes very complex, can often be de- deployable on numerous platforms.
composed into a set of fairly standard operations. This C. CVXOPT
decomposition has been developed similarly in many array
CVXOPT is a free software package for convex
languages. In some ways, NumPy is simply the application of
optimization based on the Python programming language. It
this experience to the Python language – thus many of the
can be used with the interactive Python interpreter, on the
operations described in NumPy work the way they do because
command line by executing Python scripts, or integrated in
experience has shown that way to be a good one, in a variety of
other software via Python extension modules. Its main purpose
contexts. The languages which were used to guide the
is to make the development of software for convex
development of NumPy include the infamous APL family of
optimization applications straightforward by building on
languages, Basis, MATLAB, FORTRAN, S and S+, and
Python‘s extensive standard library and on the strengths of
others[4]. This heritage will be obvious to users of NumPy who
Python as a high-level programming language.
already have experience with these other languages.
CVXOPT extends the built-in Python objects with two
When NumPy is skillfully applied, computation time is
matrix objects: a matrix object for dense matrices and
primarily spent on vectorized array operations instead of in
a spmatrix object for sparse matrices. Also an API can be used
Python for loops (which are often a bottleneck). Further speed
to extend CVXOPT with interfaces to external C routines and
improvements are achieved using optimizing compilers, such
libraries. A C program that creates or manipulates the dense or
as Cython, which allow better control over cache effects. In
sparse matrix objects defined in CVXOPT must include
addition to low-level array operations, NumPy provides sub-
the cvxopt.h header file in the src directory of the distribution.
packages for linear algebra, FFTs, random number generation,
The best part about CVXOPT is that the matrices from
and polynomial manipulation. Larger scientific packages,
NumPy arrays and CVXOPT are compatible and both these
such as SciPy, are, in turn, built on this infrastructure. NumPy
and similar projects foster an environment in which users can packages could exchange information using the array interface.
ISBN 978-81-926837-2-0
203
Proceedings of 3rd National Conference on Emerging Technologies in Electrical and Electronics Engineering (NCEEE-2013)
26th April 2013
For example, in NumPy the matrices could be created from a DC and AC optimal power flow and
CVXOPT matrix using the array() method.
>>> from cvxopt import matrix
>>> from numpy import array
>>> A = matrix([[1,2,3,4,5],[6,7,8,9,0]])
>>> print(A)
[ 1 6]
[ 2 7]
[ 3 8]
[4 9]
[5 0]
>>> B = array(A)
>>> B
array([[1, 4],
[ 1 6]
[ 2 7]
[ 3 8]
[4 9]
[5 0]])
>>> type(B)
<type 'numpy.ndarray'>
Similarly a CVXOPT matrix could be created from a
NumPy array using the matrix() method as follows.
Fig. 2. TEX Rendering in plots using Matplotlib
>>> C = matrix(B)
>>> type(C) PSS/E, MATPOWER and PSAT case serialization
<type 'cvxopt.base.matrix'> and de-serialization.
D. Matplotlib F. Minpower
Matplotlib is a library for making 2D plots of arrays in Minpower is an open source toolkit for students and
Python Although it has its origins in emulating the MATLAB researchers in power systems optimization. The toolkit is
graphics commands, it is independent of MATLAB, and can be designed to make working with the classical problems
used in a Pythonic, object oriented way. Although matplotlib is of Economic Dispatch (ED), Optimal Power Flow (OPF), and
written primarily in pure Python, it makes heavy use of NumPy Unit Commitment (UC) simple and intuitive. Minpower is also
and other extension code to provide good performance even for built for flexibility and will be a platform for research on smart
large arrays. grids and stochastic resources. Powerful generic optimization
In matplotlib it is not necessary to instantiate objects, call solvers (e.g., CPLEX) can be used by Minpower, allowing for
methods, set properties, and so on to see a histogram of data. It reasonable solution times on even large-scale problems. The
is possible to create simple plots with just a few commands. It goal is to create a state-of-the-art open source tool that enables
is also possible to automatically generate PostScript files to collaboration and accelerates research and learning. The
send to a printer or publishers and even to deploy matplotlib on Minpower code is open source and is set up for collaborative
a web application server to generate PNG output for inclusion authorship and mainte-nance.
in dynamically-generated web pages. Minpower is designed to be flexible, extensible, and fast
E. Pylon
enough for researchers and developers working on the
evolution of these problems, while remaining easy to use for
Pylon is developed by Richard Lincoln, which actually is a students learning the classical formulations.
port of MATPOWER to the Python programming language.
Pylon is funded by the Engineering and Physical Sciences III. CASE STUDY: SMALL SIGNAL STABILITY
Research Council through Grant GR/T28836/01 to provide a ANALYSIS
simple yet powerful tool for Power Engineering that is not tied . Small signal stability analysis is performed over the
to proprietary software and can be used and extended with IEEE 14-bus system[6] and the eigen values and participation
ease. factors are calculated. The below Fig. 1 and Fig. 2 shows the
Pylon‘s features currently includeμ
DC and AC (σewton‘s and Fast Decoupled method)
eigen values calculated on both the S-Domain and S-Domain.
power flow,
ISBN 978-81-926837-2-0
204
Proceedings of 3rd National Conference on Emerging Technologies in Electrical and Electronics Engineering (NCEEE-2013)
26th April 2013
A. Eigenvalues of the IEEE 14-Bus System in the S-Domain C. Computed Participation Factor
TABLE I
Computed Participation Factors
Fig. 3. Computed Eigen Values in S-domain
B. Computed Eigen Values in the Z-domain
IV. CONCLUSION
It is seen from the Table. II, that Python solves the Jacobian
matrix in 0.0319 seconds, while MATLAB and OCTAVE
solves it in 0.0363 and 0.0433 respectively. It is notable that
Python requires less time to solve problems even compared to
commercial scientific software packages with zero cost spend.
Using Python the engineers and scientists could create their
own software package to solve their own power system or even
to solve any scientific problems tailored to their own need.
Fig. 4.Computed Eigen Values in Z-domain
ISBN 978-81-926837-2-0
205
Proceedings of 3rd National Conference on Emerging Technologies in Electrical and Electronics Engineering (NCEEE-2013)
26th April 2013
[5] Fernando Perez, Brian E. Granger, John D. Hunter, ―Pythonμ An
TABLE II Ecosystem for Scientific Computing‖, 2011.
Comparison of runtime to calculate Jacobian matrix [6] Federico Milano, ―Power System Modelling and Scripting‖,
Springer-Verlag London Limited 2010.
[7] Stéfan van der Walt, S. Chris Colbert, Gaël Varoquaux, ―The
NumPy Array: A Structure for Efficient Numerical
Computation‖, Computing inSCienCe& engineering, 2011.
[8] NumPy community, ―NumPy Reference‖, March 20, 2009.
[9] EuroScipy tutorial team, ―Python Scientific lecture notesμ
Release β010‖, July 09, 2010.
[10] SciPy community, ―SciPy Reference Guide Release 0.7.dev‖,
December 07, 2008.
[11] John Hunter, Darren Dale, ―The Matplotlib User‘s Guide‖, May
27, 2007.
[12] Joachim Dahl, Lieven Vandenberghe, ―CVXOPT: Convex
REFERENCES optimization with Python‖, Workshop on Machine Learning
[1] Hans Fangohr, ―Introduction to Python for Computational Open Source Software NIPS 2006.
Science and Engineering‖, September 18, 2012. [13] Richard Lincoln, ―PYPτWER Documentation Release 4.0.1‖,
[2] Fernando Perez, Brian E. Granger, ―IPython: A System for July 15, 2011.
Interactive Scientific Computing‖, May/June 2007. [14] Hans Petter Langtangen, ―A Primer on Scientific Programming
with Python‖, Springer, 2nd Edition, Springer-Verlag Berlin
[3] Adam Greenhall, Rich Christie, Jean-Paul Watson, ―Minpower:
Heidelberg 2009, 2011.
A Power Systems Optimization Toolkit‖,
[4] Travis E. τliphant, ―Python for Scientific Computing‖,
Computing in Science and Engineering, 2007.
ISBN 978-81-926837-2-0
206
View publication stats