Ask Your Question
0

How to pass only certain elements of an array in function

asked 2018-11-09 13:32:42 -0600

rafaels100 gravatar image

updated 2018-11-09 13:33:06 -0600

Hello I would like to know how to pass only the elements of the array that im interested in changing to a function that takes an array as an argument, and leave the other elements of the array as default. Thanks !

edit retag flag offensive close merge delete

Comments

SOLUTION: To leave the elements in the array as default, you have to use psspy._i (if the element its an integer), psspy._f (if its real/float) or psspy._s (if its a string). You can import them like these: from psspy import _i, _f, _s to use them without the psspy. in front of them

rafaels100 gravatar imagerafaels100 ( 2018-11-14 09:50:07 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-11-15 02:17:56 -0600

perolofl gravatar image

updated 2018-11-15 02:20:56 -0600

I have noted that there are many question in this forum regarding which API to use in order to perform a certain task. The method I prefer is to record a python script while performing the task manually in the GUI.

Stop recording and open the script. For example if I manually change Qload at bus 205 to 600 Mvar the recorded script will be:

psspy.load_chng_4(205,r"""1""",[_i,_i,_i,_i,_i,_i],[_f, 600.0,_f,_f,_f,_f])

Now I see which API is used to perform the change (loadchng4) and I can read about the API in the manual. Only the parameter values that I changed are written to the script and the other parameters are represented with their default values ( i for integers and _f for floats). For a data changing API this means that they are not changed, i.e. keeping their old values. For API adding new components, like loaddata_4, the default values will take the same values as for actitivty READ.

It is only necessary to enter the argument up to the last one to be changed. In my example I am changing the second real argument so the rest of the real arguments can be skipped:

psspy.load_chng_4(205,r"""1""",[_i,_i,_i,_i,_i,_i],[_f, 600.0])

Since I am not changing any integer arguments I can skip those defaults and just enter an empty list for the integer arguments:

psspy.load_chng_4(205,r"""1""",[],[_f, 600.0])

It is also possible to pass argument with their keyword name. In this case the second real is named realar2:

psspy.load_chng_4(205,r"""1""",realar2= 600.0)

Integer arguments are named intgar, for example

psspy.load_chng_4(205,r"""1""",realar2= 600.0,intgar3=6)

to change the third integer (zone number) to 6. Note that the order of keyword arguments doesn't matter. The integer argument can be given after the real argument.

edit flag offensive delete link more

Comments

Thanks for the advice, its really good idea and common sense, and thanks for your thoroughly explanation !

rafaels100 gravatar imagerafaels100 ( 2018-11-22 06:34:51 -0600 )edit

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

1 follower

Stats

Asked: 2018-11-09 13:32:42 -0600

Seen: 778 times

Last updated: Nov 15 '18