Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Unfortunately I don't think you can extract that type of calculated data from caspy.

Also, see below for a slight variation to @jsexauer's answer. This version will only make sure the branch is only documented once. Otherwise if you tried to calculate total system losses, it would be double what it should be.

ierr, loss = psspy.aflowreal(-1, 2, 1, 1, 'PLOSS')
ierr, toBus = psspy.aflowint(-1, 2, 1, 1, 'TONUMBER')
ierr, fromBus = psspy.aflowint(-1, 2, 1, 1, 'FROMNUMBER')
ierr, brnID = psspy.aflowchar(-1, 2, 1, 1, 'ID')
completed_branches = []

csv = 'ToBus, FromBus, ID, PLOSS\n'
for i in range(len(loss[0])):
    if not (toBus[0][i],fromBus[0][i],brnID[0][i]) in completed_branches:
        csv += '%i,%i,%s,%f\n' % (toBus[0][i], fromBus[0][i], brnID[0][i],loss[0][i])
        completed_branches.append((fromBus[0][i],toBus[0][i],brnID[0][i]))
print csv
with open('c:\\output.csv','w') as f:
    f.write(csv)

Unfortunately I don't think you can extract that type of calculated data from caspy.

Also, see below for a slight variation to @jsexauer's answer. This version will only make sure the branch is only documented once. Otherwise if you tried to calculate total system losses, it would be double what it should be.

ierr, loss = psspy.aflowreal(-1, 2, 1, 1, 'PLOSS')
ierr, toBus = psspy.aflowint(-1, 2, 1, 1, 'TONUMBER')
ierr, fromBus = psspy.aflowint(-1, 2, 1, 1, 'FROMNUMBER')
ierr, brnID = psspy.aflowchar(-1, 2, 1, 1, 'ID')
completed_branches branches = []

csv = 'ToBus, FromBus, ID, PLOSS\n'
for i in range(len(loss[0])):
    if not (toBus[0][i],fromBus[0][i],brnID[0][i]) in completed_branches:
branches:
        csv += '%i,%i,%s,%f\n' % (toBus[0][i], fromBus[0][i], brnID[0][i],loss[0][i])
        completed_branches.append((fromBus[0][i],toBus[0][i],brnID[0][i]))
branches.append((fromBus[0][i],toBus[0][i],brnID[0][i]))
print csv
with open('c:\\output.csv','w') as f:
    f.write(csv)

Unfortunately I don't think you can extract that type of calculated data from caspy.

Also, see below for a slight variation to @jsexauer's answer. This version will only make sure the branch is only documented once. Otherwise if you tried to calculate total system losses, it would be double what it should be.

ierr, loss = psspy.aflowreal(-1, 2, 1, 1, 'PLOSS')
ierr, toBus = psspy.aflowint(-1, 2, 1, 1, 'TONUMBER')
ierr, fromBus = psspy.aflowint(-1, 2, 1, 1, 'FROMNUMBER')
ierr, brnID = psspy.aflowchar(-1, 2, 1, 1, 'ID')
branches = []

csv = 'ToBus, FromBus, ID, PLOSS\n'
for i in range(len(loss[0])):
    if not (toBus[0][i],fromBus[0][i],brnID[0][i]) in branches:
        csv += '%i,%i,%s,%f\n' % (toBus[0][i], fromBus[0][i], brnID[0][i],loss[0][i])
        branches.append((fromBus[0][i],toBus[0][i],brnID[0][i]))
print csv
with open('c:\\output.csv','w') as f:
    f.write(csv)