Ask Your Question

EBahr's profile - activity

2022-01-17 08:51:36 -0500 received badge  Necromancer (source)
2020-02-06 00:20:30 -0500 received badge  Famous Question (source)
2020-01-29 21:47:06 -0500 received badge  Notable Question (source)
2020-01-14 08:59:23 -0500 received badge  Popular Question (source)
2020-01-13 11:56:31 -0500 asked a question Supress only PSSE output

I feel like this should be an easy one, but everything I am throwing at python is failing me. I am trying to run a program within PSSE, but I would like all output to be supressed except for my python print() commands. Is this possible without creating my own print wrapper function?

2019-01-15 14:26:45 -0500 answered a question A contingency converges with FNSL, but not with ACCC

There is something extremely wrong with FNSL in ACCC. I have noticed similar issues with solving ACCC with FNSL where blown up cases reported meeting convergence even though mismatch was in the thousands. One thing that was found to somewhat work is to solve your power flow case with the exact same settings you intend to run your in your ACCC analysis. I.e. if you setup your case moving shunts, taps, and PSTs with FNLS, but run your ACCC analysis with everything locked with FNSL, make sure to solve your case once with everything locked using FNSL immediately prior to running ACCC.

2018-08-16 09:58:38 -0500 commented question Multi-Threading using xlsout

Your code works as intended for me. I wonder if you are running into a memory limitation or have an issue with you .out files?

2018-08-15 20:28:49 -0500 answered a question Multi-Threading using xlsout

The following should get you close:

import sys
import os
import multiprocessing
from multiprocessing import Pool as ThreadPool
import math
PSSE33BINPATH = r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN;C:\Program Files (x86)\PTI\PSSE33\PSSLIB;"

def main():
    processes = [] # setup blank list for processes
    out_files = ['out1.out', 'out2.out', 'out3.out'] # set this to however you are grabbing your out files
    file_number = 0 # not sure how you are giving file_number, so this is arbitrary
    signals = ['Time'] # not sure what signals you are grabbing, so this is just an example
    path_dir = r"C:\temp" # example
    file_name = "channels" # example
    # Change number_of_threads to how ever many threads you want to use, this is just an example of using all threads in CPU
    number_of_threads = int(math.ceil(multiprocessing.cpu_count()))

    # Loop through out files to setup an argument list
    for out_file in out_files:
        file_number += 1 # arbitrary
        arguments = (out_file, signals, path_dir, file_name, file_number)
        processes.append(arguments)

    # Here I set number_of_threads to equal processes if I don't need to use all available threads
    if len(processes) < number_of_threads:
        number_of_threads = len(processes)

    # Build pool and map your processes to it
    out_pool = ThreadPool(number_of_threads)
    results = out_pool.map(build_xls, processes)
    out_pool.close()
    out_pool.join()  # Wait until all threads are finished


def build_xls((outfile, signals, path_dir, file_name, file_number)):
    # The following may be different depending on PSSE version
    os.environ['PATH'] = PSSE33BINPATH + ';' + os.environ['PATH']
    sys.path.insert(0, PSSE33BINPATH)

    import dyntools

    excel_file = path_dir + "\\sheets\\" + file_name + str(file_number) + '.xlsx'
    dyntools.CHNF(outfile).xlsout(channels=signals, show=False, xlsfile=excel_file, outfile='', sheet='', overwritesheet=True)

if __name__=='__main__':
    main()
2018-08-09 11:53:14 -0500 commented question Python API to Terminate Dynamic Simulation

I hope someone has an answer to this as I have been looking for a solution like this for a while. It doesn't appear PSSEHALT works for this. Best thing I can conceive is a FORTRAN model that monitors the simulation then when I want simulation to stop, crash PSSE by dividing by zero. Awful, I know

2018-08-09 11:45:38 -0500 answered a question How do you output the load of the bus and store it as a variable

The TOTALS(2) element is an output variable for the the OLD subsystem load value. If you would like to retrieve the NEW load MW total of your subsystem, use the psspy.alodbuscplx function.

