what is the best way to get started in PSSE, Python?
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.
First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!
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.
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.
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
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.
Asked: 2020-09-03 16:52:27 -0600
Seen: 4,902 times
Last updated: Sep 08 '20
CMLDxxU2 and CMLDxxDGU2 modeling
How do I conditional format excel based on cell value using PSSE excelpy?
Run multiple python files from one python file
my question is about Python with Psse
How to import a custom Python module in PSSE?
Can anyone tell me how to use harmonics analysis module in PSSE 35.4