如何查找/修复PSSE上的属性错误?

2024-05-02 21:30:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我收到一个错误时,试图找到总负荷和发电量在一个地区。我一直得到一个属性错误。在哪里可以找到psspy.ardat代码的特定属性。对于load属性,.real是正确的,但是对于generation属性,.complex是不正确的。 我一直收到这个错误: AttributeError: 'complex' object has no attribute 'complex'

[ierr, sysload_N] = psspy.ardat(1, 'LOAD')
[ierr, sysload_D] = psspy.ardat(2, 'LOAD')
[ierr, sysload_M] = psspy.ardat(3, 'LOAD')
[ierr, sysgen_NI] = psspy.ardat(1, 'GEN')
[ierr, sysgen_DI] = psspy.ardat(2, 'GEN')
[ierr, sysgen_MI] = psspy.ardat(3, 'GEN')
sysload_TOT = sysload_N.real + sysload_D.real+sysload_M.real
output = 'Total Load iS #: {} MW\t'
formatted = output.format(sysload_TOT)
sysgen_TOT = sysgen_NI.complex + sysgen_DI.real+sysgen_MI.complex
output2 = 'Total Generation iS #: {} MW\t'
formatted2 = output2.format(sysgen_TOT)
sysLG_TOT=(sysload_TOT-sysgen_TOT)/(sysload_TOT)*100
output3 = 'Total Imports iS #: {}%\t'
formatted3 = output3.format(sysLG_TOT)
output.append(formatted)
output2.append(formatted2)
output3.append(formatted3)
print(output)
print(output2)
print(output3)

Tags: output属性错误loadrealgencomplextot
1条回答
网友
1楼 · 发布于 2024-05-02 21:30:44

函数psspy.ardat()返回[ierr, cmpval],其中ierrinteger对象,cmpval是{}对象,如下面的docstring所述,并在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.

"""

在Python标准库中定义了一个complex对象,它具有.real和{}属性,但没有.complex属性;这就是您获得AttributeError的原因。尝试以下操作:

^{pr2}$

如果您要经常执行此功能,我建议您使用以下方法:

# 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,引用文档的函数都是非常重要的。在

相关问题 更多 >