For example:

import psspy
_i, _f = psspy.getbatdefaults()

# Setup subsystem
psspy.bsys(1,0,[0.0,0.0],0,[],1,[126389],0,[],0,[])

# Scale load to 20 MW using constant P/Q ratio
ierr, totals, motors = psspy.scal_2(1, 0, 0, [0,1,0,1,0],[20.0,_f,_f,_f,_f,_f,_f])

# Print old load value
print 'OLD LOAD: {} MW'.format(round(totals[1],0))

# Print new load value
ierr, load = psspy.alodbuscplx(1, 1, 'TOTALNOM')
print 'NEW LOAD: {} MW'.format(round(load[0][0].real,0))
2018-08-09 11:12:02 -0500 answered a question Which test fixture will run after executed the all test case in python?

The following should do what you need it to do:

import shutil

shutil.rmtree(YOUR_FOLDER_TO_DELETE)
2018-05-15 13:44:05 -0500 answered a question bus-3001 to bus-3003 unbalanced fault in official file 'savnw' cannot be added successfully.

For whatever reason, PSSE cannot calculate imbalance without line charging and/or line shunts on the line. Try adding small amounts B and B0 until you don't get the error. Adding 0.01 to charging (B and B0) and 0.001 to Line B To/From I was able to get it to produce some values with SPCB. It's very annoying and potentially not as accurate, but it's about all you can do to make it work.

 ZERO SEQUENCE THEVENIN IMPEDANCE SUBMATRIX:
    BUS    3001 [MINE        230.00]    3003 [S. MINE     230.00]
   3001      (   0.00022,   0.00960)      (   0.00006,   0.00210)
   3003      (   0.00006,   0.00210)      (   0.01334,   0.13911)

 POS. SEQUENCE THEVENIN IMPEDANCE SUBMATRIX:
    BUS    3001 [MINE        230.00]    3003 [S. MINE     230.00]
   3001      (   0.00201,   0.03119)      (   0.00210,   0.00731)
   3003      (   0.00210,   0.00731)      (   0.01003,   0.05125)

 NEG. SEQUENCE THEVENIN IMPEDANCE SUBMATRIX:
    BUS    3001 [MINE        230.00]    3003 [S. MINE     230.00]
   3001      (   0.00201,   0.03119)      (   0.00210,   0.00731)
   3003      (   0.00210,   0.00731)      (   0.01003,   0.05125)

 PI EQUIVALENT Y MATRIX IS:
 (     0.5319,  -131.2263)   (     0.5319,   118.7678)
 (     0.5319,   118.7678)   (     0.5319,  -131.2263)

 TO SIMULATE:

 ONE PHASE GROUNDED WITH IMPEDANCE=      0.0000 +J      0.0000
   50.0 PERCENT OF WAY DOWN LINE FROM   3001 [MINE        230.00]

 FOR BRANCH FROM BUS   3001 [MINE        230.00] TO BUS   3003 [S. MINE     230.00] CIRCUIT 1
  USE EQUIVALENT R+JX= (   -0.00004,    0.00842)  B= 0.0

 AT BUS   3001 [MINE        230.00] USE LINE CONNECTED SHUNT= (    1.06378,  -12.45846)

 AT BUS   3003 [S. MINE     230.00] USE LINE CONNECTED SHUNT= (    1.06378,  -12.45846)

Here is the modified line data:

  3001,  3003,'1 ', 0.00000E+0, 8.00000E-3,   0.01000,    0.00,    0.00,    1.00,  0.00000,  0.00100,  0.00000,  0.00100,0,1,   0.00,  55,1.0000
2018-05-15 10:30:09 -0500 answered a question Need python code for load removal from load bus during dynamic simulation

Take a look at the LDSHBL model in the MODELS.pdf documentation. For your example, you can add something similar to the following to your .dyr: 3, 'LDSHBL', '1', 49.5, 0.2, 0.5, 0, 0, 0, 0, 0, 0, 0.05 /

