簡體   English   中英

如何在PSSE上查找/修復屬性錯誤?

[英]How to find / fix attribute error on PSSE?

嘗試查找某個區域的總負載和發電量時出現錯誤。 我不斷收到屬性錯誤。 在這里,我可以找到psspy.ardat代碼的特定屬性。 對於load屬性, .real是正確的,但是對於生成屬性, .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)

函數psspy.ardat()返回[ierr, cmpval] ,其中ierr是一個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函數時,參考文檔都非常重要。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM