#!/usr/bin/python # # Original code: Josh Lifton 2004 # Permission is hereby granted to use and abuse this document # so long as proper attribution is given. # # Modified: Peter Dobbie 2009 # This is my first Python script and probably looks like it 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. from numpy import * from pylab import load from pylab import save subdir = 'brio-wu/1st-order' print 'Loading data...' ad = [] ap = [] av1 = [] ab1 = [] ab2 = [] ab3 = [] for i in range(0,150): path = subdir + '/Brio-Wu.' + str(i).zfill(4) + '.tab' print 'reading: ' + path data = load(path) x = [] d = [] p = [] v1 = [] b1 = [] b2 = [] b3 = [] for row_num, row in enumerate(data): x.append(row[1]) d.append(row[2]) p.append(row[6]) v1.append(row[3]) b1.append(row[8]) b2.append(row[9]) b3.append(row[10]) ad.append(d) ap.append(p) av1.append(v1) ab1.append(b1) ab2.append(b2) ab3.append(b3) print 'Executing on', os.uname() print 'Python version', sys.version print 'matplotlib version', matplotlib.__version__ try: subprocess.check_call(['mencoder']) except subprocess.CalledProcessError: print "mencoder command was found" pass # mencoder is found, but returns non-zero exit as expected except OSError: print "The mencoder command was not found" sys.exit("quitting\n") # start graphing and saving the images. for i in range(len(ad)) : plt.plot(x, ad[i], color='black', marker='.', markersize=3) plt.plot(x, ap[i], color='magenta', marker='.', markersize=3) plt.plot(x, av1[i], color='cyan', marker='.', markersize=3) plt.plot(x, ab1[i], color='red', marker='.', markersize=3) plt.plot(x, ab2[i], color='green', marker='.', markersize=3) plt.plot(x, ab3[i], color='blue', marker='.', markersize=3) plt.axis((x[0],x[-1],0,1)) plt.xlabel('x') plt.ylabel('$U$') plt.title('1D Brio-Wu: $\\rho$ (black), $p$ (magenta), $v_1$ (cyan), $B_1, B_2, B_3$ (r,g,b)', fontsize=12) filename = subdir + '/' + str('%03d' % i) + '.png' plt.savefig(filename, dpi=100) print 'Wrote file', filename plt.clf() # Clear the figure to make way for the next image. # Now that we have graphed images of the dataset, we will stitch them # together using Mencoder to create a movie. Each image will become # a single frame in the movie: # mencoder mf://*.png -mf type=png:w=800:h=600:fps=5 -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o output.avi command = ('mencoder', 'mf://brio-wu/1st-order/*.png', '-mf', 'type=png:w=800:h=600:fps=5', '-ovc', 'lavc', '-lavcopts', 'vcodec=mpeg4', '-oac', 'copy', '-o', 'brio-wu/1st-order/movie.avi') #os.spawnvp(os.P_WAIT, 'mencoder', command) print "\n\nabout to execute:\n%s\n\n" % ' '.join(command) subprocess.check_call(command) print "\n The movie was written to " + subdir + "/movie.avi" print "You may want to delete " + subdir + "/*.png now."