Ask Your Question
0

Extract data with dyntools and plot with matplotlib

asked 2017-09-01 17:31:29 -0600

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?

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
0

answered 2017-09-05 10:11:20 -0600

jconto gravatar image

updated 2017-09-05 20:22:32 -0600

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()
edit flag offensive delete link more

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 ( 2017-09-11 00:47:00 -0600 )edit

"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 ( 2017-09-11 08:42:29 -0600 )edit

Thanks, this is helpful!

Dao Vu gravatar imageDao Vu ( 2018-11-23 15:21:12 -0600 )edit
0

answered 2017-12-13 07:48:28 -0600

lmcqueen gravatar image

updated 2017-12-13 07:51:55 -0600

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.

edit flag offensive delete link more

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 ( 2017-12-13 09:10:48 -0600 )edit

@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 ( 2017-12-14 00:50:14 -0600 )edit
0

answered 2017-09-03 10:57:32 -0600

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()
edit flag offensive delete link more

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 ( 2017-09-05 12:38:11 -0600 )edit

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

SqFKYo gravatar imageSqFKYo ( 2017-09-11 00:43:16 -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

6 followers

Stats

Asked: 2017-09-01 17:31:29 -0600

Seen: 6,537 times

Last updated: Dec 13 '17