Where 3 is the bus number, '1' is the load ID, 49.5 is your setpoint frequency for shedding, 0.2 is the pickup time of the relay, 0.5 is the pu amount of load to shed, and 0.05 is the breaker time. Of course, your delays might be a bit different and would depend on your relay and breaker timings.

2017-08-28 15:16:00 -0500 answered a question Removing "Terminal Read" on PSSE. User input on output bar

Your question and code seem to be two separate issues. For your question, I am guessing you are trying to read in an .idv (or other file) from within python. It will pop-up a Terminal Read window if your file doesn't have the appropriate syntax (i.e. final 0, or improper data entry). Make sure these files work properly before you try and use them in your python code. Better yet, convert the code over to python.

Your issue with your code seems to be that you are trying to convert a string into an integer. I am honestly not sure how you made it past digit=int(digit), but you should just leave that bit of code out and treat digit as a string.

2017-07-25 10:50:35 -0500 answered a question User Defined Model Development

Rsko, I would suggest looking at the available Dynamic Simulation Arrays in section 13.4.2 in the Program Application Guide Volume 2 (PAGV2.pdf) for internal arrays/variables that are available to you (also 21.1.2 in the Program Operation Manual (POM.pdf)). Section 24 in the same document will give you an idea of how to model transfer functions in Fortran. The Model Writing section in the POM also has some good information, which I am guessing is what you are looking at now. Finally, most (all?) API routines are available in Fortran. If you take a look at the Application Program Interface document (API.pdf), the Fortran command syntax is listed for each individual API. (i.e. CALL BRANCH_CHNG(IBUS, JBUS, CKT, INTGAR, REALAR, IERR) )

2017-07-19 17:18:18 -0500 answered a question How to auto save plot.

You should take a look at the dyntools module for pulling out relevant data from a .out file. The matplotlib is also a great module for plotting very similar to Matlab. I use the following to spit out *.png files that contains Frequency, Voltage, and System Angles for each simulation. You can just use this routine (or similar) after the completion of each contingency, or after all contingencies have finished.

# To install matplotlib tool, open command prompt and type the following:
#    C:\python27\python.exe -m pip install --upgrade pip
#    C:\python27\python.exe -m pip install matplotlib   

import sys
import os
import matplotlib
import numpy
import dyntools
import glob

# Define Main subroutine
def main(out_folder):
    for out_file in glob.glob(out_folder + '\\*.out'):
        plot_out(out_file)

# Define plot subroutine    
def plot_out(out_file):
    # Open file and grab data
    chan = dyntools.CHNF(out_file)

    # Set up plot details
    chan_range = chan.get_range()
    titles, ids, data = chan.get_data()
    fig = plt.figure(figsize=(8.27, 11.69))
    title = os.path.splitext(out_file)[0]
    fig.suptitle(title, fontsize=24)

    tmax = int(chan_range['time']['max'])
    if not tmax:
        print "%s has no data" % title
        return
    trange = numpy.arange(0, tmax, 1)

    # Create subplots
    ax1 = fig.add_subplot(311)
    ax2 = fig.add_subplot(312)
    ax3 = fig.add_subplot(313)
    for key, value in ids.iteritems():
        if 'VOLT' in value:
            ax2.plot(data['time'], data[key],label="key", linewidth=0.25)
        if 'FREQ' in value:
            data2 = [60 + x * 60 for x in data[key]]
            ax1.plot(data['time'], data2,label="key", linewidth=0.25)
        if 'ANGL' in value:
            ax3.plot(data['time'], data[key],label="key", linewidth=1)

    # Plot data
    ax1.set_xlabel('Time (sec)')
    ax1.set_title('Frequency')
    ax1.set_ylabel('Frequency (Hz)')
    ax1.set_xticks(trange)
    ax1.set_xbound(0,tmax)
    ax1.set_ybound(58,62)

    ax2.set_xlabel('Time (sec)')
    ax2.set_title('Voltage')
    ax2.set_ylabel('Voltage (pu)')
    ax2.set_xticks(trange)
    ax2.set_yticks([0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0,1.1,1.2])
    ax2.set_xbound(0,tmax)
    ax2.set_ybound(0,1.2)

    ax3.set_xlabel('Time (sec)')
    ax3.set_title('System Slack Bus Angle')
    ax3.set_ylabel('Angle (deg)')
    ax3.set_xticks(trange)
    ax3.set_xbound(0,tmax)

    ax1.grid(True)
    ax2.grid(True)
    ax3.grid(True)

    plt.tight_layout(rect=[0, 0.03, 1, 0.95])

    fname = title + '.png'
    plt.savefig(fname, dpi=600)     
    plt.close(fig)

