Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

ACCC script for multiple cases - crashes depending on the order of cases. How do I debug?

Hi,

I've written a script to run ACCC studies on multiple cases. The script reads in from a .dat file the names of the relevant .sav, .sub, .mon and .con files and then creates .dfx, .acc and .xlsx files also based on specifications in the .dat file.

Below is a screen shot of the .dat file contents:

image description

The weird issue I'm having is that my script works fine (i.e. produces all three ACCC reports in excel) if the order of cases listed in the data file begins with Testcase2.sav.

But if Testcase1.sav or Testcase3.sav are listed first (as in the screenshot example), the script will create only one ACCC report and then just stop running (without throwing up any errors) when it is part way through making the second .acc file.

My question is, what debugging techniques can I use to try and find out why this is happening?

My code is below, I'm already using psspy.throwPsseExceptions = True, I've had a go at using logging but you can probably tell from the code I don't know what I'm doing with it.

Thanks,

Peter

import math, sys, csv,os, logging

# Location of libraries
sys.path.append("C:\Program Files (x86)\PTI\PSSE32\PSSBIN")   # psspy

PSSE_LOCATION = r'C:\Program Files (x86)\PTI\PSSE32\PSSBIN'
sys.path.append(PSSE_LOCATION)
os.environ['PATH'] = os.environ['path'] + ';' + PSSE_LOCATION

import psspy, pssexcel, excelpy
import redirect      #redirects popups
redirect.psse2py()
psspy.psseinit()     #initialise PSSE so psspy commands can be called
psspy.throwPsseExceptions = True

def clearall():
    all = [var for var in globals() if (var[:2], var[-2:]) != ("__", "__")]
    for var in all:
        del globals()[var]

class IOFile:

    #To retrieve data from input.csv input file
    def Input_File(self):
        try:
            fileinput_tmp = open('input_ACCC_123.dat','rb')
            fileinput = csv.reader(fileinput_tmp)

        except IOError:
            psspy.lines_per_page_one_device(2,10000000)
            psspy.progress_output(1,"",[0,0])
            print ' **************** Input File Not Found **************** '
        else:
            pass

        #To store sav,sub,mon,con,dfx,accc,excel
        sav=[]
        sub=[]
        mon=[]
        con=[]
        dfx=[]
        accc=[]
        excel=[]


        for numcase, row in enumerate(fileinput):
            if row[0]=='0':
                break
            sav.append(row[0]) 
            sub.append(row[1])
            mon.append(row[2])
            con.append(row[3])
            dfx.append(row[4])
            accc.append(row[5])
            excel.append(row[6])


        #To close input file
        fileinput_tmp.close()

        return sav,sub,mon,con,dfx,accc,excel,numcase

class Run:

    #To perform ACCC in all cases 
    def multi_ACCC(self,sav,sub,mon,con,dfx,accc,excel,numcase):
        #newcase=[]

        for i in range(0,numcase,1):
            psspy.base_frequency( 50.0)
            psspy.case(sav[i])
            print'sav file opened'

            """Run ACCC"""
            psspy.dfax([1,1], sub[i], mon[i], con[i], dfx[i])
            print'dfx file created'
            psspy.accc( 0.5,[1,1,0,1,1,1,0],dfx[i],accc[i],"")
            print'acc file created'

            # 's' or 'summary' ACCC Analysis Summary
            # 'e' or 'events' Contingency Events Description
            # 'b' or 'branch' Monitored Branch Flow (MVA)
            # 'i' or 'interface' Monitored Interface Flow (MW)
            # 'v' or 'voltage' Monitored Bus Voltage
            # 'l' or 'load' Loads Shed (MW)
            # 'g' or 'generator' Generator Dispatch (MW)
            # 'p' or 'phase shifter' Phase Shifter Angle

            options = ['s','e','b']

            pssexcel.accc(accfile=accc[i], string=options, xlsfile=excel[i], ratecon = 'a')
            xl = excelpy.workbook()
            xl.close()
            print'excel file closed'
        return 

#Execute program 
if __name__ == '__main__':

    try:

        #To save progress to output files
        psspy.lines_per_page_one_device(1,10000)
        psspy.progress_output(2,r"""PDEV""",[0,0])


        #To execute functions from respective classes
        myIOFile=IOFile()
        sav,sub,mon,con,dfx,accc,excel,numcase = myIOFile.Input_File()

        myRun=Run()
        newcase = myRun.multi_ACCC(sav,sub,mon,con,dfx,accc,excel,numcase)

        #logging
        logging.basicConfig(filename='logfile.log', filemode='w',level=logging.DEBUG)
        logging.debug('This message should go to the log file')
        logging.info('So should this')
        logging.warning('And this, too')

        #To close progress files
        psspy.lines_per_page_one_device(2,10000000)
        psspy.progress_output(1,"",[0,0])

        #Completion Notice
        print ' '
        print '************************** ACCC complete, check PEDV.dat for progress **************************'

    except ValueError:
        #To close progress files
        print ' Error Occured'
        psspy.lines_per_page_one_device(2,10000000)
        psspy.progress_output(1,"",[0,0])
click to hide/show revision 2
fixed italics

