Ask Your Question
0

Error running PSSE from Python

asked 2017-03-12 03:42:58 -0600

Cynthia Hsu gravatar image

I'm new to PSS/E. And I want to run dynamic simulation in PSS/E. But encounter some problems when running PSS/E from python/. Here's the error from PSS/E when I try to open .py file in PSS/E:

Traceback (most recent call last): File "C:\Users\Cynthia\Desktop\0312.py", line 11, in <module> redirect.psse2py() File ".\redirect.py", line 147, in psse2py redirect.RedirectError: Python currently sending output to Psse Couldn't open Python file:C:\Users\Cynthia\Desktop\0312.py

And here's my code:

import os,sys

PYTHONPATH = r'C:\Program Files (x86)\PTI\PSSEXplore34\PSSPY27'
sys.path.append(PYTHONPATH)
os.environ['PATH'] += ';' + PYTHONPATH

import psspy
import redirect

# Redirect output from PSSE to Python:
redirect.psse2py()

# Last case:
CASE = r"C:\Program Files (x86)\PTI\PSSEXplore34\EXAMPLE\savnw.sav"
psspy.psseinit(12000)
psspy.case(CASE)

# Convert loads (3 step process):
psspy.conl(-1,1,1)
psspy.conl(-1,1,2,[0,0],[100,0,0,100])
psspy.conl(-1,1,3)

# Convert generators:
psspy.cong()

# Solve for dynamics
psspy.ordr()
psspy.fact()
psspy.tysl()

# Save converted case
case_root = os.path.splitext(CASE)[0]
psspy.save(case_root + "_C.sav")

# Add dynamics data
psspy.dyre_new(dyrefile="C:\Program Files (x86)\PTI\PSSEXplore34\EXAMPLE\savnw.dyr")

# Add channels by subsystem
#   BUS VOLTAGE
psspy.chsb(sid=0,all=1, status=[-1,-1,-1,1,13,0])

# Save snapshot
psspy.snap(sfile="C:\Program Files (x86)\PTI\PSSE32\EXAMPLE\python_test.snp")

# Initialize
psspy.strt(outfile="C:\Program Files (x86)\PTI\PSSE32\EXAMPLE\python_test_1.out")
psspy.run(tpause=1)

# 3-phase fault on bus 201 (default bus fault is a 3phase and there is no bus 200)
psspy.dist_bus_fault(ibus=201)

# Run to 3 cycles
time = 3.0/60.0 + 1
psspy.run(tpause=time)

# Clear fault (assuming only part of bus faults)
psspy.dist_clear_fault()
psspy.dist_branch_trip(ibus=201, jbus=151, id='1')

# Run to 20 seconds
time = 10

Thanks a lot for your help!!!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-03-12 14:42:39 -0600

jconto gravatar image

updated 2017-03-12 15:45:26 -0600

When running from PSSe GUI, PSSe send output to its GUI and python sends output to the PSSe GUI by default, so there is no need to redirect to 'python'. Your error fits this scenario. When running outside the PSSe GUI (within a DOS window, using line command) then you can send PSSe output to python using the redirect module. A little modified version of your code set to run outside the PSSe GUI (adjust path as needed) follows [to run in PSSe GUI comment lines 3 to 11]:

import os, sys

PYPATH = r'C:\Program Files (x86)\PTI\PSSE34\PSSPY27'
sys.path.append(PYPATH)
os.environ['PATH'] += ';' + PYPATH
import psspy

psspy.psseinit(12000)
import redirect
# Redirect output from PSSE to Python:
redirect.psse2py()

CASE = r'''C:\\Program Files (x86)\\PTI\\PSSE34\\EXAMPLE\\savnw.sav'''
psspy.case(CASE)

# Convert loads (3 step process):
psspy.conl(-1,1,1)
psspy.conl(-1,1,2,[0,0],[100,0,0,100])
psspy.conl(-1,1,3)

# Convert generators:
psspy.cong()

# Solve for dynamics
psspy.ordr()
psspy.fact()
psspy.tysl()

# Save converted case
case_root = os.path.splitext(CASE)[0]
psspy.save(case_root + "_C.sav")

# Add dynamics data
psspy.dyre_new(dyrefile="C:\\Program Files (x86)\\PTI\\PSSE34\\EXAMPLE\\savnw.dyr")

# Add channels by subsystem
#   BUS VOLTAGE
psspy.chsb(sid=0,all=1, status=[-1,-1,-1,1,13,0])

# Save snapshot
psspy.snap(sfile="test.snp")

# Initialize
psspy.strt(outfile="test.out")
simtime = 1
#psspy.run(tpause=simtime)
psspy.run(0,simtime,99,19,0)

# 3-phase fault on bus 201 (default bus fault is a 3phase and there is no bus 200)
psspy.dist_bus_fault(ibus=201)

# Run under fault for 3 cycles
simtime += 3.0/60.0
#psspy.run(tpause=simtime)
psspy.run(0,simtime,99,3,0)

# Clear fault (assuming only part of bus faults)
psspy.dist_clear_fault()
psspy.dist_branch_trip(ibus=201, jbus=151, id='1')

# Run to 20 seconds
simtime = 5
#psspy.run(tpause=simtime)
psspy.run(0,simtime,99,9,0)
edit flag offensive delete link more

Comments

Thank you so much for your sincere help! I comment line 3 to 11 as you said and it works really really well!

Cynthia Hsu gravatar imageCynthia Hsu ( 2017-03-13 05:57:49 -0600 )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: 2017-03-12 03:42:58 -0600

Seen: 1,985 times

Last updated: Mar 12 '17