Ask Your Question
0

what is the best way to get started in PSSE, Python?

asked 2020-09-03 16:52:27 -0500

Durga gravatar image

updated 2020-09-05 08:36:25 -0500

jconto gravatar image

Hi everyone, I am a new user of PSSE. I want to learn to use the PSSE using Python. Could you please suggest me what is the best way to get started? Your suggestion will be much appreciated.

edit retag flag offensive close merge delete

3 answers

Sort by » oldest newest most voted
0

answered 2020-09-08 00:11:07 -0500

SqFKYo gravatar image

To expand on jconto's answer, if you have a choice, go with PSSE35. PSSE33/34 use Python 2.7, which is obsolete and doesn't receive even security fixes from 2020 onwards. PSSE35 uses Python 3.7, which is forward compatible with the recent versions of python.

edit flag offensive delete link more

Comments

1

PSSe v.34.7 uses python 3.7 32-bit or v.2.7

jconto gravatar imagejconto ( 2020-09-08 08:17:21 -0500 )edit
0

answered 2020-09-05 09:19:29 -0500

jconto gravatar image

Expanding on GaryB's advice, install PSSe on default directories. Search this forum for python and/or your topic of interest. Search the net for "PSSe python". Study the python code provided in the PSSe installation folder 'example'.

To run python scripts within PSSe GUI, load a case, then run the script (save below code as lf.py):

#lf.py - load flow solving a case
ier = psspy.fnsl()        #use default parameters
if ier:
   print('ier=',ier)

To run python scripts outside the PSSe GUI, open a command line window using the link created by PSSe during installation. Save the code below as lf2.py:

import psse34
import psspy
psspy.psseinit(150000)
savfile = r"C:\Program Files (x86)\PTI\PSSE34\EXAMPLE\savnw.sav"
psspy.case(savfile)
ier = psspy.fnsl()

To run it, enter in the command line window:

c:\..>python lf2.py
edit flag offensive delete link more
0

answered 2020-09-04 21:47:00 -0500

GaryB gravatar image

updated 2020-09-04 22:00:35 -0500

This is how I do it:

Assuming you can run Python programs currently and you want to run from the command line.

I can't post links, so I had to change this to be more complicated. There is a clever way to put the bulky path stuff in the beginning into a library. This should work with PSSE 33 or 34.

Modify with filenames and try and run this code, preferably from one of the Command Line file links provided by PTI with PSSE (in the PSSE34 Folder on the Start Menu):

import _winreg
import sys
import os
# Add the PSS/E directories to our Windows path variable so we can load in the PSS/E Python libraries that are available there


if 'PSSE34' in os.getenv('PATH'):
    print('PSSE 34 detected')
    try:
        pssepath, regtype = _winreg.QueryValueEx(_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\PTI\\PSSE 34\\Product Paths", 0, _winreg.KEY_READ), "PsseInstallPath")
    except WindowsError:
        pssepath, regtype = _winreg.QueryValueEx(_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\\Wow6432Node\\PTI\\PSSE 34\\Product Paths", 0, _winreg.KEY_READ), "PsseInstallPath")
    sys.path.append(os.path.join(pssepath, 'PSSBIN'))
    sys.path.append(os.path.join(pssepath, 'PSSLIB'))
    sys.path.append(os.path.join(pssepath, 'PSSPY27'))
    os.environ['PATH'] += ';' + os.path.join(pssepath, 'PSSBIN')
    os.environ['PATH'] += ';' + os.path.join(pssepath, 'PSSLIB')
    os.environ['PATH'] += ';' + os.path.join(pssepath, 'PSSPY27')
else:
    try:
        pssepath, regtype = _winreg.QueryValueEx(_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\PTI\\PSSE 33\\Product Paths", 0, _winreg.KEY_READ), "PsseInstallPath")
    except WindowsError:
        pssepath, regtype = _winreg.QueryValueEx(_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\\Wow6432Node\\PTI\\PSSE 33\\Product Paths", 0, _winreg.KEY_READ), "PsseInstallPath")
    sys.path.append(os.path.join(pssepath, 'PSSBIN'))
    sys.path.append(os.path.join(pssepath, 'PSSLIB'))
    os.environ['PATH'] += ';' + os.path.join(pssepath, 'PSSBIN')
    os.environ['PATH'] += ';' + os.path.join(pssepath, 'PSSLIB')

import psspy
import redirect

redirect.psse2py()

psspy.psseinit(150000)

case = r'your_save_case.sav'
resp = r'your_resp_file.idv'

psspy.case(case) #load the case
psspy.runrspnsfile(resp) #run an idev 
psspy.asys(0,1,[330]) #build a subsystem
psspy.area_2(0,0,1) #load/gen report on that subsystem

If it works, use the API in the documentation to build your own code.

You will likely get an error if you don't have certain Python packages installed. You will need to install these using PIP. (Google 'pip install'.)

You can also use the Recorder in the GUI to build .py code like you would .idv files.

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

Stats

Asked: 2020-09-03 16:52:27 -0500

Seen: 4,649 times

Last updated: Sep 08 '20