In [8]:
# Import some numerical math and plotting packages
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

# Import the MesaProfile package
from MesaProfile import MesaProfile

# Import the OrderedDict package for working with MesaProfile outputs
from collections import OrderedDict

# Read the input MESA profile                                                                                                                                                                                      
mesa = MesaProfile('profile64.data')
mstar = mesa.getStar()    #gives dic of fields inside profile

In [9]:
# List the data fields available in the profile
for k in mstar.keys():  
    print(k)


zone
logT
logRho
logP
logR
luminosity
logL
velocity
entropy
conv_mixing_type
csound
v_div_csound
v_div_r
eta
mu
logdq
dq_ratio
q
radius
temperature
tau
logtau
pressure
pgas_div_ptotal
logPgas
grada
cp
logS
gam
free_e
chiRho
chiT
abar
zbar
z2bar
ye
log_opacity
eps_nuc
non_nuc_neu
eps_grav
mlt_mixing_length
log_D_mix
log_conv_vel
conv_vel_div_csound
log_mlt_D_mix
pressure_scale_height
gradT
gradr
dlnd_dt
dlnT_dt
mass
mmid
logxq
h1
he3
he4
c12
n14
o16
ne20
mg24
si28
pp
cno
tri_alfa
burn_c
burn_n
burn_o
burn_ne
burn_na
burn_mg
burn_si
burn_s
burn_ar
burn_ca
burn_ti
burn_cr
burn_fe
c12_c12
c12_o16
o16_o16
pnhe4
photo
other
extra_heat
gradr_sub_grada
brunt_N2
brunt_B
brunt_nonB
sign_brunt_N2
lamb_S2
lamb_S
log_brunt_nu
log_lamb_Sl2
log_lamb_Sl3
brunt_N_div_r_integral
k_r_integral
brunt_N2_sub_omega2
sl2_sub_omega2
logQ
radiuscm
model_number
num_zones
initial_mass
initial_z
star_age
time_step
Teff
photosphere_L
photosphere_r
center_eta
center_h1
center_he3
center_he4
center_c12
center_n14
center_o16
center_ne20
star_mass
star_mdot
star_mass_h1
star_mass_he3
star_mass_he4
star_mass_c12
star_mass_n14
star_mass_o16
star_mass_ne20
he_core_mass
c_core_mass
o_core_mass
si_core_mass
fe_core_mass
neutron_rich_core_mass
tau10_mass
tau10_radius
tau100_mass
tau100_radius
dynamic_time
kh_timescale
nuc_timescale
power_nuc_burn
power_h_burn
power_he_burn
power_neu
burn_min1
burn_min2

In [10]:
print(mstar)


