Ask Your Question
1

Plot multiple PSSE "out" files

asked 2014-11-18 23:07:31 -0500

anonymous user

Anonymous

updated 2017-11-02 21:23:20 -0500

jconto gravatar image

Hi,

I recently came across some code that shows how to run PSSE from python and the some tricks with the dyntools module. This is the code.

The code works great but my problem is, instead of entering the name of each out file, is there a way of plotting all the outfiles in a directory?

Thanks.

----------------------------
import os, sys

# =============================================================================================
# Get installed location of latest PSS(R)E version

def latest_psse_location():
    import _winreg
    ptiloc = r"SOFTWARE\PTI"
    ptikey = _w

    inreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, ptiloc, 0, _winreg.KEY_READ)

    ptikeyinfo = _winreg.QueryInfoKey(ptikey)
    numptisubkeys = ptikeyinfo[0]
    vdict = {}
    for i in range(numptisubkeys):
        vernum = _winreg.EnumKey(ptikey, i)
        try:
            n = int(vernum[-2:])
            vdict[n]=vernum
        except:
            pass

    vers = vdict.keys()
    vers.sort()
    k = vers[-1]
    lver = vdict[k]
    lverloc = ptiloc + "\\" + lver + "\\" + "Product Paths"
    lverkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, lverloc, 0, _winreg.KEY_READ)
    lverdir, stype = _winreg.QueryValueEx(lverkey, 'PsseInstallPath')
    _winreg.CloseKey(ptikey)
    _winreg.CloseKey(lverkey)
    return lverdir

pssedir = latest_psse_location()
pssedir = str(pssedir)              # convert unicode to str

# =============================================================================================
# Files Used

pssbindir  = os.path.join(pssedir,'PSSBIN')
exampledir = os.path.join(pssedir,'EXAMPLE')

savfile    = os.path.join(exampledir,'savcnv.sav')
snpfile    = os.path.join(exampledir,'savnw.snp')
outfile1   = os.path.join(exampledir,'bus154_fault.out')
outfile2   = os.path.join(exampledir,'bus3018_gentrip.out')
outfile3   = os.path.join(exampledir,'brn3005_3007_trip.out')
prgfile    = os.path.join(exampledir,'dyntools_demo_progress.txt')

# =============================================================================================
# Check if running from Python Interpreter
exename = sys.executable
p, nx   = os.path.split(exename)
nx      = nx.lower()
if nx in ['python.exe', 'pythonw.exe']:
    os.environ['PATH'] = pssbindir + ';' + os.environ['PATH']
    sys.path.insert(0,pssbindir)

# =============================================================================================

import dyntools

# =============================================================================================
# Run Dynamic simulation on SAVNW to generate .out files

def run_savnw_simulation():
    import redirect
    redirect.psse2py()    
    import psspy
    ierr = psspy.psseinit(buses=80000)  # choose here bus numbers you want

    psspy.lines_per_page_one_device(1,90)
    psspy.progress_output(2,prgfile,[0,0])

    psspy.case(savfile)
    psspy.rstr(snpfile)
    psspy.strt(0,outfile1)
    psspy.run(0, 1.0,1000,1,0)
    psspy.dist_bus_fault(154,1, 230.0,[0.0,-0.2E+10])
    psspy.run(0, 1.05,1000,1,0)
    psspy.dist_clear_fault(1)
    psspy.run(0, 5.0,1000,1,0)

    psspy.case(savfile)
    psspy.rstr(snpfile)
    psspy.strt(0,outfile2)
    psspy.run(0, 1.0,1000,1,0)
    psspy.dist_machine_trip(3018,'1')
    psspy.run(0, 5.0,1000,1,0)

    psspy.case(savfile)
    psspy.rstr(snpfile)
    psspy.strt(0,outfile3)
    psspy.run(0, 1.0,1000,1,0)
    psspy.dist_branch_trip(3005,3007,'1')
    psspy.run(0, 5.0,1000,1,0)

    psspy.lines_per_page_one_device(2,10000000)
    psspy.progress_output(1,"",[0,0])

# =============================================================================================
# 1. Data extraction/information

def test_data_extraction(chnfobj):   
    print '\n Testing call to get_data'
    sh_ttl, ch_id, ch_data = chnfobj.get_data()
    print sh_ttl
    print ch_id

    print '\n Testing call to get_id'
    sh_ttl, ch_id = chnfobj.get_id()
    print sh_ttl
    print ch_id

    print '\n Testing call to get_range'
    ch_range = chnfobj.get_range()
    print ch_range

    print '\n Testing call to get_scale'
    ch_scale = chnfobj.get_scale()
    print ch_scale

    print '\n Testing call to print_scale'
    chnfobj.print_scale()

    print '\n Testing call to txtout'
    chnfobj.txtout(channels=[1,4])

    print '\n Testing call to xlsout'
    chnfobj.xlsout(channels ...
(more)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-11-19 22:31:48 -0500

jconto gravatar image

the function test1() already uses a list of out files!!. To make it more generic:

1: add to the top of the code

import glob

2: knowing the folder name where the out files are stored, in test1() replace the outlst definition with

outlist = glob.glob('examples\*.out') #or full path of folder name. It collects all *.out file into a list

edit flag offensive delete link more

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

1 follower

Stats

Asked: 2014-11-18 23:07:31 -0500

Seen: 2,435 times

Last updated: Nov 02 '17