Ask Your Question
0

QV Analysis Automation Script

asked 2017-06-26 16:01:20 -0500

Paalang gravatar image

updated 2017-06-26 16:03:55 -0500

Hi folks!

I really need to run QV analysis for several buses with contingencies and export all the results for all buses and all contingencies in a spreadsheet as follows,

BUSNumber Contingency MVARReserve Vmincollapse

There is an script in in forum to generate QV results; but it asks for a governor or something that I did not quit get that. Also, it generates separate workbooks for each bus, that is not my interest. It'd be really appreciated if you can share a python script to generate such a spreadsheet or a similar for me. Thank you.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2017-07-18 21:15:38 -0500

ays gravatar image

updated 2017-07-18 21:21:33 -0500

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 ...
(more)
edit flag offensive delete link more
0

answered 2017-07-18 18:41:15 -0500

knucklehead gravatar image

updated 2017-07-18 18:45:51 -0500

To my knowledge QV Analysis is performed on one bus at a time. Although you could loop the analysis across multiple buses. I suppose this is why you would typically have a sheet for each bus. In regards to MVARReserve and Vmincollapse... Not sure what you are after. The QV Analysis puts an infinite dynamic reactive source on the bus, and all other reactive devices must be switched out or locked. Anyhow, here is some code that might help:

def GetQVSolution(studybus,dfxfile,qvfile,mismatchtol,vhighsetpoint,vlowsetpoint,adjtaps,adjpsts,adjswshunts):
    qverrdict = {0: 'NO ERROR',
                 1: 'INVALID VALUES VALUE',
                 2: 'INVALID OPTIONS VALUE',
                 3: 'GENERATORS ARE CONVERTED',
                 4: 'BUSES IN ISLAND(S) WITHOUT A SWING BUS; USE ACTIVITY TREE',
                 5: 'LARGEST MISMATCH EXCEEDS MISMATCH TOLERANCE',
                 6: 'VHI IS NOT GREATER THAN VLO',
                 7: 'STUDY BUS NOT FOUND',
                 8: 'SWShunt Not Locked Or Gen Controlling?',
                 9: 'ERROR WHEN ADDING A PLANT TO THE STUDY BUS',
                10: 'ERROR WHEN ADDING A MACHINE TO THE STUDY BUS',
                11: 'BASE CASE VHI SOLUTION DID NOT CONVERGE',
                12: 'NO DISTRIBUTION FACTOR DATA FILE SPECIFIED',
                13: 'NO Q-V SOLUTION OUTPUT FILE SPECIFIED',
                14: 'NO ZIP ARCHIVE OUTPUT FILE SPECIFIED',
                15: 'IN-SERVICE INDUCTION MACHINES ARE IN THE STALLED OR TRIPPED STATE',
                16: 'BUS TYPE CODE AND SERIES ELEMENT STATUS INCONSISTENCIES',
                17: 'NO DISPATCH SUBSYSTEM IS SPECIFIED',
                18: 'MORE THAN 10 ISLANDS IN THE BASE CASE',
                21: 'FILE DFXFILE IS NOT IN THE FORM OF A PSSE-25 OR LATER DFAX FILE; RUN DFAX',
                22: 'MONITORED ELEMENTS EXCEED LIMIT WHEN ADDING MULTISECTION LINE MEMBERS',
                23: 'NO SUBSYSTEMS DEFINED',
                24: 'SUBSYSTEM NOT FOUND',
                51: 'ERROR OPENING QV RESULTS FILE',
                52: 'ERROR OPENING DISTRIBUTION FACTOR DATA FILE',
                53: 'ERROR OPENING LOAD THROWOVER DATA FILE',
                54: 'ERROR OPENING INERTIA AND GOVERNOR RESPONSE DATA FILE',
                55: 'ERROR OPENING ZIP ARCHIVE OUTPUT FILE',
                56: 'PREREQUISITE REQUIREMENTS FOR API ARE NOT MET',
                99: 'TERMINATED BY USER INTERRUPT OR FILE ERROR'}

    #QV OPTIONS ----------------------------------------------------------------
    a=adjtaps       # tap adjustment flag
    b=0             # area interchange adjustment flag
    c=adjpsts       # phase shifter adjustment flag
    d=1             # dc tap adjustment flag
    e=adjswshunts   # switched shunt adjustment flag(0,1,2-Enable Continuous Only)
    f=0             # induction motor treatment flag
    g=0             # non-divergent solution flag
    h=0             # solution method flag (0-Fixed Slope, 1-Full Newton, 2-Optimized Fixed Slope)
    i=0             # var limit for the VHI solution (0-Apply Immediately, 1-Ignore then Apply)
    j=0             # var limit code for subsequent solutons (0-Apply Immediately, 1-Ignore then Apply)
    k=studybus      # Study Bus Number (Input to this Function)
    l=0             # dispatch mode for power imbalances resulting from the application of contingencies
    m=0             # Zip archive flag

    A=mismatchtol   # mismatch tolerance in MW and Mvar
    B=vhighsetpoint # per unit initial (maximum) setpoint voltage for study bus
    C=vlowsetpoint  # per unit minimum setpoint voltage for study bus
    D=0.01          # per unit voltage setpoint decrement

    qverr=psspy.qv_engine_4([a,b,c,d,e,f,g,h,i,j,k,l,m],[A,B,C,D],'',dfxfile,'','',qvfile,'')
    errordesc=qverrdict[qverr]
    return qverr,errordesc

3phaseee.com

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: 2017-06-26 16:01:20 -0500

Seen: 4,861 times

Last updated: Jul 18 '17