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:
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 Test_case_2.sav
.
But if Test_case_1.sav
or 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
, 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 ...
For some reason when I write underscoreX, what comes out is an italicised X. That's why the case names in the question look a bit different to what's in the .dat file. I don't know how to fix that.
just want to know whether you run the code from PSS/E GUI. I noticed that some strange things could happen if I run some python code from Python IDLE, although all the modules were properly imported.
I just ran it from inside PSS/E and it did work, strange. As a matter of principle I'll still try and do some debugging as suggested by @JervisW, so that hopefully I can get it working properly from outside PSS/E. Thanks for the reminder to try the simple solution first @yfwing!
Peter B, regarding to the strange behavior of PSS/E, I talked to technical support of PSS/E sometime ago. The problem comes from the different version of compilers when python module and PSS/E main engine were built. There are some inconsistent internally. It is hard for the user to debug.