Approximation of how I do this:
Running Short circuit and building lots of text files:
def splitter(self, inputlist, chunk=100):
""" Breaks inputlist into a list of lists with size chunk."""
chunks = [inputlist[x:x + chunk] for x in range(0, len(inputlist), chunk)]
return chunks
def RunASCC_study(self, options):
ascc_results = []
# create subsystem of areas in user input
self.createSubsystemOfAreas(options['Areas'])
# find all buses in study areas
study_buses = self.returnBusesInSubsystem(sid=0, in_service_only=False, bus_property='Number')
# make list of buses manageable size for PSS/E report window
self.log('Segmenting %d study buses.' % len(study_buses))
study_buses = self.splitter(study_buses, chunk=100)
# loop thru lists of buses, create subsystems, and perform ASCC on them
self.log('Created %d segments of size %d.\nPerforming ASCC portion of study.' % (
len(study_buses), len(study_buses[0])))
for i, segment_of_study_buses in enumerate(study_buses, 1):
self.createSubsystemOfBuses(segment_of_study_buses, sid=0)
self.log('Running ASCC for segment %d' % i)
self.__ASCC(i, self.report_directory, 0)
def __ASCC(self, out_file_identifier, out_file_path, subsystem, gen_scfiles=False):
"""
:param out_file_identifier: increments file names
:param out_file_path: gives folder to place reports in
:param subsystem: specifies subsystem id for psspy.ascc api
:param gen_scfiles: option flag for scfile output of psspy.ascc api
:return:
"""
ierr = self.psspy.report_output(2, os.path.join(out_file_path, '%d_ASCC_rawData.txt' % out_file_identifier))
if ierr: self.log('Error on ASCC segment %s ier %s' % (out_file_identifier, ierr), 'error')
# class fault analysis conditions
# ierr = self.psspy.flat_2([1, 1, 1, 2, 1, 2, 1, 3], [1, 1])
if gen_scfiles:
if not os.path.exists(os.path.join(out_file_path, 'scfiles')):
os.makedirs(os.path.join(out_file_path, 'scfiles'))
scfile_path = os.path.join(out_file_path, 'scfiles', '%d_scfile.sc' % out_file_identifier)
else:
scfile_path = ""
ierr = self.psspy.ascc_3(subsystem, 0, [1, 1, 0, 1, 0, 2, 0, 1, 0, 1, 1, 0, 0, 2, 2, 1, 1], [1],
'', '', scfile_path)
if ierr: self.log('Error on ASCC segment %s' % out_file_identifier, 'error')
Parsing text files:
def __compileASCCresults(self, folder):
"""
Parses a folder and build ASCC results from PSSE ASCC report txt files.
:param folder: Directory of containing psse reports.
:return: List of result objects.
"""
# get list of report filepaths
list_of_ascc_reports = []
for txtfile in os.listdir(folder):
if txtfile.endswith("ASCC_rawData.txt"):
list_of_ascc_reports.append(os.path.join(folder, txtfile))
# file in memory
data = []
for report in list_of_ascc_reports:
data_file = open(report, 'rU')
data.extend(data_file.readlines())
# parse file
list_of_result_objects = []
options = []
while data:
line = data.pop(0)
line = line.rstrip().rstrip('\r\n')
# build options
if line.upper().startswith('OPTIONS USED'):
# only need options once because its the same
if not options:
options.append(line)
line = data.pop(0).rstrip().rstrip('\r\n')
while line:
options.append(line.split('-', 1)[1])
line = data.pop(0).rstrip().rstrip('\r\n')
else:
pass
# build fault result objects
temp_list = []
if line.startswith('AT BUS'):
while line != "-----------------------------------------------------------------------------------------------------------------------------------------------":
temp_list.append(line)
line = data.pop(0).rstrip().rstrip('\r\n')
list_of_result_objects.append(self.ASCCfaultResult(temp_list, options, self.log))
self.log('Read in %d ASCC data files.' % len(list_of_ascc_reports))
return list_of_result_objects
class ASCCfaultResult():
""" Creates an object from a list of text lines ...
(more)