Upload
prabakaran-santhanam
View
86
Download
0
Embed Size (px)
DESCRIPTION
Power Systems computation which were being computed so far using MATLAB, OCTAVE and other closed software packages could be solved using Python. There are various open source tools available which along with Python could be used to solve complex power system problems. Python with simple and easy to learn syntax along with its power of being a general purpose scripting language enables engineers and researchers to solve complex problems interactively. They could develop their own software package either an open source or even commercial software without any permissions from Python. A test case was conducted using an IEEE 14-bus system in which the small signal stability analysis is performed using Python and it is compared with MATLAB and OCTAVE.
Citation preview
Python for Power Systems Computation
Prabakaran. S
M.E., Power Systems Engineering,
Valliammai Engineering College
Chennai, India
AbstractPower Systems computation which were being
computed so far using MATLAB, OCTAVE and other closed
software packages could be solved using Python. There are
various open source tools available which along with Python
could be used to solve complex power system problems. Python
with simple and easy to learn syntax along with its power of
being a general purpose scripting language enables engineers and
researchers to solve complex problems interactively. They could
develop their own software package either an open source or
even commercial software without any permissions from Python.
A test case was conducted using an IEEE 14-bus system in which
the small signal stability analysis is performed using Python and
it is compared with MATLAB and OCTAVE.
Index TermsPython, tools, power system computations, open
source, NumPy, SciPy, Matplotlib, CVXOPT.
I. INTRODUCTION
In general, Power System design, analysis and control
involve complex mathematical computations exhibiting
exhaustive nature. Because of its exhaustive nature it became a
hardball for scientists and engineers to solve power system
problems, even using computer. This is the reason that most of
the power system engineers and researchers use a commercial
software package like MATLAB which is a closed software
package.
However, there are also freely-distributed projects but
whose source code is not provided or, if provided, is
too complicated to be mastered in a reasonable time. As it can
be promptly observed, closed software packages embed and
mask the most interesting parts, i.e., the modelling and
computer implementation phases. There are at least two
important drawbacks in this approach. The first one is that the
user has to accept the hypotheses and simplifications used by
the authors of the software package. The other one is that the
user often ignores the hypotheses and simplifications used by
the authors of the software package. A byproduct drawback is
also the absent or reduced possibility of modifying the
equations and of replacing the algorithms used by the
software package.
Clearly, the main advantage of using a closed software
packages is to save time. For well-assessed and repetitive
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
Octave[14]. Python is inherently object oriented. Almost
everything is an object: strings, lists, dictionaries, tuples,
functions, classes, and more. The implied usefulness is that
these things each have their own members and methods that
encapsulate its functionality and information. To get
functionalities of MATLAB and Octave in Python, the NumPy,
SciPy and Matplotlib packages should be used. Scipy is a
package that has the goal of providing all the other
functionality of MATLAB, including those in the MATLAB
toolboxes. There are also a handful of IDE's available for
Python, most of which are for free.
Because Python is open and free, it is very easy for other
parties to design packages or other software tools that extend
Python. It is possible to create applications using any of the
major GUI libraries[1] (TK, WX, GTK, QT ...), use OpenGL,
drive your USB port, etc. Another example is Pyrex/Cython to
enhance the speed of algorithms by converting Python to C
code, and py2exe and the like to create a standalone application
from the source. Also the system programming languages are
not much faster than efficient scientific scripting languages.
However, scripting languages do not perform
directly heavy mathematical operations, butcall efficient
FORTRAN or C-based libraries. The proposed system for
studying a Power System through Python (open software
package) is shown in Fig. 1. Thus, the main conclusion is that
the interfaces that link scripting languages with external
compiled libraries are quite efficient.
II. AVAILABLE TOOLS FOR POWER SYSTEM COMPUTATION
There are a large number of modules of the libraries
available to Python for Power System computations. Also,
there is an advanced Python shell, IPython[2], developed
specifically for scientific computing.
Below are the most potential modules including NumPy[8],
SciPy[10], Matpltotlib[11], CVXOPT[12], Pylon,
PyPower[13], Minpower[3] that are standard libraries which
could be used for Power System computations.
A. NumPy
The Numeric Python extensions (NumPy) is a set of
extensions to the Python programming language which allows
Fig. 1. Approach for studying a system using Python
Python programmers to efficiently manipulate large sets of
objects organized in grid-like fashion. These sets of objects are
called arrays, and they can have any number of dimensions:
one dimensional arrays are similar to standard Python
sequences, two-dimensional arrays are similar to matrices from
linear algebra.
Anything that can be done in NumPy could also be done in
standard Python we just may not be alive to see the program finish. A more subtle reason for these extensions however is
that the kinds of operations that programmers typically want to
do on arrays, while sometimes very complex, can often be de-
composed into a set of fairly standard operations. This
decomposition has been developed similarly in many array
languages. In some ways, NumPy is simply the application of
this experience to the Python language thus many of the operations described in NumPy work the way they do because
experience has shown that way to be a good one, in a variety of
contexts. The languages which were used to guide the
development of NumPy include the infamous APL family of
languages, Basis, MATLAB, FORTRAN, S and S+, and
others[4]. This heritage will be obvious to users of NumPy who
already have experience with these other languages.
When NumPy is skillfully applied, computation time is
primarily spent on vectorized array operations instead of in
Python for loops (which are often a bottleneck). Further speed
improvements are achieved using optimizing compilers, such
as Cython, which allow better control over cache effects. In
addition to low-level array operations, NumPy provides sub-
packages for linear algebra, FFTs, random number generation,
and polynomial manipulation. Larger scientific packages,
such as SciPy, are, in turn, built on this infrastructure. NumPy
and similar projects foster an environment in which users can
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 niches 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.
SciPy makes it easy to integrate C code, which is essential
when algorithms operating on large data sets cannot be
vectorized. The universality of Python, the language in
which SciPy was written, gives the researcher access to a
broader set of non-numerical libraries to support GUI
development, interface with databases, manipulate graph
structures, render 3D graphics, unpack binary files, etc.
Pythons extensive support for operator overloading makes SciPys syntax as succinct as its competitors, MATLAB, Octave, and R. More profoundly, we found it easy to rework
research code written with SciPy into a production application,
deployable on numerous platforms.
C. CVXOPT
CVXOPT is a free software package for convex
optimization based on the Python programming language. It
can be used with the interactive Python interpreter, on the
command line by executing Python scripts, or integrated in
other software via Python extension modules. Its main purpose
is to make the development of software for convex
optimization applications straightforward by building on
Pythons extensive standard library and on the strengths of Python as a high-level programming language.
CVXOPT extends the built-in Python objects with two
matrix objects: a matrix object for dense matrices and
a spmatrix object for sparse matrices. Also an API can be used
to extend CVXOPT with interfaces to external C routines and
libraries. A C program that creates or manipulates the dense or
sparse matrix objects defined in CVXOPT must include
the cvxopt.h header file in the src directory of the distribution.
The best part about CVXOPT is that the matrices from
NumPy arrays and CVXOPT are compatible and both these
packages could exchange information using the array interface.
For example, in NumPy the matrices could be created from a
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)
Similarly a CVXOPT matrix could be created from a
NumPy array using the matrix() method as follows.
>>> C = matrix(B)
>>> type(C)
D. Matplotlib
Matplotlib is a library for making 2D plots of arrays in
Python Although it has its origins in emulating the MATLAB
graphics commands, it is independent of MATLAB, and can be
used in a Pythonic, object oriented way. Although matplotlib is
written primarily in pure Python, it makes heavy use of NumPy
and other extension code to provide good performance even for
large arrays.
In matplotlib it is not necessary to instantiate objects, call
methods, set properties, and so on to see a histogram of data. It
is possible to create simple plots with just a few commands. It
is also possible to automatically generate PostScript files to
send to a printer or publishers and even to deploy matplotlib on
a web application server to generate PNG output for inclusion
in dynamically-generated web pages.
E. Pylon
Pylon is developed by Richard Lincoln, which actually is a
port of MATPOWER to the Python programming language.
Pylon is funded by the Engineering and Physical Sciences
Research Council through Grant GR/T28836/01 to provide a
simple yet powerful tool for Power Engineering that is not tied
to proprietary software and can be used and extended with
ease.
Pylons features currently include:
DC and AC (Newtons and Fast Decoupled method) power flow,
DC and AC optimal power flow and
Fig. 2. TEX Rendering in plots using Matplotlib
PSS/E, MATPOWER and PSAT case serialization and de-serialization.
F. Minpower
Minpower is an open source toolkit for students and
researchers in power systems optimization. The toolkit is
designed to make working with the classical problems
of Economic Dispatch (ED), Optimal Power Flow (OPF), and
Unit Commitment (UC) simple and intuitive. Minpower is also
built for flexibility and will be a platform for research on smart
grids and stochastic resources. Powerful generic optimization
solvers (e.g., CPLEX) can be used by Minpower, allowing for
reasonable solution times on even large-scale problems. The
goal is to create a state-of-the-art open source tool that enables
collaboration and accelerates research and learning. The
Minpower code is open source and is set up for collaborative
authorship and mainte-nance.
Minpower is designed to be flexible, extensible, and fast
enough for researchers and developers working on the
evolution of these problems, while remaining easy to use for
students learning the classical formulations.
III. CASE STUDY: SMALL SIGNAL STABILITY ANALYSIS
. Small signal stability analysis is performed over the
IEEE 14-bus system[6] and the eigen values and participation
factors are calculated. The below Fig. 1 and Fig. 2 shows the
eigen values calculated on both the S-Domain and S-Domain.
A. Eigenvalues of the IEEE 14-Bus System in the S-Domain
Fig. 3. Computed Eigen Values in S-domain
B. Computed Eigen Values in the Z-domain
Fig. 4.Computed Eigen Values in Z-domain
C. Computed Participation Factor
TABLE I
Computed Participation Factors
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.
TABLE II
Comparison of runtime to calculate Jacobian matrix
REFERENCES
[1] Hans Fangohr, Introduction to Python for Computational Science and Engineering, September 18, 2012.
[2] Fernando Perez, Brian E. Granger, IPython: A System for
Interactive Scientific Computing, May/June 2007.
[3] Adam Greenhall, Rich Christie, Jean-Paul Watson, Minpower: A Power Systems Optimization Toolkit,
[4] Travis E. Oliphant, Python for Scientific Computing, Computing in Science and Engineering, 2007.
[5] Fernando Perez, Brian E. Granger, John D. Hunter, Python: An Ecosystem for Scientific Computing, 2011.
[6] Federico Milano, Power System Modelling and Scripting, Springer-Verlag London Limited 2010.
[7] Stfan van der Walt, S. Chris Colbert, Gal 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 2010, July 09, 2010.
[10] SciPy community, SciPy Reference Guide Release 0.7.dev, December 07, 2008.
[11] John Hunter, Darren Dale, The Matplotlib Users Guide, May 27, 2007.
[12] Joachim Dahl, Lieven Vandenberghe, CVXOPT: Convex optimization with Python, Workshop on Machine Learning Open Source Software NIPS 2006.
[13] Richard Lincoln, PYPOWER Documentation Release 4.0.1, July 15, 2011.
[14] Hans Petter Langtangen, A Primer on Scientific Programming with Python, Springer, 2nd Edition, Springer-Verlag Berlin Heidelberg 2009, 2011.