First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!
1 | initial version |
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