Ask Your Question
0

Complex generation: get the Real par and Imagine part

asked 2019-01-23 09:59:03 -0500

L0r3als gravatar image

Hi!

I try to obtain the plant total power output from the Bus WF

CMPVAL2 =psspy.gendat(Bus_WF)
psspy.progress('  REAL_SCMPVAL  ' +str(CMPVAL2[1].real)+'\n')
psspy.progress('  IMA_SCMPVAL  ' +str(CMPVAL2[1].imag)+'\n')

I have the following error AttributeError: 'NoneType' object has no attribute 'real'

Also, I created a variable for keeping the REAL_MW = CMPVAL2[1].real but I received the same error.

I don´t know what is happening, Somebody can help me?

Thank you a lot!

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
1

answered 2019-01-23 11:07:58 -0500

jconto gravatar image

updated 2019-01-23 19:59:08 -0500

The function gendat returns a tuple with two entries, an integer ierr and a complex value cmpval. Use the following format (as it appears in the API manual) to 'break' the returned tuple:

ierr, cmpval = psspy.gendat(ibus)
edit flag offensive delete link more

Comments

Thank you, it works!!

L0r3als gravatar imageL0r3als ( 2019-01-24 01:29:57 -0500 )edit
1

answered 2019-01-24 02:16:21 -0500

perolofl gravatar image

In addition to jconto's answer your code should check the ierr value before taking the real part of cmpval. If the bus doesn't exist or there is no machine at the bus the API will return None. For example in savnw:

ierr, cmpval  = psspy.gendat(101)

will return ierr=0 and cmpval=(750+95.0456008911j) and it is possible to retrieve the real part of the complex power with cmpval.real.

If the bus or plant do not exist the error code will be non-zero and None will be returned instead of the complex power. For example ierr=3 and cmpval=None. You cannot use method .real on a NoneType object and therefore need to check the value of ierr before using method .real. E.g.

if  ierr==0: REAL_MW=cmpval.real
edit flag offensive delete link more

Comments

Thank you, Perolofl!

L0r3als gravatar imageL0r3als ( 2019-01-24 02:34:36 -0500 )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: 2019-01-23 09:59:03 -0500

Seen: 519 times

Last updated: Jan 24 '19