OrderedDict([('zone', array([4670, 4669, 4668, ...,    3,    2,    1])), ('logT', array([ 8.90681299,  8.90681197,  8.90681078, ...,  7.0292963 ,
        7.02681864,  7.02341436])), ('logRho', array([ 9.66511783,  9.6651162 ,  9.66511426, ..., -0.68603295,
       -0.69350332, -0.70371653])), ('logP', array([ 27.57290096,  27.57289878,  27.57289618, ...,  14.2294201 ,
        14.21947902,  14.20585976])), ('logR', array([-5.85545746, -5.75511366, -5.65476959, ..., -2.57834948,
       -2.57833857, -2.57832741])), ('luminosity', array([ 155752.91738267,  311495.59796466,  622956.90815246, ...,
         15294.33145995,   15294.51791051,   15294.70863798])), ('logL', array([ 5.19243619,  5.49345191,  5.79445801, ...,  4.1845305 ,
        4.18453579,  4.18454121])), ('velocity', array([  1.01312906e+00,   1.27646394e+00,   1.60824638e+00, ...,
         5.80601186e+04,   7.31220318e+04,  -9.54019023e-02])), ('entropy', array([  0.59640509,   0.596405  ,   0.59640491, ...,  11.78939432,
        11.79578147,  11.80440057])), ('conv_mixing_type', array([1, 1, 1, ..., 0, 0, 0])), ('csound', array([  1.04031149e+09,   1.04031083e+09,   1.04031005e+09, ...,
         3.52865399e+07,   3.51862915e+07,   3.50486597e+07])), ('v_div_csound', array([  9.73871187e-10,   1.22700276e-09,   1.54593049e-09, ...,
         1.64694961e-03,   2.08221208e-03,  -2.72198433e-09])), ('v_div_r', array([  1.04357935e-05,   1.04357929e-05,   1.04357919e-05, ...,
         3.15958929e-04,   3.97914771e-04,  -5.19143813e-10])), ('eta', array([ 90.93550015,  90.93559337,  90.93569695, ...,  -7.91616488,
        -7.92453241,  -7.9359889 ])), ('mu', array([ 1.78124569,  1.78124569,  1.78124569, ...,  1.34070662,
        1.34070662,  1.34070662])), ('logdq', array([ -8.19396315,  -8.19396197,  -7.89293087, ..., -13.14533619,
       -12.8443062 , -12.8443062 ])), ('dq_ratio', array([ 1.        ,  2.00000508,  1.99999998, ...,  2.        ,
        1.        ,  1.        ])), ('q', array([  6.39789122e-09,   1.27957999e-08,   2.55916496e-08, ...,
         1.00000000e+00,   1.00000000e+00,   1.00000000e+00])), ('radius', array([  1.39489828e-06,   1.75746360e-06,   2.21426916e-06, ...,
         2.64028328e-03,   2.64034957e-03,   2.64041744e-03])), ('temperature', array([  8.06887509e+08,   8.06885600e+08,   8.06883394e+08, ...,
         1.06978450e+07,   1.06369874e+07,   1.05539336e+07])), ('tau', array([  7.05489176e+12,   7.05351351e+12,   7.05177702e+12, ...,
         7.09820257e+03,   6.88245400e+03,   6.66666667e+03])), ('logtau', array([ 12.84849036,  12.8484055 ,  12.84829857, ...,   3.85114839,
         3.83774332,   3.82390874])), ('pressure', array([  3.74025281e+27,   3.74023403e+27,   3.74021166e+27, ...,
         1.69597755e+14,   1.65759726e+14,   1.60642244e+14])), ('pgas_div_ptotal', array([ 0.99999971,  0.99999971,  0.99999971, ...,  0.80524132,
        0.80522766,  0.80522671])), ('logPgas', array([ 27.57290083,  27.57289865,  27.57289606, ...,  14.13534615,
        14.1253977 ,  14.11177793])), ('grada', array([ 0.37536356,  0.37536358,  0.37536361, ...,  0.29514733,
        0.2951445 ,  0.29514496])), ('cp', array([  1.51942120e+07,   1.51942090e+07,   1.51942057e+07, ...,
         5.13532559e+08,   5.13566891e+08,   5.13564330e+08])), ('logS', array([ 7.69537604,  7.69537598,  7.69537591, ...,  8.99132619,
        8.99156142,  8.99187864])), ('gam', array([ 12.28626633,  12.28628003,  12.28629534, ...,   0.03242995,
         0.03242902,   0.03242901])), ('free_e', array([ 0.49999958,  0.49999958,  0.49999958, ...,  0.49712827,
        0.49725659,  0.49738535])), ('chiRho', array([ 1.33445506,  1.33445507,  1.33445508, ...,  0.80484829,
        0.80483464,  0.80483482])), ('chiT', array([ 0.00759389,  0.00759388,  0.00759387, ...,  1.58550091,
        1.58554111,  1.58553997])), ('abar', array([ 16.28535439,  16.28535438,  16.28535438, ...,   4.05913218,
         4.05913218,   4.05913218])), ('zbar', array([ 8.14267719,  8.14267719,  8.14267719, ...,  2.02956609,
        2.02956609,  2.02956609])), ('z2bar', array([ 68.27273489,  68.27273487,  68.27273484, ...,   4.31435164,
         4.31435164,   4.31435164])), ('ye', array([ 0.5,  0.5,  0.5, ...,  0.5,  0.5,  0.5])), ('log_opacity', array([-4.91841314, -4.91841227, -4.91841305, ..., -0.63667518,
       -0.63661802, -0.63651794])), ('eps_nuc', array([  3.45673910e+13,   3.45650751e+13,   3.45623772e+13, ...,
         3.92831163e-39,   2.95821679e-39,   2.00200793e-39])), ('non_nuc_neu', array([  3.44729933e+07,   3.44724560e+07,   3.44718366e+07, ...,
         5.35527636e-11,   4.30025318e-11,   3.09299096e-11])), ('eps_grav', array([ -8.11698878e+11,  -8.11693265e+11,  -8.11687279e+11, ...,
         1.77730029e+12,   1.80642087e+12,   1.84786341e+12])), ('mlt_mixing_length', array([  1.02367171e+08,   1.02367285e+08,   1.02367465e+08, ...,
         3.00035823e+05,   2.97753689e+05,   2.96587668e+05])), ('log_D_mix', array([ 14.6318604 ,  14.5984083 ,  14.56495329, ..., -99.        ,
       -99.        , -99.        ])), ('log_conv_vel', array([  7.10074037,   7.06728778,   7.03383201, ..., -99.        ,
       -99.        , -99.        ])), ('conv_vel_div_csound', array([ 0.01212208,  0.01122341,  0.01039128, ...,  0.        ,
        0.        ,  0.        ])), ('log_mlt_D_mix', array([ 14.70356997,  14.67011767,  14.63666237, ..., -99.        ,
       -99.        , -99.        ])), ('pressure_scale_height', array([  9.25627410e-02,   7.34670611e-02,   5.83108421e-02, ...,
         2.15952858e-06,   2.14738570e-06,   2.13071976e-06])), ('gradT', array([ 0.47093025,  0.4572824 ,  0.44555611, ...,  0.24994164,
        0.24999528,  0.25000354])), ('gradr', array([  1.41695855e+10,   1.41691611e+10,   1.41684279e+10, ...,
         2.49941644e-01,   2.49995276e-01,   2.50003538e-01])), ('dlnd_dt', array([ -3.13073804e-05,  -3.13073768e-05,  -3.13073728e-05, ...,
         3.47564363e-03,   2.31261944e-03,   0.00000000e+00])), ('dlnT_dt', array([  5.06693620e-05,   5.06690734e-05,   5.06687805e-05, ...,
         1.02572716e-03,   6.08238787e-04,   0.00000000e+00])), ('mass', array([  8.91139890e-09,   1.78228221e-08,   3.56457136e-08, ...,
         1.39286502e+00,   1.39286502e+00,   1.39286502e+00])), ('mmid', array([  4.45569945e-09,   1.33671105e-08,   2.67342678e-08, ...,
         1.39286502e+00,   1.39286502e+00,   1.39286502e+00])), ('logxq', array([ -2.77856886e-09,  -5.55714531e-09,  -1.11143123e-08, ...,
        -1.25432762e+01,  -1.28443062e+01,  -9.90000000e+01])), ('h1', array([  0.00000000e+00,   0.00000000e+00,   0.00000000e+00, ...,
         1.00000020e-99,   1.00000020e-99,   1.00000020e-99])), ('he3', array([  9.52913460e-33,   9.52913619e-33,   9.52913823e-33, ...,
         1.00000016e-99,   1.00000016e-99,   1.00000016e-99])), ('he4', array([  3.49291460e-12,   3.49277828e-12,   3.49261887e-12, ...,
         9.80577079e-01,   9.80577079e-01,   9.80577079e-01])), ('c12', array([ 0.14193008,  0.14193008,  0.14193008, ...,  0.00021885,
        0.00021885,  0.00021885])), ('n14', array([  8.43391242e-06,   8.43391245e-06,   8.43391249e-06, ...,
         1.25673285e-02,   1.25673285e-02,   1.25673285e-02])), ('o16', array([  5.52822173e-01,   5.52822173e-01,   5.52822173e-01, ...,
         4.46957762e-04,   4.46957762e-04,   4.46957762e-04])), ('ne20', array([ 0.27830225,  0.27830225,  0.27830225, ...,  0.00188949,
        0.00188949,  0.00188949])), ('mg24', array([ 0.02490102,  0.02490102,  0.02490102, ...,  0.00368124,
        0.00368124,  0.00368124])), ('si28', array([ 0.00203604,  0.00203604,  0.00203604, ...,  0.00061905,
        0.00061905,  0.00061905])), ('pp', array([  4.01316120e-15,   4.01296037e-15,   4.01272546e-15, ...,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00])), ('cno', array([  5.38781897e-14,   5.38664031e-14,   5.38527364e-14, ...,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00])), ('tri_alfa', array([  2.94686111e-07,   2.94649198e-07,   2.94605933e-07, ...,
         8.81412633e-56,   6.21397647e-56,   3.84115356e-56])), ('burn_c', array([  4.20379542e+09,   4.20353268e+09,   4.20322564e+09, ...,
         3.92821845e-39,   2.95814943e-39,   2.00196483e-39])), ('burn_n', array([  1.23921914e+10,   1.23914570e+10,   1.23905980e+10, ...,
         9.31814139e-44,   6.73644440e-44,   4.30989735e-44])), ('burn_o', array([  1.23213336e+13,   1.23204944e+13,   1.23195141e+13, ...,
         1.60392081e-54,   1.12252009e-54,   6.86798416e-55])), ('burn_ne', array([  6.59323853e+12,   6.59282470e+12,   6.59234072e+12, ...,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00])), ('burn_na', array([ 0.,  0.,  0., ...,  0.,  0.,  0.])), ('burn_mg', array([  2.03744132e+011,   2.03728443e+011,   2.03710128e+011, ...,
         9.49174606e-198,   6.39410887e-199,   1.53194609e-200])), ('burn_si', array([ 0.,  0.,  0., ...,  0.,  0.,  0.])), ('burn_s', array([ 0.,  0.,  0., ...,  0.,  0.,  0.])), ('burn_ar', array([ 0.,  0.,  0., ...,  0.,  0.,  0.])), ('burn_ca', array([ 0.,  0.,  0., ...,  0.,  0.,  0.])), ('burn_ti', array([ 0.,  0.,  0., ...,  0.,  0.,  0.])), ('burn_cr', array([ 0.,  0.,  0., ...,  0.,  0.,  0.])), ('burn_fe', array([ 0.,  0.,  0., ...,  0.,  0.,  0.])), ('c12_c12', array([  1.53897773e+13,   1.53887344e+13,   1.53875242e+13, ...,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00])), ('c12_o16', array([  4.27014764e+10,   4.26981079e+10,   4.26941894e+10, ...,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00])), ('o16_o16', array([ 14817.54344939,  14816.04667533,  14814.30621713, ...,
            0.        ,      0.        ,      0.        ])), ('pnhe4', array([ 0.,  0.,  0., ...,  0.,  0.,  0.])), ('photo', array([ -3.19576399e-06,  -3.19514371e-06,  -3.19442667e-06, ...,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00])), ('other', array([ 0.,  0.,  0., ...,  0.,  0.,  0.])), ('extra_heat', array([ 0.,  0.,  0., ...,  0.,  0.,  0.])), ('gradr_sub_grada', array([  1.41695855e+10,   1.41691611e+10,   1.41684279e+10, ...,
        -4.52047441e-02,  -4.51494502e-02,  -4.51414180e-02])), ('brunt_N2', array([ -1.05920522e-05,  -1.44109936e-05,  -1.95981152e-05, ...,
         3.25094322e+03,   3.27188613e+03,   3.28379275e+03])), ('brunt_B', array([  6.37038543e-05,   6.97473572e-05,   7.45623417e-05, ...,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00])), ('brunt_nonB', array([-0.09556668, -0.08191881, -0.07019249, ...,  0.04520474,
        0.04514945,  0.04514142])), ('sign_brunt_N2', array([-1., -1., -1., ...,  1.,  1.,  1.])), ('lamb_S2', array([  2.29656062e+08,   1.44673777e+08,   9.11382933e+07, ...,
         7.36089525e-02,   7.30399044e-02,   7.27501880e-02])), ('lamb_S', array([  1.51544074e+04,   1.20280413e+04,   9.54663780e+03, ...,
         2.71309698e-01,   2.70258958e-01,   2.69722428e-01])), ('log_brunt_nu', array([-99.        , -99.        , -99.        , ...,   6.95782482,
         6.95921922,   6.960008  ])), ('log_lamb_Sl2', array([ 9.62091972,  9.52057567,  9.4202312 , ...,  4.87384608,
        4.87216086,  4.87129782])), ('log_lamb_Sl3', array([ 9.77143471,  9.67109067,  9.5707462 , ...,  5.02436108,
        5.02267585,  5.02181282])), ('brunt_N_div_r_integral', array([ 0.       ,  0.       ,  0.       , ...,  0.9997725,  1.       ,  1.       ])), ('k_r_integral', array([ 0.,  0.,  0., ...,  1.,  1.,  1.])), ('brunt_N2_sub_omega2', array([ 0.,  0.,  0., ...,  0.,  0.,  0.])), ('sl2_sub_omega2', array([ 1.,  1.,  1., ...,  0.,  0.,  0.])), ('logQ', array([ 3.85149185,  3.85149227,  3.85149271, ..., -2.74462555,
       -2.74714061, -2.75054525])), ('radiuscm', array([  9.70151753e+04,   1.22231593e+05,   1.54002420e+05, ...,
         1.83631702e+08,   1.83636313e+08,   1.83641033e+08])), ('model_number', 302941), ('num_zones', 4670), ('initial_mass', 1.0), ('initial_z', 0.02), ('star_age', 6374110.407142787), ('time_step', 1.3215502803744876e-05), ('Teff', 1250052.992477552), ('photosphere_L', 15294.708637982387), ('photosphere_r', 0.0026404174383996026), ('center_eta', 90.9355337273967), ('center_h1', 0.0), ('center_he3', 9.52913517501673e-33), ('center_he4', 3.492865493770681e-12), ('center_c12', 0.14193008147772534), ('center_n14', 8.433912427237713e-06), ('center_o16', 0.5528221729869516), ('center_ne20', 0.27830224814319093), ('star_mass', 1.392865023090213), ('star_mdot', 1.4862656251675844e-06), ('star_mass_h1', 2.6997658217148352e-36), ('star_mass_he3', 1.2240830091843529e-32), ('star_mass_he4', 3.1606403718893226e-06), ('star_mass_c12', 0.3388083469730627), ('star_mass_n14', 9.172189772774057e-06), ('star_mass_o16', 0.7148888829203025), ('star_mass_ne20', 0.30802448808118954), ('he_core_mass', 1.392865023090213), ('c_core_mass', 1.3928533733545418), ('o_core_mass', 0.0), ('si_core_mass', 0.0), ('fe_core_mass', 0.0), ('neutron_rich_core_mass', 0.0), ('tau10_mass', 0.0), ('tau10_radius', 0.0), ('tau100_mass', 0.0), ('tau100_radius', 0.0), ('dynamic_time', 1.1510334470266221), ('kh_timescale', 1127674.6144765103), ('nuc_timescale', 910684.2477739111), ('power_nuc_burn', 251482990030.16107), ('power_h_burn', 1.814409361722184e-09), ('power_he_burn', 2314.601415664566), ('power_neu', 1985280.953501792), ('burn_min1', 50.0), ('burn_min2', 1000.0)])

