Ask Your Question
0

Extract data with dyntools and plot with matplotlib

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

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

2 answers

Sort by ยป oldest newest most voted
0

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

jconto gravatar image

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

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 -0500 )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 -0500 )edit
0

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

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 -0500 )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 -0500 )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

1 follower

Stats

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

Seen: 236 times

Last updated: Sep 05