First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

Ask Your Question
1

Extract data with dyntools and plot with matplotlib

asked Sep 1 '17

Karma1 gravatar image

I am running psse from python but how do I extract the data from the .out file using dyntools and then plot with matplotlib? In my view, this aspect has not been cover well on this forum. Does anyone have a complete code (load flow+dynamic simulation+extracting data using dyntools+plotting using matplotlib), say using the savnw.sav and savnw.dyr files in PSSE examples?

3 answers

Sort by » oldest newest most voted
0

answered Sep 5 '17

jconto gravatar image

updated Sep 6 '17

For plot code from dyntools,check also the post "Plot Legend For Dyntools" or "chanplot.py = dyntools_demo.py with function calls." zezo510 code did not work on my pc. I made a few mods to get it run in/out of the PSSe GUI:

import os,sys
#---User vars   -----------------
outfile = r"""bus154_fault.out"""
chani   = 41
psseversion = 33
#--------------------------------
if psseversion== 34 or psseversion== 33:
   exec('import psse%s'%psseversion)
else:
   pssepath = r"C:\Program Files (x86)\PTI\PSSE%s\PSSBIN"%psseversion
   if pssepath not in sys.path:
      sys.path.append(pssepath)
#--------------------------------
import psspy
#psspy.psseinit(15000)
#--------------------------------
import dyntools
import matplotlib.pyplot as plt

chnfobj = dyntools.CHNF(outfile)
short_title, chanid, chandata = chnfobj.get_data()

t = chandata['time']
v = chandata[chani]              #based on the channel identifier set in the dynamic simulation

fig = plt.figure()
fig.patch.set_facecolor('0.8')
plt.plot(t,v,linestyle='-', linewidth=1, color='green',label="Voltage")     #change ax1. to plt.
plt.grid(linestyle='--', color='grey',linewidth=0.5)
plt.xlabel("Time")
plt.ylabel("Voltage")
plt.legend()
axes = plt.gca()
#axes.set_facecolor('w')            #<- produce error
#axes.set_ylim([0.6,1.2])
axes.set_xlim([0,10])
plt.savefig(r"""figure.pdf""",dpi=fig.dpi,facecolor='0.8')
plt.show()
link

Comments

exec is completely unnecessary here, deprecated in Python 3, and generally a bad idea when posting code for public use. I'm not sure why you got errors with set_ylim and set_facecolor, could you perhaps post them? The difference in using plt.stuff and ax.stuff is that plt style is more Matlab.

SqFKYo gravatar imageSqFKYo (Sep 11 '17)

"exec" is not being used! Code has been tested in a PSSe v.33, python 2.7 setup. axes.set_ylim does not cause an error but it is by-passed to allow auto range. "set_facecolor" causes error in python 2.7.

jconto gravatar imagejconto (Sep 11 '17)

Thanks, this is helpful!

Dao Vu gravatar imageDao Vu (Nov 23 '18)
0

answered Dec 13 '17

lmcqueen gravatar image

updated Dec 13 '17

Does this work on extracting large amount of data from .out file? When i tried to run the WSCC 9 bus system and extracted the data, it worked perfectly. However, when i try the code to extract the data from results or large simulation, this is what i got:

C:\Users\jcsC\Anaconda2\python.exe D:/WSCC9busPSSE/WSCC9busPSSE/plot2.py Traceback (most recent call last): File "D:/WSCC9busPSSE/WSCC9busPSSE/plot2.py", line 22, in <module> chnfobj = dyntools.CHNF(outfile) File ".\dyntools.py", line 1007, in init File ".\dyntools.py", line 341, in outextractdata File ".\dyntools.py", line 315, in outextractid Exception: ERROR ... File d:\wscc9buspsse\wscc9buspsse\q530-sum-on-cct-1-12cy.out version is 1.47195e+19 DynChanExtract handles version 2.0 files only.

link

Comments

You have saved an outx-file even if the suffix is .out. Dyntools cannot read .outx file format. See Question "PSSE/e 34 dyntools module" for more information.

perolofl gravatar imageperolofl (Dec 13 '17)

@perolofl. Yes, already saw the post and fixed the problem. Thanks. Now, I'm working to create a code that extracts the data in the out file and plots them into 4 plots in a single page.

lmcqueen gravatar imagelmcqueen (Dec 14 '17)
0

answered Sep 3 '17

zezo510 gravatar image

This is a simple example to extract (time) and (voltage) channels from an output (.out) file and plotting them using matplotlip. Then saving the resulting plot in a pdf file. You can manipulate it to extract and plot any other data you need.

import dyntools
import matplotlib.pyplot as plt

outfile = r"""test.out"""
chnfobj = dyntools.CHNF(outfile)
short_title, chanid, chandata = chnfobj.get_data()

t = chandata['time']
v = chandata[1]              #based on the channel identifier set in the dynamic simulation

fig = plt.figure()
fig.patch.set_facecolor('0.8')
ax1.plot(t,v,linestyle='-', linewidth=1, color='green',label="Voltage")
plt.grid(linestyle='--', color='grey',linewidth=0.5)
plt.xlabel("Time")
plt.ylabel("Voltage")
plt.legend()
axes = plt.gca()
axes.set_facecolor('w')
axes.set_ylim([0.6,1.2])
axes.set_xlim([0,10])
plt.savefig(r"""figure.pdf""",dpi=fig.dpi,facecolor='0.8')
plt.show()
link

Comments

#jconto and #zezo510, job well done guys! #zezo510 replacing ax1 with plt in your answer like #jconto did works wonders...I guess you actually didn't mean to type ax1 as well. I hope admin can take note of this answer as the most complete on this subject.

Karma1 gravatar imageKarma1 (Sep 5 '17)

Should be `axes.plot(t,v,linestyle='-', linewidth=1, color='green',label="Voltage")` After the `axes = plt.gca()`

SqFKYo gravatar imageSqFKYo (Sep 11 '17)

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

6 followers

Stats

Asked: Sep 1 '17

Seen: 6,680 times

Last updated: Dec 13 '17