First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!
1 | initial version |
You can refer to this link
2 | No.2 Revision |
You can refer to this link
This is my modification:
# created by: Waltter Valdez
# Source: https://psspy.org/psse-help-forum/question/444/what-is-the-api-for-generating-the-qv-files/
# Modified by: ays
# Sebaiknya aplikasi excel di-save atau ditutup terlebih dahulu agar tidak terjadi error
# ========================================================== FILE BASECASE ==========================================================
kasus = ('1PM - 20160816 TAHUN 2017-apb', '')
# ========================================================== FILE BASECASE ==========================================================
# ============================================================ NOMOR BUS ============================================================
nobus = (25056, 25072, 25052, 25064, 25901, 25164, 25028, 25054, 25094, 25096)
# ============================================================ NOMOR BUS ============================================================
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
_i = psspy.getdefaultint()
_f = psspy.getdefaultreal()
_s = psspy.getdefaultchar()
import pssarrays
import matplotlib.pyplot as plt
import csv
psspy.psseinit(50000)
kerja = 'D:\\PLN\\PSSE\\STUDI\\QV'
os.chdir(kerja)
archSub = kerja + '\\' + 'ALL.sub'
archMon = kerja + '\\' + 'ALL.mon'
archCon = kerja + '\\' + 'ALL.con'
import pssexcel
psspy.progress_output(2, 'LaporanPro', [2, 0])
# Crea kasus y QV por gobernador
for kasusN in kasus:
if kasusN != '':
gelar = kerja + '\\' + kasusN
if not os.path.isdir(gelar):
os.makedirs(gelar)
kes = kerja + '\\' + kasusN + '.sav'
Difaxx = gelar + '\\' + 'ALL-' + kasusN + '.dfx'
progres = gelar + '\\' + 'Progres_' + kasusN + '.txt'
psspy.progress_output(2, progres, [2, 0])
#zeroz = gelar + '\\' + 'Error_' + kasusN + '.txt'
#psspy.report_output(islct=2, filarg=zeroz, options=[0])
psspy.case(kes)
# psspy.branch_data(27371, 27372, r"""1""",
# [_i, _i, _i, _i, _i, _i], [0.1E-05, _f, _f, _f, _f, _f, _f, _f,
# _f, _f, _f, _f, _f, _f, _f])
"""Do it if you have Zero branch..."""
psspy.fdns([2,0,0,1,1,1,-1,0])
psspy.fdns([2,0,0,1,1,1,99,0])
psspy.fdns([2,0,0,1,1,0,99,0])
psspy.fdns([2,0,0,1,1,0,99,0])
psspy.dfax([1, 1], archSub, archMon, archCon, Difaxx)
for nod in nobus:
nod1 = str(nod)
archivoqv = gelar + '\\' + 'QV_' + nod1
ierr2 = psspy.qv_engine([0, 0, 0, 0, 0, 0, 1, 0, 0, nod],
[0.5, 1.1, 0.8, 0.01], Difaxx, "", archivoqv)
if ierr2 != 0:
continue
qvfile = 'QV_' + nod1 + ".qv"
qvfile1 = gelar + '\\''QV_' + nod1 + ".qv"
Kontingensi = pssarrays.qv_summary(qvfile1).colabel
reserva = ["Daya Reaktif (Mvars)"]
Contingency = ["Kontingensi"]
plt.cla()
ierr, cval = psspy.notona(nod)
for colabel in Kontingensi:
rlst = pssarrays.qv_solution(qvfile1, colabel)
v = rlst.vsetpoint
q = rlst.mgenmvar
Contingency.append(colabel)
reserva.append(min(rlst.mgenmvar)[0])
plt.plot(v, q)
pssexcel.qv(qvfile=gelar + '\\' + qvfile, string=['s', 'v', 'm', 'g'], colabel='', namesplit=True, xlsfile=gelar + '\\''QV_' + nod1, sheet='', overwritesheet=True, show=False)
pssexcel.qv(qvfile=gelar + '\\' + qvfile, string=['g'], colabel='', namesplit=True, xlsfile=gelar + '\\''QV_' + kasusN, sheet=nod1, overwritesheet=True, show=False)
# C:\Program Files(x86)\PTI\PSSE33\DOCS\API.pdf
# String = ['s','m','v','g']
# 's' or 'summary' QV Solution Summary
# 'v' or 'voltage' Monitored Bus Voltage
# 'm' or 'mismatch' Largest and Total Mismatch
# 'g' or 'generator' Monitored Plants MW and MVAR
plt.legend(Kontingensi, loc='upper right')
plt.title(qvfile[0:-3] + "_" + cval[0:-7])
plt.ylabel('MVAr')
plt.xlabel('Tegangan(p.u.)')
plt.grid(True)
plt.savefig(gelar + '\\' + qvfile[0:-3] + '.pdf', format=None, orientation='portrait')
import pythoncom
import win32com
xl = win32com.client.Dispatch("Excel.Application")
# 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()