First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!
1 | initial version |
Hi, folks. I am trying to do multiple QV analyses and wirte data to csv file. Data contain Vsetpoint and Q of fictious generator, write along columns. But when I used:
ierr, cval = psspy.notona(node)
rlst = pssarrays.qv_solution(qvfile1, colabel)
v = rlst.vsetpoint
q = (rlst.mgenmvar)
I got q with size (199*length(v)) more bigger than what I expected (1 * length(v)). All of my monitored buses in .mon file are type 1, so I just don't know why it is so big. Is there anyway to get q of fictious generator contacted with the interested bus in those data or just an simpler way to get direct Q without relating to rlst.mgenmvar.
Also, I got an error message when try to do second interation. It is TypeError: 'float' object is not iterable in
for row,vol in zip(rows,V):
row.append(vol)
for row,mvar in zip(rows,Q):
rows.append(mvar)
Here is my code( I edited from code in https://psspy.org/psse-help-forum/question/444/what-is-the-api-for-generating-the-qv-files/).
# created by: Waltter Valdez
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()
cases = ('Peak15_V2','')
"""Do not remove the single quotes from the end, these allow you to use the
python even a single scenario """
archSub = Ruta + '\\' + 'QV_VN15.sub'
archMon = Ruta + '\\' + 'QV_VN15.mon'
archCon = Ruta + '\\' + 'QV_VN15.con'
nodes = (13203,18501,38501,42501, 49501)
"""# Nodes must be entered in the numbers of the buses in which
you want to get the QV curves"""
#psspy.progress_output(2, 'reportePro', [2, 0])
# Create cases and QV governor
for caseN in cases:
if caseN != '':
carpeta = Ruta + '\\' + caseN
if not os.path.isdir(carpeta):
os.makedirs(carpeta)
case = Ruta + '\\' + caseN + '.sav'
Difaxx = carpeta + '\\' + 'Difaxx-' + caseN + '.dfx'
progress = carpeta + '\\' + 'progress_' + caseN + '.txt'
psspy.progress_output(2, progress, [2, 0])
psspy.case(case)
psspy.fnsl([1, 0, 0, 1, 1, 0, 0, 0])
psspy.dfax([1, 1], archSub, archMon, archCon, Difaxx)
rows=[]
for node in nodes:
node1 = str(node)
archivoqv = carpeta + '\\' + 'QV_' + node1
ierr2 = psspy.qv_engine_4([0, 0, 0, 0, 0, 0, 1, 1, 0, 1, node, 0, 0],
[0.5, 1.05, 0.5, 0.01],"",Difaxx,"","",archivoqv,"")
if ierr2 != 0:
continue
# Change these values as required.
qvfile = 'QV_' + node1 + ".qv"
qvfile1 = carpeta + '\\''QV_' + node1 + ".qv"
Q=['Q(MVAr))']
V=['V'+'_'+str(node)]
Contingencies = pssarrays.qv_summary(qvfile1).colabel
colabel=Contingencies[0]
ierr, cval = psspy.notona(node)
rlst = pssarrays.qv_solution(qvfile1, colabel)
v = rlst.vsetpoint
q = rlst.mgenmvar
Q.extend(q)
V.extend(v)
if count==1:
rows=[]
for q,v in zip(Q,V):
row=[q]
row.extend([v])
rows.append(row)
else:
for row,vol in zip(rows,V):
row.append(vol)
for row,mvar in zip(rows,Q):
rows.append(mvar)
Report = carpeta + '\\' + 'Report' + '.csv'
csv_out = open(Report, 'wb')
mywriter = csv.writer(csv_out)
mywriter.writerows(rows)
#plt.plot(v, q)
csv_out.close()
2 | No.2 Revision |
Hi, folks. I am trying to do multiple QV analyses and wirte data to csv file. Data contain Vsetpoint and Q of fictious generator, write along columns. But when I used:
ierr, cval = psspy.notona(node)
rlst = pssarrays.qv_solution(qvfile1, colabel)
v = rlst.vsetpoint
q = (rlst.mgenmvar)
I got q with size (199*length(v)) more bigger than what I expected (1 * length(v)). All of my monitored buses in .mon file are type 1, so I just don't know why it is so big. Is there anyway to get q of fictious generator contacted with the interested bus in those data or just an simpler way to get direct Q without relating to rlst.mgenmvar.
Also, I got an error message when try to do second interation. It is TypeError: 'float' object is not iterable in
for row,vol in zip(rows,V):
row.append(vol)
for row,mvar in zip(rows,Q):
rows.append(mvar)
Here is my code( I edited from code in https://psspy.org/psse-help-forum/question/444/what-is-the-api-for-generating-the-qv-files/).
# created by: Waltter Valdez
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()
cases = ('Peak15_V2','')
"""Do not remove the single quotes from the end, these allow you to use the
python even a single scenario """
archSub = Ruta + '\\' + 'QV_VN15.sub'
archMon = Ruta + '\\' + 'QV_VN15.mon'
archCon = Ruta + '\\' + 'QV_VN15.con'
nodes = (13203,18501,38501,42501, 49501)
"""# Nodes must be entered in the numbers of the buses in which
you want to get the QV curves"""
#psspy.progress_output(2, 'reportePro', [2, 0])
# Create cases and QV governor
for caseN in cases:
if caseN != '':
carpeta = Ruta + '\\' + caseN
if not os.path.isdir(carpeta):
os.makedirs(carpeta)
case = Ruta + '\\' + caseN + '.sav'
Difaxx = carpeta + '\\' + 'Difaxx-' + caseN + '.dfx'
progress = carpeta + '\\' + 'progress_' + caseN + '.txt'
psspy.progress_output(2, progress, [2, 0])
psspy.case(case)
psspy.fnsl([1, 0, 0, 1, 1, 0, 0, 0])
psspy.dfax([1, 1], archSub, archMon, archCon, Difaxx)
rows=[]
count=0
for node in nodes:
count+=1
node1 = str(node)
archivoqv = carpeta + '\\' + 'QV_' + node1
ierr2 = psspy.qv_engine_4([0, 0, 0, 0, 0, 0, 1, 1, 0, 1, node, 0, 0],
[0.5, 1.05, 0.5, 0.01],"",Difaxx,"","",archivoqv,"")
if ierr2 != 0:
continue
# Change these values as required.
qvfile = 'QV_' + node1 + ".qv"
qvfile1 = carpeta + '\\''QV_' + node1 + ".qv"
Q=['Q(MVAr))']
V=['V'+'_'+str(node)]
Contingencies = pssarrays.qv_summary(qvfile1).colabel
colabel=Contingencies[0]
ierr, cval = psspy.notona(node)
rlst = pssarrays.qv_solution(qvfile1, colabel)
v = rlst.vsetpoint
q = rlst.mgenmvar
Q.extend(q)
V.extend(v)
if count==1:
rows=[]
for q,v in zip(Q,V):
row=[q]
row.extend([v])
rows.append(row)
else:
for row,vol in zip(rows,V):
row.append(vol)
for row,mvar in zip(rows,Q):
rows.append(mvar)
Report = carpeta + '\\' + 'Report' + '.csv'
csv_out = open(Report, 'wb')
mywriter = csv.writer(csv_out)
mywriter.writerows(rows)
#plt.plot(v, q)
csv_out.close()
Edit: I got the error message. It should be:
row.append(mvar)
Instead of rows.append(mvar)
. But any idea to improve the code is appropriated.
3 | No.3 Revision |
Hi, folks. I am trying to do multiple QV analyses and wirte data to csv file. Data contain Vsetpoint and Q of fictious generator, write along columns. But when I used:
ierr, cval = psspy.notona(node)
rlst = pssarrays.qv_solution(qvfile1, colabel)
v = rlst.vsetpoint
q = (rlst.mgenmvar)
I got q with size (199*length(v)) more bigger than what I expected (1 * length(v)). All of my monitored buses in .mon file are type 1, so I just don't know why it is so big. Is there anyway to get q of fictious generator contacted with the interested bus in those data or just an simpler way to get direct Q without relating to rlst.mgenmvar.
Also, I got an error message when try to do second interation. It is TypeError: 'float' object is not iterable in
for row,vol in zip(rows,V):
row.append(vol)
for row,mvar in zip(rows,Q):
rows.append(mvar)
Here is my code( I edited from code in https://psspy.org/psse-help-forum/question/444/what-is-the-api-for-generating-the-qv-files/).
# created by: Waltter Valdez
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()
cases = ('Peak15_V2','')
"""Do not remove the single quotes from the end, these allow you to use the
python even a single scenario """
archSub = Ruta + '\\' + 'QV_VN15.sub'
archMon = Ruta + '\\' + 'QV_VN15.mon'
archCon = Ruta + '\\' + 'QV_VN15.con'
nodes = (13203,18501,38501,42501, 49501)
"""# Nodes must be entered in the numbers of the buses in which
you want to get the QV curves"""
#psspy.progress_output(2, 'reportePro', [2, 0])
# Create cases and QV governor
for caseN in cases:
if caseN != '':
carpeta = Ruta + '\\' + caseN
if not os.path.isdir(carpeta):
os.makedirs(carpeta)
case = Ruta + '\\' + caseN + '.sav'
Difaxx = carpeta + '\\' + 'Difaxx-' + caseN + '.dfx'
progress = carpeta + '\\' + 'progress_' + caseN + '.txt'
psspy.progress_output(2, progress, [2, 0])
psspy.case(case)
psspy.fnsl([1, 0, 0, 1, 1, 0, 0, 0])
psspy.dfax([1, 1], archSub, archMon, archCon, Difaxx)
rows=[]
count=0
for node in nodes:
count+=1
node1 = str(node)
archivoqv = carpeta + '\\' + 'QV_' + node1
ierr2 = psspy.qv_engine_4([0, 0, 0, 0, 0, 0, 1, 1, 0, 1, node, 0, 0],
[0.5, 1.05, 0.5, 0.01],"",Difaxx,"","",archivoqv,"")
if ierr2 != 0:
continue
# Change these values as required.
qvfile = 'QV_' + node1 + ".qv"
qvfile1 = carpeta + '\\''QV_' + node1 + ".qv"
Q=['Q(MVAr))']
V=['V'+'_'+str(node)]
Contingencies = pssarrays.qv_summary(qvfile1).colabel
colabel=Contingencies[0]
ierr, cval = psspy.notona(node)
rlst = pssarrays.qv_solution(qvfile1, colabel)
v = rlst.vsetpoint
q = rlst.mgenmvar
Q.extend(q)
V.extend(v)
if count==1:
rows=[]
for q,v in zip(Q,V):
row=[q]
row.extend([v])
rows.append(row)
else:
for row,vol in zip(rows,V):
row.append(vol)
for row,mvar in zip(rows,Q):
rows.append(mvar)
Report = carpeta + '\\' + 'Report' + '.csv'
csv_out = open(Report, 'wb')
mywriter = csv.writer(csv_out)
mywriter.writerows(rows)
#plt.plot(v, q)
csv_out.close()
Edit: I got the error message. It should be:
row.append(mvar)
row.extend([mvar])
Instead of rows.append(mvar)
. But any idea to improve the code is appropriated.
4 | No.4 Revision |
Hi, folks. I am trying to do multiple QV analyses and wirte data to csv file. Data contain Vsetpoint and Q of fictious generator, write along columns. But when I used:
ierr, cval = psspy.notona(node)
rlst = pssarrays.qv_solution(qvfile1, colabel)
v = rlst.vsetpoint
q = (rlst.mgenmvar)
I got q with size (199*length(v)) more bigger than what I expected (1 * length(v)). All of my monitored buses in .mon file are type 1, so I just don't know why it is so big. Is there anyway to get q of fictious generator contacted with the interested bus in those data or just an simpler way to get direct Q without relating to rlst.mgenmvar.
Also, I got an error message when try to do second interation. It is TypeError: 'float' object is not iterable in
for row,vol in zip(rows,V):
row.append(vol)
for row,mvar in zip(rows,Q):
rows.append(mvar)
Here is my code( I edited from code in https://psspy.org/psse-help-forum/question/444/what-is-the-api-for-generating-the-qv-files/).
# created by: Waltter Valdez
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()
cases = ('Peak15_V2','')
"""Do not remove the single quotes from the end, these allow you to use the
python even a single scenario """
archSub = Ruta + '\\' + 'QV_VN15.sub'
archMon = Ruta + '\\' + 'QV_VN15.mon'
archCon = Ruta + '\\' + 'QV_VN15.con'
nodes = (13203,18501,38501,42501, 49501)
"""# Nodes must be entered in the numbers of the buses in which
you want to get the QV curves"""
#psspy.progress_output(2, 'reportePro', [2, 0])
# Create cases and QV governor
for caseN in cases:
if caseN != '':
carpeta = Ruta + '\\' + caseN
if not os.path.isdir(carpeta):
os.makedirs(carpeta)
case = Ruta + '\\' + caseN + '.sav'
Difaxx = carpeta + '\\' + 'Difaxx-' + caseN + '.dfx'
progress = carpeta + '\\' + 'progress_' + caseN + '.txt'
psspy.progress_output(2, progress, [2, 0])
psspy.case(case)
psspy.fnsl([1, 0, 0, 1, 1, 0, 0, 0])
psspy.dfax([1, 1], archSub, archMon, archCon, Difaxx)
rows=[]
count=0
for node in nodes:
count+=1
node1 = str(node)
archivoqv = carpeta + '\\' + 'QV_' + node1
ierr2 = psspy.qv_engine_4([0, 0, 0, 0, 0, 0, 1, 1, 0, 1, node, 0, 0],
[0.5, 1.05, 0.5, 0.01],"",Difaxx,"","",archivoqv,"")
if ierr2 != 0:
continue
# Change these values as required.
qvfile = 'QV_' + node1 + ".qv"
qvfile1 = carpeta + '\\''QV_' + node1 + ".qv"
Q=['Q(MVAr))']
V=['V'+'_'+str(node)]
Contingencies = pssarrays.qv_summary(qvfile1).colabel
colabel=Contingencies[0]
ierr, cval = psspy.notona(node)
rlst = pssarrays.qv_solution(qvfile1, colabel)
v = rlst.vsetpoint
q = rlst.mgenmvar
Q.extend(q)
V.extend(v)
if count==1:
rows=[]
for q,v in zip(Q,V):
row=[q]
row.extend([v])
rows.append(row)
else:
for row,vol in zip(rows,V):
row.append(vol)
for row,mvar in zip(rows,Q):
rows.append(mvar)
Report = carpeta + '\\' + 'Report' + '.csv'
csv_out = open(Report, 'wb')
mywriter = csv.writer(csv_out)
mywriter.writerows(rows)
#plt.plot(v, q)
csv_out.close()
Edit: I got the error message. It should be:
row.extend([mvar])
Instead of rows.append(mvar)
. But any idea to improve the code is appropriated.
I used another code in forum and get the result I want. Here the code:
# PSS/E Saved case
#import numpy as np
#import matplotlib.pyplot as plt
import psspy
import os
import csv
def floatrange(start, stop, step):
# for loop with float variable
while abs(start - stop)>abs(step):
yield start
start += step
CASE = r"Peak15_V2"
busno = 99999 # Fictitious generator bus
genid = 1
status = 1
pgen = 0.0 # Fict gen P output
Qlimit = 9999.0 # Fict. gen Q limit
pmax = 0.0 # Fict gen P limit
iregs = [38501,42501,43501,44501,49501,55501]
# Regulated bus for which QV curve is to be determined
#--------------------------------
def add_machine(busno,ireg,genid,status,pgen,Qlimit,pmax):
psspy.plant_data(busno, intgar1=ireg)
psspy.machine_data_2(
busno,
str(genid),
intgar1=int(status),
realar1=pgen,
realar3=Qlimit,
realar4=-Qlimit,
realar5=pmax)
def get_mvar(i):
"""
Changes the voltage set point at the synchronous machine
solves the case
returns the the new reactive power output of the sync machine.
"""
psspy.plant_data(busno, realar1=i)
ierr = psspy.fnsl()
ierr, mvar = psspy.macdat(busno, str(genid), 'Q')
return mvar
psspy.psseinit(12000)
rows=[]
count=1
for ireg in iregs:
psspy.case(CASE)
psspy.solution_parameters_3(intgar2=60) # set number of solution iterations.
psspy.bus_data_2(busno, intgar1=2, name='TEST')
psspy.branch_data(i=busno, j=ireg)
add_machine(busno,ireg,genid,status,pgen,Qlimit,pmax)
pu = [x for x in floatrange(1.2, 0.5, -0.01)]
varlist = [get_mvar(v) for v in pu]
pu.insert(0,'V_'+str(ireg))
varlist.insert(0,'Q_'+str(ireg))
if count==1:
for q,v in zip(varlist,pu):
row=[q]
row.extend([v])
rows.append(row)
else:
for row,mvar in zip(rows,varlist):
row.extend([mvar])
for row,vol in zip(rows,pu):
row.extend([vol])
count=count+1
Ruta = os.getcwd()
Report = Ruta + '\\' + 'Report' + '.csv'
csv_out = open(Report, 'wb')
mywriter = csv.writer(csv_out)
mywriter.writerows(rows)
csv_out.close()
5 | No.5 Revision |
Hi, folks. I am trying to do multiple QV analyses and wirte data to csv file. Data contain Vsetpoint and Q of fictious generator, write along columns. But when I used:
ierr, cval = psspy.notona(node)
rlst = pssarrays.qv_solution(qvfile1, colabel)
v = rlst.vsetpoint
q = (rlst.mgenmvar)
I got q with size (199*length(v)) more bigger than what I expected (1 * length(v)). All of my monitored buses in .mon file are type 1, so I just don't know why it is so big. Is there anyway to get q of fictious generator contacted with the interested bus in those data or just an simpler way to get direct Q without relating to rlst.mgenmvar.
Also, I got an error message when try to do second interation. It is TypeError: 'float' object is not iterable in
for row,vol in zip(rows,V):
row.append(vol)
for row,mvar in zip(rows,Q):
rows.append(mvar)
Here is my code( I edited from code in https://psspy.org/psse-help-forum/question/444/what-is-the-api-for-generating-the-qv-files/).
# created by: Waltter Valdez
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()
cases = ('Peak15_V2','')
"""Do not remove the single quotes from the end, these allow you to use the
python even a single scenario """
archSub = Ruta + '\\' + 'QV_VN15.sub'
archMon = Ruta + '\\' + 'QV_VN15.mon'
archCon = Ruta + '\\' + 'QV_VN15.con'
nodes = (13203,18501,38501,42501, 49501)
"""# Nodes must be entered in the numbers of the buses in which
you want to get the QV curves"""
#psspy.progress_output(2, 'reportePro', [2, 0])
# Create cases and QV governor
for caseN in cases:
if caseN != '':
carpeta = Ruta + '\\' + caseN
if not os.path.isdir(carpeta):
os.makedirs(carpeta)
case = Ruta + '\\' + caseN + '.sav'
Difaxx = carpeta + '\\' + 'Difaxx-' + caseN + '.dfx'
progress = carpeta + '\\' + 'progress_' + caseN + '.txt'
psspy.progress_output(2, progress, [2, 0])
psspy.case(case)
psspy.fnsl([1, 0, 0, 1, 1, 0, 0, 0])
psspy.dfax([1, 1], archSub, archMon, archCon, Difaxx)
rows=[]
count=0
for node in nodes:
count+=1
node1 = str(node)
archivoqv = carpeta + '\\' + 'QV_' + node1
ierr2 = psspy.qv_engine_4([0, 0, 0, 0, 0, 0, 1, 1, 0, 1, node, 0, 0],
[0.5, 1.05, 0.5, 0.01],"",Difaxx,"","",archivoqv,"")
if ierr2 != 0:
continue
# Change these values as required.
qvfile = 'QV_' + node1 + ".qv"
qvfile1 = carpeta + '\\''QV_' + node1 + ".qv"
Q=['Q(MVAr))']
V=['V'+'_'+str(node)]
Contingencies = pssarrays.qv_summary(qvfile1).colabel
colabel=Contingencies[0]
ierr, cval = psspy.notona(node)
rlst = pssarrays.qv_solution(qvfile1, colabel)
v = rlst.vsetpoint
q = rlst.mgenmvar
Q.extend(q)
V.extend(v)
if count==1:
rows=[]
for q,v in zip(Q,V):
row=[q]
row.extend([v])
rows.append(row)
else:
for row,vol in zip(rows,V):
row.append(vol)
for row,mvar in zip(rows,Q):
rows.append(mvar)
Report = carpeta + '\\' + 'Report' + '.csv'
csv_out = open(Report, 'wb')
mywriter = csv.writer(csv_out)
mywriter.writerows(rows)
#plt.plot(v, q)
csv_out.close()
Edit: I got the error message. It should be:
row.extend([mvar])
Instead of rows.append(mvar)
. But any idea to improve the code is appropriated.
I used another code in forum and get the result I want. want (but still have some problem with blown up cases). Here the code:
# PSS/E Saved case
#import numpy as np
#import matplotlib.pyplot as plt
import psspy
import os
import csv
def floatrange(start, stop, step):
# for loop with float variable
while abs(start - stop)>abs(step):
yield start
start += step
CASE = r"Peak15_V2"
busno = 99999 # Fictitious generator bus
genid = 1
status = 1
pgen = 0.0 # Fict gen P output
Qlimit = 9999.0 # Fict. gen Q limit
pmax = 0.0 # Fict gen P limit
iregs = [38501,42501,43501,44501,49501,55501]
# Regulated bus for which QV curve is to be determined
#--------------------------------
def add_machine(busno,ireg,genid,status,pgen,Qlimit,pmax):
psspy.plant_data(busno, intgar1=ireg)
psspy.machine_data_2(
busno,
str(genid),
intgar1=int(status),
realar1=pgen,
realar3=Qlimit,
realar4=-Qlimit,
realar5=pmax)
def get_mvar(i):
"""
Changes the voltage set point at the synchronous machine
solves the case
returns the the new reactive power output of the sync machine.
"""
psspy.plant_data(busno, realar1=i)
ierr = psspy.fnsl()
ierr, mvar = psspy.macdat(busno, str(genid), 'Q')
return mvar
psspy.psseinit(12000)
rows=[]
count=1
for ireg in iregs:
psspy.case(CASE)
psspy.solution_parameters_3(intgar2=60) # set number of solution iterations.
psspy.bus_data_2(busno, intgar1=2, name='TEST')
psspy.branch_data(i=busno, j=ireg)
add_machine(busno,ireg,genid,status,pgen,Qlimit,pmax)
pu = [x for x in floatrange(1.2, 0.5, -0.01)]
varlist = [get_mvar(v) for v in pu]
pu.insert(0,'V_'+str(ireg))
varlist.insert(0,'Q_'+str(ireg))
if count==1:
for q,v in zip(varlist,pu):
row=[q]
row.extend([v])
rows.append(row)
else:
for row,mvar in zip(rows,varlist):
row.extend([mvar])
for row,vol in zip(rows,pu):
row.extend([vol])
count=count+1
Ruta = os.getcwd()
Report = Ruta + '\\' + 'Report' + '.csv'
csv_out = open(Report, 'wb')
mywriter = csv.writer(csv_out)
mywriter.writerows(rows)
csv_out.close()
6 | No.6 Revision |
Hi, folks. I am trying to do multiple QV analyses and wirte data to csv file. Data contain Vsetpoint and Q of fictious generator, write along columns. But when I used:
ierr, cval = psspy.notona(node)
rlst = pssarrays.qv_solution(qvfile1, colabel)
v = rlst.vsetpoint
q = (rlst.mgenmvar)
I got q with size (199*length(v)) more bigger than what I expected (1 * length(v)). All of my monitored buses in .mon file are type 1, so I just don't know why it is so big. Is there anyway to get q of fictious generator contacted with the interested bus in those data or just an simpler way to get direct Q without relating to rlst.mgenmvar.
Also, I got an error message when try to do second interation. It is TypeError: 'float' object is not iterable in
for row,vol in zip(rows,V):
row.append(vol)
for row,mvar in zip(rows,Q):
rows.append(mvar)
Here is my code( I edited from code in https://psspy.org/psse-help-forum/question/444/what-is-the-api-for-generating-the-qv-files/).
# created by: Waltter Valdez
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()
cases = ('Peak15_V2','')
('savnw','')
"""Do not remove the single quotes from the end, these allow you to use the
python even a single scenario """
archSub = Ruta + '\\' + 'QV_VN15.sub'
'savnw.sub'
archMon = Ruta + '\\' + 'QV_VN15.mon'
'savnw.mon'
archCon = Ruta + '\\' + 'QV_VN15.con'
'savnw.con'
nodes = (13203,18501,38501,42501, 49501)
(153,154)
"""# Nodes must be entered in the numbers of the buses in which
you want to get the QV curves"""
#psspy.progress_output(2, 'reportePro', [2, 0])
# Create cases and QV governor
for caseN in cases:
if caseN != '':
carpeta = Ruta + '\\' + caseN
if not os.path.isdir(carpeta):
os.makedirs(carpeta)
case = Ruta + '\\' + caseN + '.sav'
Difaxx = carpeta + '\\' + 'Difaxx-' + caseN + '.dfx'
progress = carpeta + '\\' + 'progress_' + caseN + '.txt'
psspy.progress_output(2, progress, [2, 0])
psspy.case(case)
psspy.fnsl([1, 0, 0, 1, 1, 0, 0, 0])
psspy.dfax([1, 1], archSub, archMon, archCon, Difaxx)
rows=[]
count=0
for node in nodes:
count+=1
psspy.case(case)
node1 = str(node)
archivoqv = carpeta + '\\' + 'QV_' + node1
ierr2 = psspy.qv_engine_4([0, 0, 0, 0, 0, 0, 1, 1, 0, 1, node, 0, 0],
[0.5, 1.05, 0.5, 0.01],"",Difaxx,"","",archivoqv,"")
if ierr2 != 0:
continue
# Change these values as required.
qvfile = 'QV_' + node1 + ".qv"
qvfile1 = carpeta + '\\''QV_' + node1 + ".qv"
Q=['Q(MVAr))']
V=['V'+'_'+str(node)]
Contingencies = pssarrays.qv_summary(qvfile1).colabel
colabel=Contingencies[0]
ierr, cval = psspy.notona(node)
rlst = pssarrays.qv_solution(qvfile1, colabel)
v = rlst.vsetpoint
q = rlst.mgenmvar
Q.extend(q)
V.extend(v)
if count==1:
rows=[]
for q,v in zip(Q,V):
row=[q]
row.extend([v])
rows.append(row)
else:
for row,vol in zip(rows,V):
row.append(vol)
for row,mvar in zip(rows,Q):
rows.append(mvar) row.append(mvar)
Report = carpeta + '\\' + 'Report' + '.csv'
csv_out = open(Report, 'wb')
mywriter = csv.writer(csv_out)
mywriter.writerows(rows)
#plt.plot(v, q)
csv_out.close()
Edit: I got the error message. It should be:
row.extend([mvar])
row.extend(mvar])
Instead of rows.append(mvar)
. But any idea to improve the code is appropriated.
I used another code in forum and get the result I want (but still have some problem with blown up cases). Here the code:
# PSS/E Saved case
#import numpy as np
#import matplotlib.pyplot as plt
import psspy
import os
import csv
def floatrange(start, stop, step):
# for loop with float variable
while abs(start - stop)>abs(step):
yield start
start += step
CASE = r"Peak15_V2"
busno = 99999 # Fictitious generator bus
genid = 1
status = 1
pgen = 0.0 # Fict gen P output
Qlimit = 9999.0 # Fict. gen Q limit
pmax = 0.0 # Fict gen P limit
iregs = [38501,42501,43501,44501,49501,55501]
# Regulated bus for which QV curve is to be determined
#--------------------------------
def add_machine(busno,ireg,genid,status,pgen,Qlimit,pmax):
psspy.plant_data(busno, intgar1=ireg)
psspy.machine_data_2(
busno,
str(genid),
intgar1=int(status),
realar1=pgen,
realar3=Qlimit,
realar4=-Qlimit,
realar5=pmax)
def get_mvar(i):
"""
Changes the voltage set point at the synchronous machine
solves the case
returns the the new reactive power output of the sync machine.
"""
psspy.plant_data(busno, realar1=i)
ierr = psspy.fnsl()
ierr, mvar = psspy.macdat(busno, str(genid), 'Q')
return mvar
psspy.psseinit(12000)
rows=[]
count=1
for ireg in iregs:
psspy.case(CASE)
psspy.solution_parameters_3(intgar2=60) # set number of solution iterations.
psspy.bus_data_2(busno, intgar1=2, name='TEST')
psspy.branch_data(i=busno, j=ireg)
add_machine(busno,ireg,genid,status,pgen,Qlimit,pmax)
pu = [x for x in floatrange(1.2, 0.5, -0.01)]
varlist = [get_mvar(v) for v in pu]
pu.insert(0,'V_'+str(ireg))
varlist.insert(0,'Q_'+str(ireg))
if count==1:
for q,v in zip(varlist,pu):
row=[q]
row.extend([v])
rows.append(row)
else:
for row,mvar in zip(rows,varlist):
row.extend([mvar])
for row,vol in zip(rows,pu):
row.extend([vol])
count=count+1
Ruta = os.getcwd()
Report = Ruta + '\\' + 'Report' + '.csv'
csv_out = open(Report, 'wb')
mywriter = csv.writer(csv_out)
mywriter.writerows(rows)
csv_out.close()