该函数psspy.ardat()
返回[ierr, cmpval]
whereierr
是一个integer
对象,并且cmpval
是一个complex
对象,如下面的文档字符串所述,并在 API 文档中重复:
"""
Use this API to return area totals.
Python syntax:
ierr, cmpval = ardat(iar, string)
where:
Integer IAR Area number (input).
Character STRING String indicating the area total desired (input).
= LOAD, Total owner load by bus owner assignment (net of load plus in-service distributed
generation on load feeder).
= LOADLD, Total owner load by load owner assignment.
= LDGN, Total distributed generation on load feeder by bus owner assignment.
= LDGNLD, Total distributed generation on load feeder by load owner assignment.
= GEN, Total owner generation.
= LOSS, Total owner losses.
= INT, Net area interchange.
= INDMAC, Total owner induction machine powers by bus owner assignment.
= INDMACMC, Total owner induction machine powers by machine owner assignment.
= INDGEN, Total owner induction generator powers by bus owner assignment.
= INDGENMC, Total owner induction generator powers by machine owner assignment.
= INDMOT, Total owner induction motor powers by bus owner assignment.
= INDMOTMC, Total owner induction motor powers by machine owner assignment.
Complex CMPVAL Desired complex power (output).
Integer IERR Error code (output).
= 0, No error; 'P' and 'Q' or 'CMPVAL' returned.
= 1, Area number < 0 or > largest allowable area number; 'P' and 'Q' or 'CMPVAL' unchanged.
= 2, No in-service buses with in-service loads (for 'LOAD'), no in-service loads (for
'LOADLD'), no type 2 or type 3 buses (for 'GEN'), no branches (for 'LOSS'), or no ties
(for 'INT') in area; 'P' and 'Q' or 'CMPVAL' unchanged.
= 3, Area not found; 'P' and 'Q' or 'CMPVAL' unchanged.
= 4, Bad 'STRING' value; 'P' and 'Q' or 'CMPVAL' unchanged.
"""
一个complex
对象在Python标准库中定义,有属性.real
,.imag
但没有.complex
属性;这就是为什么你得到AttributeError
. 尝试以下操作:
sysload_TOT = sysload_N.real + sysload_D.real + sysload_M.real
output1 = 'Total Load iS #: {} MW\t'
formatted = output.format(sysload_TOT)
sysgen_TOT = sysgen_NI.real + sysgen_DI.real + sysgen_MI.real
output2 = 'Total Generation iS #: {} MW\t'
formatted2 = output2.format(sysgen_TOT)
sysLG_TOT = 100 * (sysload_TOT - sysgen_TOT) / (sysload_TOT)
output3 = 'Total Imports is #: {}%\t'
formatted3 = output3.format(sysLG_TOT)
print(formatted)
print(formatted2)
print(formatted3)
如果您要经常执行此功能,我会推荐以下方法:
# create a subsystem which contains the areas of interest
psspy.asys(sid=0, num=3, areas=[1,2,3])
# return an array of real values for subsystem areas
ierr, rarray = psspy.aareareal(sid=0, string=['PLOAD', 'PGEN', 'PINT'])
每当您使用psspy
参考文档的功能时,这一点非常重要。