0

how to export ANSI values to txt

  • retag add tags

I need to calculate a lot of fault level cases, so is there any way to export the output bar ANSI results into a txt or ideally csv file.

Currently I am using the syntax below

recdFN=r"recd.recd"

psspy.alert_output(2,recdFN,[0,0])
psspy.progress_output(2,recdFN,[0,0])
psspy.prompt_output(2,recdFN,[0,0])

Filelist = ['a.sav','b.sav']

for i in Filelist:
    psspy.case(i)
    psspy.ansi_3([0,0,0,4,0],[ 40.0, 80.0, 40.0, 80.0],1,[45110],[0],[ 1.0],[ 0.02],"")

the output recd file only includes the progress message but no ANSI_3 output message we can see on the screen.

Rick's avatar
1
Rick
asked 2019-06-18 22:59:10 -0500
jconto's avatar
2.9k
jconto
updated 2019-06-23 20:53:53 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

3 Answers

0

Here is some code I use, hopefully you can leverage portions of it to save yourself some time.

 def __ANSI(self, out_file_identifier, out_file_path, subsystem):
        ierr, busarray = self.psspy.abusint(subsystem, 1, 'NUMBER')
        if ierr: return ierr
        busarray = busarray[0]
        # skip rerun
        if not os.path.isfile(os.path.join(out_file_path, '%d_ANSI_rawData_tot.txt' % out_file_identifier)):
            ierr = self.psspy.report_output(2, os.path.join(out_file_path,
                                                            '%d_ANSI_rawData_tot.txt' % out_file_identifier))
            if ierr: return ierr
            vltary = [1.05 for x in busarray if x]
            cptary = [0.033 for x in busarray if x]
            # total current
            ierr = self.psspy.ansi_2([0, 0, 0, 5, 0], [40, 80, 40, 80], len(busarray), busarray, vltary, cptary, '')
            if ierr > 0:
                self.log('ERROR PERFORMING ANSI %s - Error code %s' % (out_file_identifier, ierr), 'error')
            ierr = self.psspy.report_output(2, os.path.join(out_file_path,
                                                            '%d_ANSI_rawData_sym.txt' % out_file_identifier))
            if ierr: return ierr
            vltary = [1.05 for x in busarray if x]
            cptary = [0.033 for x in busarray if x]
            # symmetric current
            ierr = self.psspy.ansi_2([0, 0, 0, 5, 1], [40, 80, 40, 80], len(busarray), busarray, vltary, cptary, '')
            if ierr > 0:
                self.log('ERROR PERFORMING ANSI %s - Error code %s' % (out_file_identifier, ierr), 'error')
        else:
            self.log('skipping %d_ANSI_rawData_tot.txt' % out_file_identifier)



 def RunANSI_study(self):
        self.log('Beginning ANSI portion of study...')
        # trim tp specific to those in study

        TP_specific_areas = list(set(int(x.area) for x in self.ansi_param))

        # create a default subsystem
        self.createSubsystemOfAreas(self.areas, sid=0)

        # find all buses in default subsystem
        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 ANSI on them
        self.log('  Created %d segments of size %d.' % (len(study_buses), len(study_buses[0])))
        for i, segment_of_study_buses in enumerate(study_buses, 1):
            self.createSubsystemOfBuses(segment_of_study_buses, 0)
            self.log('    Running default ANSI for segment %d' % i)
            self.__ANSI(i, self.report_dir, 0)
        self.log('ANSI study complete.')

    def processANSIresults(self, workbook, folder):
        """

        :param workbook: Workbook to add results.
        :param folder: Location of psse reports.
        :return: Workbook with results included.
        """
        if not hasattr(self, 'psspy'):
            #self.init_psse()
            self.init_psse()
            #self.PSSEService.init_psse()
            self.openCase(self.model_path)

        ansi_results_sym, ansi_results_tot, ansi_tpspec = self.__compileANSIresults(folder)
        workbook = self.__writeANSIresults(workbook, ansi_results_sym, 'Default-ANSI-Symm Curr Basis')
        workbook = self.__writeANSIresults(workbook, ansi_results_tot, 'Default-ANSI-Total Curr Basis')
        if ansi_tpspec:
            workbook = self.__writeANSIresults(workbook, ansi_tpspec, 'TP-Criteria ANSI')
        return workbook

    def __compileANSIresults(self, folder):
        """ Parses a folder and build ANSI results from PSSE ANSI report txt files."""
        # get list of report filepaths
        list_of_ansi_reports = glob.glob(os.path.join(folder, '*ANSI_rawData*.txt'))
        self.log('Read in %d ANSI report files.' % len(list_of_ansi_reports))
        list_of_ansi_reports_sym = [x for x in list_of_ansi_reports if 'sym' in os.path.basename(x)]
        list_of_ansi_reports_tot = [x for x in list_of_ansi_reports if 'tot' in os.path.basename(x)]
        list_of_ansi_reports_tp = [x for x in list_of_ansi_reports if 'TPSPEC' in os.path.basename(x)]

        # file in memory
        data = []
        for report in list_of_ansi_reports_sym:
            data_file = open(report, 'rU')
            data.extend(data_file.readlines())
        # parse ...
(more)
nelak's avatar
1
nelak
answered 2019-07-11 08:14:36 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
0

You need

psspy.report_output(2,recdFN,[0,0])

to write the report output to a file.

perolofl's avatar
3.8k
perolofl
answered 2019-06-19 00:25:34 -0500
edit flag offensive 0 remove flag delete link

Comments

thanks I try this way and works well

Rick's avatar Rick (2019-06-23 20:23:52 -0500) edit
add a comment see more comments
0

To add to @perolofl 's answer, you can also try setting the same things in the PSSE GUI.

I/O Control -> Direct Report output

I/O Control -> Direct Progress output

But if you want to format things into the proper CSV format, you need more programming. Or just rely on Excel to recognise the fixed width.

drsgao's avatar
76
drsgao
answered 2019-06-19 03:51:09 -0500
edit flag offensive 0 remove flag delete link

Comments

Thanks, I tried this way and works well

Rick's avatar Rick (2019-06-23 20:23:28 -0500) edit
add a comment see more comments

Your Answer

Login/Signup to Answer