Ask Your Question
0

How to get MW and MVAR on psspy.aloadcplx and How to kill excel on Task Manager

asked 2016-11-22 09:07:12 -0600

ays gravatar image

I have the following script:

# get data loading branches, buses voltage, loads and machines.

import sys
import os

sys.path.insert(0, r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN")
# xx --> substitute xx with Version Number here.
os.environ['PATH'] = r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN" + ";" + os.environ['PATH']

import redirect
redirect.psse2py()
# this redirects PSS(R)E progress, report output to Python Shell/Console

import psspy

psspy.psseinit(50000)

kerja = 'D:\\DATA'
kasus = ('2018_1a.sav')
kes = kerja + '\\' + kasus
psspy.case(kes)
psspy.fdns([2,0,0,1,1,0,99,0])

#Branch
ierr,busnum = psspy.abrnint(flag=4,entry=2,string=['FROMNUMBER','TONUMBER'])
ierr,ckt = psspy.abrnchar(flag=4,entry=2,string='ID')
ierr,loading = psspy.abrnreal(flag=4,entry=2,string=['P','Q','PCTRATEA'])

#Trafo
# ierr,trbusnum = psspy.atrnint(string=['FROMNUMBER','TONUMBER'])
# ierr,trckt = psspy.atrnchar(string='ID')
# ierr,trloading = psspy.atrnreal(string=['P','Q','PCTRATEA'])

#Bus
ierr,bus = psspy.abusint(string='NUMBER')
ierr,name = psspy.abuschar(string='NAME')
ierr,volt = psspy.abusreal(string='KV')

#Load
ierr,bnum = psspy.aloadint(flag=1,string='NUMBER')
ierr,bname = psspy.aloadchar(flag=1,string='NAME')
ierr,bload = psspy.aloadcplx(flag=1,string=['MVANOM'])

#Machine
ierr,machnum = psspy.amachint(flag=4,string='NUMBER')
ierr,machname = psspy.amachchar(flag=4,string='NAME')
ierr,machload = psspy.amachreal(flag=4,string=['PGEN','QGEN'])

print 'Tahap 1 Run PSSE'

# x=len(trbusnum)
# print ('X = ' + str(x))
import excelpy

# create a Excel workbook for writing
xlobj = excelpy.workbook()
#=======================================
import pythoncom
import win32com
xl = win32com.client.Dispatch("Excel.Application")

# write header
xlobj.set_range(1,'b',['From bus','To bus','ID','MW','MVAr','PCTRATEA'])
xlobj.set_range(1,'i',['NUMBER','NAME','KV'])
xlobj.set_range(1,'m',['BNUM','BNAME','BLOAD'])
xlobj.set_range(1,'q',['MACHNUM','MACHNAME','PGEN','QGEN'])
# write data
xlobj.set_range(2,'b',zip(*busnum))
xlobj.set_range(2,'d',zip(*ckt))
xlobj.set_range(2,'e',zip(*loading))
xlobj.set_range(2,'i',zip(*bus))
xlobj.set_range(2,'j',zip(*name))
xlobj.set_range(2,'k',zip(*volt))
xlobj.set_range(2,'m',zip(*bnum))
xlobj.set_range(2,'n',zip(*bname))
xlobj.set_range(2,'o',zip(*bload))
xlobj.set_range(2,'q',zip(*machnum))
xlobj.set_range(2,'r',zip(*machname))
xlobj.set_range(2,'s',zip(*machload))

print 'Tahap 2 Olah Data di Excel'

# save workbook
    import win32com
xl = win32com.client.Dispatch("Excel.Application")
xl.DisplayAlerts = False
xlobj.save(kerja + '\\' + 'scen1bfull.xlsx')
xl.DisplayAlerts = True
print 'Tahap 3 Save Data ke Excel'

# Cek Aplikasi Excel ada yang terbuka atau tidak
#=====================================================
try:
    xl.Quit()   #quit excel, as if user hit the close button/clicked file->exit.
    wb = xl.ActiveWorkbook #Source https://mail.python.org/pipermail/python-win32/2011-August/011738.html
    xl.Visible = 0
    xl = None
    del xl
    del wb
except:
    raise TypeError('Simpan dan Tutup File Excel atau End Task Ms Excel di Task Manager --> Background Process')
print 'Selesai'
pythoncom.CoUninitialize()

When I run this script, I got an error:

Tahap 1 Run PSSE
Traceback (most recent call last):
File "D:/DATA/myscript.py", line 75, in <module>
xlobj.set_range(2,'o',zip(*bload))
File ".\excelpy ...
(more)
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2016-11-22 11:47:03 -0600

perolofl gravatar image

Variable bload is complex. Try to convert to two float lists (P&Q) before set_range statement.

edit flag offensive delete link more

Comments

I try add this code: import numpy as np .... a = np.real(bload) b = np.imag(bload) and the result "a" is MVA and "b" is zero I need more clue

ays gravatar imageays ( 2016-11-22 12:49:49 -0600 )edit

Try a = [s.real for s in bload] and b = [s.imag for s in bload]

perolofl gravatar imageperolofl ( 2016-11-22 16:41:13 -0600 )edit

i'm sorry, myscript a = np.real(bload) and b = np.imag(bload) are okey. I made a mistake when I change ierr,bload = psspy.aloadreal(flag=1,string=['MVANOM']) and not undo to aloadcplx. Go to next issue about kicking excel on task manager. some body can give me tips and trick?

ays gravatar imageays ( 2016-11-22 21:01:55 -0600 )edit
0

answered 2016-11-28 00:59:03 -0600

SqFKYo gravatar image
ierr,bus = psspy.abusint(string='NUMBER')

This yields you bus object that looks like this: [[1,2,3,4,5]], so when you zip(*bus), you get [([1,2,3,4,5],)] back, which is probably what you don't want. Instead use this:

ierr, [bus] = psspy.abusint(string='NUMBER')

This unpacks it so the bus object is a flat list [1,2,3,4,5] and zip(*bus) yields [(1,), (2,), (3,), (4,), (5,)]

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: 2016-11-22 09:07:12 -0600

Seen: 824 times

Last updated: Nov 28 '16