Ask Your Question

How do I call a psspy function without listing every argument?

asked 2012-02-03 00:35:23 -0500

Daniel_Hillier gravatar image

updated 2012-02-06 19:44:04 -0500

Many psspy functions take an enormous number of arguments. In most cases I am using the defaults except for one or two arguments that I actually wish to specify. How can I make my code easier to read by calling the functions with only the arguments I want.

In particular, I am looking for the methodology to take the arguments I want to specify from the Python PSSE API document (normally listed under OPTIONS, INTGAR, etc.) for a particular function and only passing them to the function in my code.

Here is an example piece of API documentation:

1.61 FNSL Use this API to apply the Newton-Raphson power flow calculation (activity FNSL).
Python Syntax:
ierr = fnsl(options)

Integer OPTIONS(8) Is an array of eight elements specifying solution options (input).
The values are as follows:

OPTIONS(1) tap adjustment flag (use tap adjustment option setting by default).
OPTIONS(1) = 0 disable.
OPTIONS(1) = 1 enable stepping adjustment.
OPTIONS(1) = 2 enable direct adjustment.
OPTIONS(2) area interchange adjustment flag (use area interchange adjustment option setting by default).
OPTIONS(2) = 0 disable.
OPTIONS(2) = 1 enable using tie line flows only in calculating area interchange.

How would I call this function with only issuing keyword arguments for, say, only OPTIONS(2) and not specifying OPTIONS(1)?

edit retag flag offensive close merge delete


Do you have an example? For instance the output of the PSSE macro recording?

JervisW gravatar imageJervisW ( 2012-02-03 05:11:46 -0500 )edit

It's not necessarily a macro recording (although it will help with that). My problem is when I want to write my own scripts. I would like to know how to compose a function call using the API documentation. I have updated the question to reflect this.

Daniel_Hillier gravatar imageDaniel_Hillier ( 2012-02-06 19:15:43 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2012-02-08 02:07:56 -0500

jtrain gravatar image

PSSE lets you change options using keyword arguments to the function.

You want to change OPTIONS(2) which is the area interchange adjustment flag, lets play that out to see how it looks.

Typically you might write the following to set OPTIONS(2) to 1:

ierr = psspy.fnsl([_i, 1])

Now, using keyword arguments lets change OPTIONS(2) to a 1:

ierr = psspy.fnsl(options2=1)

You can rewrite the API document PSSE argument descriptions as keyword arguments easily:

OPTIONS(2) -> options2
INTGAR(11) -> intgar11

and so on.

edit flag offensive delete link more


Exactly what I needed. Just a question about the first example (probably due to me only including 2 options from the API as opposed to the complete 8): when specifying the options as `[_i, 1]`, do I only have to specify up to the option I want to change or is the full set required in the list?

Daniel_Hillier gravatar imageDaniel_Hillier ( 2012-02-08 17:53:24 -0500 )edit

In most cases (95%+) you only need to specify what you need to actually change, and the others will be sent as default arguments. Be aware though that some functions need all arguments (scal_2), and some functions like fdns might need testing to see what they default values really are. *doh, necro*

SqFKYo gravatar imageSqFKYo ( 2017-09-27 00:52:14 -0500 )edit

answered 2017-09-21 10:00:09 -0500

I'm new on this tasks and I have some doubts related to argumen modifying.

Is it possible to use this argument writing with Fortran? OPTIONS(2) -> options2

Is it possible to write as [_i, _i, 1] with Fortran coding?

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools


Asked: 2012-02-03 00:35:23 -0500

Seen: 883 times

Last updated: Sep 21