First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

Ask Your Question
0

How to pass only certain elements of an array in function

asked Nov 9 '18

rafaels100 gravatar image

updated Nov 9 '18

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 !

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 (Nov 14 '18)

1 answer

Sort by » oldest newest most voted
1

answered Nov 15 '18

perolofl gravatar image

updated Nov 15 '18

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.

link

Comments

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

rafaels100 gravatar imagerafaels100 (Nov 22 '18)

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: Nov 9 '18

Seen: 857 times

Last updated: Nov 15 '18