In [11]:
## Show all plots
plt.show()


# Map abundances to set of C12, O16, Ne20, Ne22 for flash!
fmap = {'c12':np.array([]),'o16':np.array([]),'ne20':np.array([]),'ne22':np.array([])}
## Maintain constant C12 abundance
fmap['c12'] = mstar['c12']
## Determine Ne22 abundance from model Ye
fmap['ne22'] = np.maximum(22.0*(0.5-mstar['ye']), 0.0)
## Normalization requires Ne20 + O16 abundances = xother
xother = 1.0 - fmap['c12'] - fmap['ne22']
## Ne20/O16 ratio remains constant
rneo = mstar['ne20']/mstar['o16']
## Use rneo and xother constraints to find Ne20 and O16 abundances
fmap['o16'] = xother/(rneo+1.0)
fmap['ne20'] = rneo*xother/(rneo+1.0)

# Write new abundances to output file (one line per zone)
## Note we assume normalization so o16 makes up the difference!
## Note mesa's radius units are Rsun so I convert to cm for output
## Format is:
## l.1: # radius         dens           temp        c12          ne20          ne22
## l.2: [Number of lines to follow]
## l.3: data according to header
fout = open('profile64.output.data','w')
fout.write('# radius         dens           pres           temp        c12          ne20          ne22\n')
numpts = len(fmap['c12']) # Can use something else if, e.g. you mass-average
fout.write(str(numpts) + '\n')

def esf(x):
	return '{0:0.15e}'.format(x)

for i in range(0,numpts):
	fout.write(esf(mstar['radiuscm'][i]) + '  ' +
			esf(10.0**mstar['logRho'][i]) + '  ' + 
			esf(mstar['pressure'][i]) + '  ' + 
			esf(mstar['temperature'][i]) + '  ' +
			esf(fmap['c12'][i]) + '  ' +
			esf(fmap['ne20'][i]) + '  ' +
			esf(fmap['ne22'][i]) + '\n')

# All done, save file!
fout.close()

In [ ]: