Hi, This is a script that I use to do that task
You can use it with more than one case and get the curve for varius nodes
I get the .qv file, QV curves in .pdf file and the Mvar reserve in .csv files.
I didn't have time to translate the comments
# created by: Waltter Valdez
#Este script es para sacar las curvas QV de las contingencias
import sys, os
sys.path.insert(0, r"C:\Program Files\PTI\PSSE33\PSSBIN")
# xx --> substitute xx with Version Number here.
os.environ['PATH'] = r"C:\Program Files\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)
Ruta = os.getcwd()
casos = ('ERT-MaxAbr12-UT_ST', 'ERT-MedAbr12-UT_ST', '')
"""No se debe quitar las comillas simples del final, estas permiten usar el
python incluso con un solo escenario """
archSub = Ruta + '\\' + 'subsistemas_QV.sub'
archMon = Ruta + '\\' + 'monitoreo_QV.mon'
archCon = Ruta + '\\' + 'contingencias_QV.con'
nodos = (28161, 28181, 27421, 27461)
"""# En nodos se debe introducir los numeros de los buses en los cuales
se desea obtener las curvas QV"""
psspy.progress_output(2, 'reportePro', [2, 0])
# Crea casos y QV por gobernador
for casoN in casos:
if casoN != '':
carpeta = Ruta + '\\' + casoN
if not os.path.isdir(carpeta):
os.makedirs(carpeta)
caso = Ruta + '\\' + casoN + '.sav'
Difaxx = carpeta + '\\' + 'Difaxx-' + casoN + '.dfx'
progreso = carpeta + '\\' + 'Progreso_' + casoN + '.txt'
psspy.progress_output(2, progreso, [2, 0])
psspy.case(caso)
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.fnsl([1, 0, 0, 1, 1, 0, 0, 0])
psspy.dfax([1, 1], archSub, archMon, archCon, Difaxx)
for nodo in nodos:
nodo1 = str(nodo)
archivoqv = carpeta + '\\' + 'QV_' + nodo1
ierr2 = psspy.qv_engine([0, 0, 0, 0, 0, 0, 1, 0, 0, nodo],
[0.5, 1.2, 0.5, 0.01], Difaxx, "", archivoqv)
if ierr2 != 0:
continue
# Change these values as required.
qvfile = 'QV_' + nodo1 + ".qv"
qvfile1 = carpeta + '\\''QV_' + nodo1 + ".qv"
contingencias = pssarrays.qv_summary(qvfile1).colabel
reserva = ["Reserva (Mvars)"]
contingencia = ["Contingencias"]
plt.cla()
ierr, cval = psspy.notona(nodo)
for colabel in contingencias:
rlst = pssarrays.qv_solution(qvfile1, colabel)
v = rlst.vsetpoint
q = rlst.mgenmvar
contingencia.append(colabel)
reserva.append(min(rlst.mgenmvar)[0])
plt.plot(v, q)
reporteReserva = carpeta + '\\' + 'Reporte_Reserva_' + qvfile + '.csv'
csv_out = open(reporteReserva, 'wb')
mywriter = csv.writer(csv_out)
rows = zip(contingencia, reserva)
mywriter.writerows(rows)
csv_out.close()
plt.legend(contingencias, loc='upper right')
plt.title(qvfile[0:-3] + "_" + cval[0:-7])
plt.ylabel('MVAr')
plt.xlabel('Voltaje(p.u.)')
plt.grid(True)
plt.savefig(carpeta + '\\' + qvfile[0:-3] + '.pdf', format=None, orientation='portrait')