Following on from the last video “How to solve a loadflow with Python”
This video explains exactly how and why I used keyword arguments in my Python functions. If you want to learn how to make your scripts easier to read, this 9 minute video is for you.
If you want to see more tutorial posts like this: Tell us what topic you’d like covered using this form
Transcript
Hi there power system engineers, last video we talked about how to make a
full newton rapheson solution with Python and PSSE. And during that example I
showed how to use keyword arguments to your function. Inside my fnsl
function I’ve used options1=0
and options5=0
to turn off taps and switched
shunt adjustments.
The old way
You might be familiar with the alternate form of calling a function with the
_i
in it. I’m going to show you how I wrote a function with options1
and
options5
keywords based on the documentation.
You might be more familiar with the _i
arguments that PSSE provides. WHen you
record a macro into a Python file you might find something that looks like
this:
1
|
|
Now this equivalent to the one above, options1
is set to zero and options5
is set to zero. However then you need to fill in the intermediate options
with these default integers which PSSE takes to mean don’t set this option
leave it as the default. You’ll get something like this from the PSSE record
macro.
Why change from the older method?
What I do is I replace this list of integer arguments with just two keyword arguments. Just the ones I want to change. The reason I do this is because it is easier for me to read later on. I can just look and see that I’m only changing options 1 and 5. I think that later on for me at least it is easier to read.
How to find keyword argument names
I’ve looked up the documentation to find how to define each of these things. The way I find the documentation is inside PSSE 32, in the help topics there is a PDF. There is a line in there called Application Program Interface or API. Which is the Python connection to PSSE.
If I look inside the menu here on the side and go down to fnsl
, this is the
definition of that function in the documentation. I can see the Python syntax
fnsl
and a named argument called options
. A unique quality of PSSE is that
you can refer to each of the option list elements as a keyword argument. So
1,2,3,4,5,6,7 and 8 each of these options can be addressed individually.
Python keyword arguments cannot have brackets ()
. So I write options1
all
lower case. It corresponds to the tap adjustments flag. The docs tell you what
values 0, 1 and 2 mean. I’ve used value 0 which means disable tap stepping,
the default is 1 (tap stepping enabled) and another value is 2 (direct tap
stepping).
options5
is a switched shunt adjustment flag. I’ve disabled the flag which is
value 0.
These keyword arguments start at 1 not zero. Normally in Python indexing starts at 0, however the PSSE keyword arguments start at one.
The keywords are not always the word options
I’ll just show one more function, its the machine data changing function. If
we go to Power Data Flow Changing. Let’s head to machine_data_2
, this function
has four arguments. This one intgar
and realar
are lists of arguments. intgar
is an array of 6 elements. If I wanted to change the machine status I might
say intgar1=0
. The intgar
ones are normally integers and the realar
ones are
floating point numbers.
So thats how I found the keyword arguments for the fnsl
function.
If you have any questions about setting up keyword arguments for your PSSE functions, get onto https://psspy.org/ and ask a question (it’s free).