I found the following thread in the physics stackexchange where I saw the video called output attached to the main post. The video can be found here.
How would I go about creating such an animation?
Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. It only takes a minute to sign up.
Sign up to join this communityIn case you are interested in generating the individual frames, here is a little example in python:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt # For plotting graphs.
import numpy as np
import subprocess # For issuing commands to the OS.
import os
import sys # For determining the Python version.
import glob
fileList = glob.glob(os.path.join("LEMtrace*.dat"))
style = {0: '--',
1: '-',
2: '-.',
3: ':'}
color = {0: 'k',
1: 'r',
2: 'g',
3: 'b'}
n = 0
for f in fileList:
n = n + 1
plt.figure()
data = np.loadtxt(f)
ax = plt.subplot(111)
ax.plot(data[:,0],data[:,1],label='YO2',c=color[0],ls=style[0])
ax.plot(data[:,0],data[:,2],label='YH2',c=color[1],ls=style[1])
ax.plot(data[:,0],data[:,3],label='YOH',c=color[2],ls=style[2])
ax.plot(data[:,0],data[:,8]/2000.,label='T/2000',c=color[3],ls=style[3])
ax.set_xlabel('LEM cell')
ax.set_ylabel('Mass fraction or T / 2000 K')
ax.set_ylim((0.0,2.0))
str = 'Time {0:.5f} ms'.format(n * 5.8e-5)
plt.title(str)
leg = ax.legend(loc='best', shadow=True, fancybox=True)
fig = "frame_%04d"%(n)
plt.savefig(fig+'.png',format='png')
plt.clf()
command = ('mencoder',
'mf://*png',
'-mf',
'type=png:w=800:h=600:fps=5',
'-ovc',
'lavc',
'-lavcopts',
'vcodec=mpeg4',
'-oac',
'copy',
'-o',
'profile_LEM.avi')
print "\n\nabout to execute:\n%s\n\n" % ' '.join(command)
subprocess.check_call(command)
command = ('convert',
'frame*png',
'+dither',
'-layers',
'Optimize',
'-colors',
'256',
'-depth',
'8',
'profile_LEM.gif')
subprocess.check_call(command)
print "\n\n The movie was written to 'output.avi'"
Assuming you have some 1D data stored in the LEMtrace*.dat
files, this program loads the data for each file using numpy.loadtxt
(great for text files), plots a simple graph using matplotlib
and output 1 frame for each file with nice little time counter. Then it uses either mencoder
or convert
to generate an avi
or gif
animation. Hope this helps !
PS: A not so pretty (because of the data) example of the output:
I will assume that you know how to output all the frames you want in the movie. Then a simple free tool to turn them into a movie as Imagemagick's convert. If you are on a Linux system, you probably already have it or can easily get it through your package manager. Depending on the format of movie you want to make, you will also need an appropriate encoder (e.g., ffmpeg). If you have a bunch of files
frame001.png
frame002.png
...
Then you simply
convert *.png movie.mpg
There are lots of options you can use to change the framerate and other things; see the documentation for convert linked above.
I use Mathematica a lot for this kind of things... Animation can be made very easily:
Manipulate[
Plot[Sin[x + t] + Cos[0.3 x + t], {x, 0, 20},PlotRange -> {All, {-2, 2}}],
{t, 1, 10}
]
This gives you an interactive plot with a slider to drag for t.
To save the animation as a movie just export it:
Export["movie.mov",
Table[Plot[Sin[x + t] + Cos[0.3 x + t], {x, 0, 20}, PlotRange -> {All, {-2, 2}}],
{t, 1, 10, 0.1}
]
]
Example:
For quick viz nothing beats gnuplot ...
for i in `seq 1 100`; do echo "set pm3d; set zrange [1:5000]; splot $i*x**2+$i*y**2"; done | gnuplot