Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I have checked the code again and saw that the 1st of each tuple in nested-tuple q is the fictious MVAr that I want to retrieve. So I have edited the code to run properly. Here it is. ( run with sav file in the example folder of PSSE)

# created by: Waltter Valdez
#Edited by Huy Cao

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 = ('savnw','')
"""Do not remove the single quotes from the end, these allow you to use the
python even a single scenario """

archSub = Ruta + '\\' + 'savnw.sub'
archMon = Ruta + '\\' + 'savnw.mon'
archCon = Ruta + '\\' + 'savnw.con'

nodes = (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 =list(rlst.mgenmvar)
            q1=[]
            for e in q:
                q1.append(e[0])
            Q.extend(q1)
            V.extend(v)
            if count==1:
                rows=[]
                for q,v in zip(Q,V):
                    row=[v]
                    row.extend([q])
                    rows.append(row)
            else:
                for row,vol in zip(rows,V):
                    row.append(vol)
                for row,mvar in zip(rows,Q):
                    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()

I have checked the code again and saw that the 1st of each tuple in nested-tuple q is the fictious MVAr that I want to retrieve. So I have edited the code to run properly. Here it is. ( run with sav savnw file in the example folder of PSSE)

# created by: Waltter Valdez
#Edited by Huy Cao

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 = ('savnw','')
"""Do not remove the single quotes from the end, these allow you to use the
python even a single scenario """

archSub = Ruta + '\\' + 'savnw.sub'
archMon = Ruta + '\\' + 'savnw.mon'
archCon = Ruta + '\\' + 'savnw.con'

nodes = (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 =list(rlst.mgenmvar)
            q1=[]
            for e in q:
                q1.append(e[0])
            Q.extend(q1)
            V.extend(v)
            if count==1:
                rows=[]
                for q,v in zip(Q,V):
                    row=[v]
                    row.extend([q])
                    rows.append(row)
            else:
                for row,vol in zip(rows,V):
                    row.append(vol)
                for row,mvar in zip(rows,Q):
                    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()

But when I used the code for another file, I got a problem. It turned out that in some cases the fictious MVAr is another elements. savnw case is just by coincidence.

I have checked the code again and saw that the 1st of each tuple in nested-tuple q is the fictious MVAr that I want to retrieve. So I have edited the code to run properly. Here it is. ( run with savnw file in the example folder of PSSE)

# created by: Waltter Valdez
#Edited by Huy Cao

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 = ('savnw','')
"""Do not remove the single quotes from the end, these allow you to use the
python even a single scenario """

archSub = Ruta + '\\' + 'savnw.sub'
archMon = Ruta + '\\' + 'savnw.mon'
archCon = Ruta + '\\' + 'savnw.con'

nodes = (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 =list(rlst.mgenmvar)
            q1=[]
            for e in q:
                q1.append(e[0])
            Q.extend(q1)
            V.extend(v)
            if count==1:
                rows=[]
                for q,v in zip(Q,V):
                    row=[v]
                    row.extend([q])
                    rows.append(row)
            else:
                for row,vol in zip(rows,V):
                    row.append(vol)
                for row,mvar in zip(rows,Q):
                    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: But when I used the code for another file, I got a problem. It turned out that in some cases the fictious MVAr is another elements. elements instead of 1st of each tuple in nested-tuple q. savnw case is just by coincidence.