ACCC script for multiple cases - crashes depending on the order of cases. How do I debug?

Hi,

I've written a script to run ACCC studies on multiple cases. The script reads in from a .dat file the names of the relevant .sav, .sub, .mon and .con files and then creates .dfx, .acc and .xlsx files also based on specifications in the .dat file.

Below is a screen shot of the .dat file contents:

image description

The weird issue I'm having is that my script works fine (i.e. produces all three ACCC reports in excel) if the order of cases listed in the data file begins with Testcase2.sav.Test_case_2.sav.

But if Testcase1.sav Test_case_1.sav or Testcase3.sav Test_case_3.sav are listed first (as in the screenshot example), the script will create only one ACCC report and then just stop running (without throwing up any errors) when it is part way through making the second .acc file.

My question is, what debugging techniques can I use to try and find out why this is happening?

My code is below, I'm already using psspy.throwPsseExceptions = True, True, I've had a go at using logging but you can probably tell from the code I don't know what I'm doing with it.

Thanks,

Peter

import math, sys, csv,os, logging

# Location of libraries
sys.path.append("C:\Program Files (x86)\PTI\PSSE32\PSSBIN")   # psspy

PSSE_LOCATION = r'C:\Program Files (x86)\PTI\PSSE32\PSSBIN'
sys.path.append(PSSE_LOCATION)
os.environ['PATH'] = os.environ['path'] + ';' + PSSE_LOCATION

import psspy, pssexcel, excelpy
import redirect      #redirects popups
redirect.psse2py()
psspy.psseinit()     #initialise PSSE so psspy commands can be called
psspy.throwPsseExceptions = True

def clearall():
    all = [var for var in globals() if (var[:2], var[-2:]) != ("__", "__")]
    for var in all:
        del globals()[var]

class IOFile:

    #To retrieve data from input.csv input file
    def Input_File(self):
        try:
            fileinput_tmp = open('input_ACCC_123.dat','rb')
            fileinput = csv.reader(fileinput_tmp)

        except IOError:
            psspy.lines_per_page_one_device(2,10000000)
            psspy.progress_output(1,"",[0,0])
            print ' **************** Input File Not Found **************** '
        else:
            pass

        #To store sav,sub,mon,con,dfx,accc,excel
        sav=[]
        sub=[]
        mon=[]
        con=[]
        dfx=[]
        accc=[]
        excel=[]


        for numcase, row in enumerate(fileinput):
            if row[0]=='0':
                break
            sav.append(row[0]) 
            sub.append(row[1])
            mon.append(row[2])
            con.append(row[3])
            dfx.append(row[4])
            accc.append(row[5])
            excel.append(row[6])


        #To close input file
        fileinput_tmp.close()

        return sav,sub,mon,con,dfx,accc,excel,numcase

class Run:

    #To perform ACCC in all cases 
    def multi_ACCC(self,sav,sub,mon,con,dfx,accc,excel,numcase):
        #newcase=[]

        for i in range(0,numcase,1):
            psspy.base_frequency( 50.0)
            psspy.case(sav[i])
            print'sav file opened'

            """Run ACCC"""
            psspy.dfax([1,1], sub[i], mon[i], con[i], dfx[i])
            print'dfx file created'
            psspy.accc( 0.5,[1,1,0,1,1,1,0],dfx[i],accc[i],"")
            print'acc file created'

            # 's' or 'summary' ACCC Analysis Summary
            # 'e' or 'events' Contingency Events Description
            # 'b' or 'branch' Monitored Branch Flow (MVA)
            # 'i' or 'interface' Monitored Interface Flow (MW)
            # 'v' or 'voltage' Monitored Bus Voltage
            # 'l' or 'load' Loads Shed (MW)
            # 'g' or 'generator' Generator Dispatch (MW)
            # 'p' or 'phase shifter' Phase Shifter Angle

            options = ['s','e','b']

            pssexcel.accc(accfile=accc[i], string=options, xlsfile=excel[i], ratecon = 'a')
            xl = excelpy.workbook()
            xl.close()
            print'excel file closed'
        return 

#Execute program 
if __name__ == '__main__':

    try:

        #To save progress to output files
        psspy.lines_per_page_one_device(1,10000)
        psspy.progress_output(2,r"""PDEV""",[0,0])


        #To execute functions from respective classes
        myIOFile=IOFile()
        sav,sub,mon,con,dfx,accc,excel,numcase = myIOFile.Input_File()

        myRun=Run()
        newcase = myRun.multi_ACCC(sav,sub,mon,con,dfx,accc,excel,numcase)

        #logging
        logging.basicConfig(filename='logfile.log', filemode='w',level=logging.DEBUG)
        logging.debug('This message should go to the log file')
        logging.info('So should this')
        logging.warning('And this, too')

        #To close progress files
        psspy.lines_per_page_one_device(2,10000000)
        psspy.progress_output(1,"",[0,0])

        #Completion Notice
        print ' '
        print '************************** ACCC complete, check PEDV.dat for progress **************************'

    except ValueError:
        #To close progress files
        print ' Error Occured'
        psspy.lines_per_page_one_device(2,10000000)
        psspy.progress_output(1,"",[0,0])