if __name__ == "__main__":
    main(r'C:\Path\To\Out\Files')
2017-05-24 16:45:09 -0500 answered a question PSSE V33 Compile User Model Failure

One thing to check is that you have write privileges to C:\windows\system32\

2017-05-23 12:05:22 -0500 commented answer How to set different load models in dynamic simulation?

Please see edited answer for example of IEEE load model.

2017-05-23 09:11:12 -0500 answered a question How to set different load models in dynamic simulation?

Dynamic load models are added just like generators in .dyr file. Load models can be added by either bus, zone, area, or owner. I would take a look at section 9 of the PSSE Model Library document.

The following is an example of a "standard" IEEE Load Model used in the WECC:

 [AREA NUMBER] 'IEELAR' *     0.0000       1.0000       0.0000       1.0000
      0.0000       0.0000       1.0000      -1.0000       2.0000
      1.0000       0.0000       2.0000       1.0000       0.0000    /

Change [AREA NUMBER] to the area of your choice.

2017-03-31 10:39:13 -0500 answered a question Modelling Dyn5 Transformers

I might be wrong, but I don't believe the fault duty calculations use any information from the power flow simulation data. I believe it just calculates every thing based on the impedances. So I wouldn't worry about it being able to solve or not as it should be able to calculate the faults just fine without solving. For what it's worth, our fault duty file does not solve either and has no generation dispatched (although the machines are in service).

2017-03-16 10:36:09 -0500 answered a question Running PSSE from Python IDLE or Python IDE

I think "best" is all up to user preference. I personally like to use PyCharm when I am building a very large project as it, to me, is the best full blown IDE for python. Most of the time it is overkill though, and i actually do a lot of my programming in something basic like Notepad++. I like Notepad++ better than IDLE because it allows you to keep however many files you are working with within the same window. It also allows you to work with files that aren't python files (.dyr, .idv, etc), and also has pretty good syntax highlighting. When I want to run a python script that I am working on in Notepad++, I usually go to Command Prompt (or PSSE Command Prompt) and run it from there.

2017-03-02 11:49:15 -0500 received badge  Enthusiast
2017-02-24 11:31:44 -0500 answered a question There is any guide to entry the data for induction machines? PSS/E 34.1

If you are referring to dynamics models, please look at the Model Library documentation (MODELS.pdf).

2017-02-23 11:24:10 -0500 answered a question i want to add GPS location to each bus, i have the latitude and longitude coordinates of each bus. please guide me how to add these coordinates to each bus?

I would check out section 3.6.8 Specifying Bus Locations from a File in the GUI Users Guide. Basically you create a file with something like the following format and save as a *.loc:

GEOPHYSICAL
/BusID, X location, Y location
100,        50.863N,    90.423W
101,        50.345N,    80.564W

Then, just load the *.loc file and start building your SLD. If you already have a SLD built, you can click Diagram, then click Update bus locations.

2017-02-23 10:52:48 -0500 answered a question Change the value of loads (load_chng_4) in Python

If you add the following at the top of your code it should work correctly.

_i, _f = psspy.getbatdefaults()

2017-02-22 17:18:09 -0500 commented answer Can't open .sav file

You will have to another program that supports the GE .out format. As far as I know, GE PSLF is the only program that can.

2017-02-22 17:12:19 -0500 answered a question How to insert non overlapping text in matplotlib?

I know this it late to the game, but I would try tight_layout. The following works well for me : plt.tight_layout(rect=[0, 0.03, 1, 0.95])

