0

Complex generation: get the Real par and Imagine part

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!

L0r3als's avatar
17
L0r3als
asked 2019-01-23 09:59:03 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

1

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)
jconto's avatar
2.9k
jconto
answered 2019-01-23 11:07:58 -0500, updated 2019-01-23 19:59:08 -0500
edit flag offensive 0 remove flag delete link

Comments

Thank you, it works!!

L0r3als's avatar L0r3als (2019-01-24 01:29:57 -0500) edit
add a comment see more comments
1

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
perolofl's avatar
3.8k
perolofl
answered 2019-01-24 02:16:21 -0500
edit flag offensive 0 remove flag delete link

Comments

Thank you, Perolofl!

L0r3als's avatar L0r3als (2019-01-24 02:34:36 -0500) edit
add a comment see more comments

Your Answer

Login/Signup to Answer