简体   繁体   中英

How to find / fix attribute error on PSSE?

I am receiving an error when trying to find total load and generation in an area. I keep getting an attribute error. WHere can i find specific attributes for the psspy.ardat code. For the load attribute, .real is correct but for generation attribute, .complex is incorrect. I keep getting this error: 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)

The function psspy.ardat() returns [ierr, cmpval] where ierr is an integer object and cmpval is a complex object as described by the docstring below and repeated in the API documentation:

"""
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.

"""

A complex object is defined in the Python standard library and has attributes .real and .imag but does not have a .complex attribute; this is why you are getting the AttributeError . Try the following:

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)

If you are going to be performing this functionality often I would recommend the following approach:

# 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'])

Whenever you are using psspy functions referring to the documentation is very important.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM