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

SimpleMesaProf.py

Basis python script to generate a matplotlib structure plot, using the mesa class to easily import data from MESA's .data files

SimpleMesaProf.py — Python Source, 1 kB (1825 bytes)

File contents

'''
Basis python script to generate a matplotlib structure 
plot using mesa class to easily import data from 
MESA's .data files
'''
#-Mesa & plot specifics----------------------------
import matplotlib.pyplot as plt
import mesa as ms

#--------------------------------------------------
#...simplest settings in matplotlib Figures
#...further modifications can be applied in 
#...the matplotlibrc file
#--------------------------------------------------
from matplotlib import rc
rc('font',**{'family':'serif','serif':['Times']})
rc('text', usetex=True)
#--------------------------------------------------

#...set up the stepping through the profile data sets
models = (13980,14220,14405)

#...Plot initializations
lwght  = 0.8                  
offset = 0

for mod_no in models:
    prof=ms.mesa_profile('.',mod_no,num_type='model')

    #...get global stellar data
    star_age = prof.header_attr.get('star_age')

    print 'model no.          :', mod_no
    print 'star age /yrs      :', star_age

    #...get structural quantities
    velocity  = prof.get('velocity')
    lgone_m_q = prof.get('logxq')
    cp        = prof.get('cp')
    mu        = prof.get('mu')
    lgkap     = prof.get('log_opacity')
    dq        = prof.get('dq')    
    lgp       = prof.get('logP')
    lgr       = prof.get('logR')
    lgrho     = prof.get('logRho')
    lgs       = prof.get('logS')
    lgt       = prof.get('logT')
    nabrad    = prof.get('gradr')
    nabad     = prof.get('grada')
    epsnuc    = prof.get('eps_nuc')
    epsgrav   = prof.get('eps_grav')
    lum       = prof.get('luminosity')
    #... and so on!

    mrel = (1.0 - 10**(lgone_m_q))

    plt.plot(mrel,lgt,c='k',lw=lwght + offset)

    offset += 0.1
   
#labeling the plot
plt.xlabel(r'$m/M_\odot$')     
plt.ylabel(r'$\log \rho$')

plt.grid(False)
plt.show()