Ask Your Question
0

how to export ANSI values to txt

asked 2019-06-18 22:59:10 -0500

Rick gravatar image

updated 2019-06-23 20:53:53 -0500

jconto gravatar image

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.

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
0

answered 2019-07-11 08:14:36 -0500

nelak gravatar image

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

answered 2019-06-19 03:51:09 -0500

drsgao gravatar image

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.

edit flag offensive delete link more

Comments

Thanks, I tried this way and works well

Rick gravatar imageRick ( 2019-06-23 20:23:28 -0500 )edit
0

answered 2019-06-19 00:25:34 -0500

perolofl gravatar image

You need

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

to write the report output to a file.

edit flag offensive delete link more

Comments

thanks I try this way and works well

Rick gravatar imageRick ( 2019-06-23 20:23:52 -0500 )edit

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

Stats

Asked: 2019-06-18 22:59:10 -0500

Seen: 453 times

Last updated: Jul 11 '19