2016-05-09 21:12:31 -0500 marked best answer How to deal with unicode strings - PSS/e 33, Python 2.7, and wxPython

It seems there are various PTI PSS/e python modules that aren't very friendly with unicode formatted strings (psse_env_manager,dyntools, etc). I never had this issue with Rev 32 and the previous bundled python utilities, but the new version is causing some issues with some of my programs. I believe the issue stems from the new wxPython module that is unicode rather than ascii. Anytime I grab text from any one of my GUI's, it converts the text string to unicode format (ie u"string"). Often, I grab a portion of a string from a GUI to define something like a dynamic channel file name. Any time I even grab a portion of the original text and manipulate it, it still formats it as unicode. So if I specify a file in unicode format in psse_env_manager or dyntools, the packages straight up ignore the text and either do nothing (dyntools) or throw an error (psse_env_manager).

So, what I am wondering is if any of you all have ever dealt with this issue? I feel I have two options, both of which are less than ideal:

  1. Convert all text gathered from TextCtrl, ListCtrl, etc boxes into strings (str(object.GetValue())) in every single GUI, or
  2. Go through code and make sure all psse module function calls have an appropriately encoded string (non-unicode) in them

Any ideas?

Is it possible to force ASCII/utf-8 encoding in my programs to disable it ever encoding a string as unicode?

Is it possible to build a function to loop through local/global variables and convert any unicode string to a general string?

2016-05-09 21:11:44 -0500 marked best answer PSS/E Rev 33 - psspy.py UnicodeWarning

I have been testing out some of my code in PSS/E 33 and am getting the following error:

C:\Progra~2\PTI\PSSE33\PSSBIN\psspy.py:16893: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal

It is cluttering up my output and I am not sure what is causing it. There is A LOT of code in my program, so I haven't been able to pinpoint what commands are causing it to produce this error. Also, I do not get this error when I run the same program in PSS/E 32. Any thoughts?

2015-09-13 07:03:34 -0500 received badge  Taxonomist
2014-08-08 08:42:11 -0500 answered a question PSS/E and Python and Conec File interface

If I recall correctly, there is no data stored in the conec/conet files. I think what you are going to want to do is either modify the .dyr call before you load it in, or use the change_con or change_icon functions to change the value after your dynamics data is loaded.

2014-04-07 11:56:11 -0500 answered a question Is there any way to export to excel LOSSES of all the branches of a system?

Unfortunately I don't think you can extract that type of calculated data from caspy.

Also, see below for a slight variation to @jsexauer's answer. This version will make sure the branch is only documented once. Otherwise if you tried to calculate total system losses, it would be double what it should be.

ierr, loss = psspy.aflowreal(-1, 2, 1, 1, 'PLOSS')
ierr, toBus = psspy.aflowint(-1, 2, 1, 1, 'TONUMBER')
ierr, fromBus = psspy.aflowint(-1, 2, 1, 1, 'FROMNUMBER')
ierr, brnID = psspy.aflowchar(-1, 2, 1, 1, 'ID')
branches = []

csv = 'ToBus, FromBus, ID, PLOSS\n'
for i in range(len(loss[0])):
    if not (toBus[0][i],fromBus[0][i],brnID[0][i]) in branches:
        csv += '%i,%i,%s,%f\n' % (toBus[0][i], fromBus[0][i], brnID[0][i],loss[0][i])
        branches.append((fromBus[0][i],toBus[0][i],brnID[0][i]))
print csv
with open('c:\\output.csv','w') as f:
    f.write(csv)
2014-04-04 12:08:36 -0500 commented question Exporting Power flow data to excel

Can you please expand on exactly what data you are looking to export? Pretty much any data you might be looking for will be available for export, but doing so may be vastly different for different types of data.

2014-04-03 10:19:54 -0500 answered a question PSS/E Program Application Guide

Unfortunately you will likely have to go through PTI to obtain the document you are looking for. Most companies consider this information proprietary and confidential, and you are usually only able to view it if you purchased the software or sign a Non-Disclosure Agreement with the company. I would suggest contacting them directly as to not get any users here in trouble.

