You are here: Home / Tools & Utilities / Python / SimpleMesaMovie.py

SimpleMesaMovie.py

Simple python script to generate an mp4 movie using stellar data stored in MESA .data files made available through mesa class

SimpleMesaMovie.py — Python Source, 1 kB (1878 bytes)

File contents

'''
Simple python script to generate a mp4 movie using stellar
data stored in MESA .data files made available through 
mesa class
'''
import os, sys
import numpy as np

#...Mesa & plot specifics
import matplotlib.pyplot as plt
import mesa as ms

#...basic matplotlib setup to use tex style
#...further customization through matplotlibrc
from matplotlib.pyplot import  rc
rc('font',**{'family':'serif','serif':['Palatino']})
rc('text', usetex=True)


files = []
i     = 0

#...how to step through the .data sequence
models    = np.arange(13025,15100,5)              

#...initialize the figure
fig = plt.figure(figsize=(8.,6.))
ax  = fig.add_subplot(111,axisbg='#3366CC')

ax.set_autoscale_on(False)
ax.set_xlim(0.,1.)

for mod_no in models:
    ax.cla()

    prof=ms.mesa_profile('.',mod_no,num_type='model')

    lgrh      = prof.get('logRho')
    lgt       = prof.get('logT')

    ax.plot(lgrh,lgt,c='k',lw=1.8)

    plt.xlabel(r'$\log \rho$')      
    plt.ylabel(r'$\log T$')

    ax.set_ylim(7.0,8.4)
    ax.set_xlim(1.0,5.5)
    ax.grid(True)
    ax.set_autoscale_on(False)  # enforce x-y lims as set up initially
                                # MUST be placed after LAST plot statement!
    
    fname = '_tmp%03d.png'%i    # I assume <1000 frames!
    print 'Saving frame', fname
    plt.savefig(fname)
    files.append(fname)
 
    # increment what has to be incremented
    i += 1      
                             

print 'Making movie animation.mp4 - this may take a while'

os.system("opt='vbitrate=2160000:mbd=2:keyint=132:v4mv:vqmin=3:vlelim=-4:vcelim=7:lumi_mask=0.07:dark_mask=0.10:naq:vqcomp=0.7:vqblur=0.2:mpeg_quant'")

os.system("mencoder 'mf://_tmp*.png' -mf type=png:fps=10 \
  -ovc lavc -lavcopts vcodec=mpeg4:vpass=1:$opt -oac copy -o animation.mp4")

os.system("rm -rf _tmp*.png")