2014-04-02 15:39:17 -0500 answered a question Read CHAN(7) from .out file

I would suggest looking into the dyntools package.

import dyntools

chan = dyntools.CHNF("C:\\PATH\\TO\\YOUR\\CHAN.OUT")
data = chan.get_data()
chan_7_title = data[1][7]
chan_7_data = data[2][7]
2014-04-02 15:05:07 -0500 answered a question PSSE dynamic simulation on multiple processor cores

Here is something incredibly basic, but hopefully it will get you started. This will run the same fault on the same case in 5 simultaneous processes. Hopefully you can figure out how to make it work with what you want to do. For example, if you wanted to run multiple different faults on the same base case, you could create a function for each fault (ie run_fault_1, run_fault_2, etc), then scrap the for loop and start a new thread for each fault function.

import os,sys
PYTHONPATH = r'C:\Program Files (x86)\PTI\PSSE33\PSSBIN'
MODELFOLDER = r'C:\Program Files (x86)\PTI\PSSE33\MODELDRW'

sys.path.append(PYTHONPATH)
os.environ['PATH'] += ';' + PYTHONPATH

import psspy
import redirect
import multiprocessing

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

    # Last case:
    CASE = r"C:\Program Files (x86)\PTI\PSSE33\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\PSSE33\EXAMPLE\savnw.dyr")

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

    # Add channels individually
    #   BRANCH MVA
    psspy.branch_mva_channel([-1,-1,-1,3001,3002],'1')

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

    # Run multiprocessed faults
    for i in range (5):
        arguments = (case_root + "_C.sav", 
                "C:\Program Files (x86)\PTI\PSSE33\EXAMPLE\python_test.snp",
                case_root + "_" + `i` + ".out",
                case_root + "_" + `i` + ".log")

        # Start new thread
        p = multiprocessing.Process(target = run_fault, args = arguments)      
        p.start()    

def run_fault(case, snp, out, log):
    # Initialize PSSE
    psspy.psseinit(12000)

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

    # Create log    
    psspy.report_output(2,log,[0,0])
    psspy.prompt_output(2,log,[2,0])
    psspy.progress_output(2,log,[2,0])

    # Load case
    psspy.case(case)
    psspy.rstr(snp)

    # Initialize case
    psspy.strt(outfile=out)
    psspy.run(tpause=0)

    # 1-phase fault branch 3001 to 3003
    psspy.dist_branch_fault(ibus=3001, jbus=3003, id='1',units=1,values=[352,-2389])

    # Run to 4 cycles
    time = 4.0/60.0
    psspy.run(tpause=time)

    # Clear fault
    psspy.dist_clear_fault()
    psspy.dist_branch_trip(ibus=3001, jbus=3003, id='1')

    # Run to 20 seconds
    time = 20
    psspy.run(tpause=time)

    psspy.pssehalt_2()    

if __name__ == "__main__":
    main()
2014-04-02 13:58:44 -0500 commented question How to compile an ipl file in the IPLAN compiler?

@Shengen Try running it without the -RUN option and you will see all sorts of errors. I am not sure what is wrong, but it seems PTI's code is missing something.

2014-03-13 17:20:49 -0500 answered a question How to compile an ipl file in the IPLAN compiler?

I hope you figured this out already, but if not this should work : "TEST1.ipl" -RUN

2014-02-21 12:38:03 -0500 answered a question I want to read some datas from dyr file and to change it.
2014-02-21 12:31:39 -0500 answered a question Changing VAR(L) during dynamic simulation

I am not sure exactly what you are trying to do, or if you are working with a normal model or a user model, but I would take a look at the API and look at the ierr = psspy.change_var(number, newval) function. You might need to do some DOCU parsing to get the VAR number if you want it to be automatic.

2014-02-21 12:28:27 -0500 commented question How to compile an ipl file in the IPLAN compiler?

Try giving it the full path to the .ipl file

2014-02-04 15:46:24 -0500 received badge  Good Answer (source)