Analyzing Brown Dwarf Models with MESA Data in Python

InvestigateMESABrownDwarfModel.ipynb

This file appears to be a Jupyter notebook (.ipynb) focused on analyzing brown dwarf models using data processed through the Modules for Experiments in Stellar Astrophysics (MESA). It includes Python code to import necessary libraries (matplotlib for plotting, numpy for numerical calculations, mesa_reader for reading MESA data, pandas for data manipulation), define a function to parse MESA model files, load and process data from a specific model file, and plot the results to visualize the properties (like radius and density) of brown dwarfs. The notebook likely serves as an educational or research tool to investigate the physical characteristics of brown dwarfs using computational astrophysics methods.

snippet.python
import matplotlib.pyplot as plt
import numpy as np
import mesa_reader as mr
import pandas as pd
from io import StringIO
import re
plt.style.use(pubStyle)
snippet.python
def parse_mesa_MOD_file(filepath):
    with open(filepath, 'r') as f:
        content = f.read()
 
    metadataSection = '\n'.join(content.split('\n')[:23])
    metadata = re.finditer(r"(([A-Za-z_\/]+)\s+(.+)\n)[^\n]", metadataSection)
 
    dataSection = '\n'.join(content.split('\n')[23:-9])
    dataSection = dataSection.replace("D", "E")
    df = pd.read_fwf(StringIO(dataSection), colspecs='infer')
    return df
snippet.python
df = parse_mesa_MOD_file("../../BrownDwarfMESA/BD_TEST.mod")
print(df)
     Unnamed: 0        lnd        lnT        lnR             L            dq  \
0             1 -12.054305   6.527047  22.453983  4.802104e+27  5.000000e-13   
1             2 -11.980301   6.538191  22.453980  4.802104e+27  2.500000e-13   
2             3 -11.934523   6.545397  22.453979  4.802104e+27  2.500000e-13   
3             4 -11.899147   6.551094  22.453977  4.802104e+27  1.562500e-13   
4             5 -11.872967   6.555398  22.453976  4.802104e+27  1.562500e-13   
..          ...        ...        ...        ...           ...           ...   
784          85   6.282040  13.137382  17.382338  1.268326e+22  6.250582e-07   
785          86   6.282077  13.137392  17.151280  6.341716e+21  3.125291e-07   
786          87   6.282099  13.137398  16.920226  3.170886e+21  1.562646e-07   
787          88   6.282114  13.137402  16.689173  1.585451e+21  7.813228e-08   
788          89   6.282126  13.137405  16.458122  7.927282e+20  7.813228e-08   

     mlt_vc   h1      he3      he4       c12      n14       o16      ne20  \
0       0.0  0.7  0.00003  0.27997  0.003447  0.00101  0.009381  0.002085   
1       0.0  0.7  0.00003  0.27997  0.003447  0.00101  0.009381  0.002085   
2       0.0  0.7  0.00003  0.27997  0.003447  0.00101  0.009381  0.002085   
3       0.0  0.7  0.00003  0.27997  0.003447  0.00101  0.009381  0.002085   
4       0.0  0.7  0.00003  0.27997  0.003447  0.00101  0.009381  0.002085   
..      ...  ...      ...      ...       ...      ...       ...       ...   
784     0.0  0.7  0.00003  0.27997  0.003447  0.00101  0.009381  0.002085   
785     0.0  0.7  0.00003  0.27997  0.003447  0.00101  0.009381  0.002085   
786     0.0  0.7  0.00003  0.27997  0.003447  0.00101  0.009381  0.002085   
787     0.0  0.7  0.00003  0.27997  0.003447  0.00101  0.009381  0.002085   
788     0.0  0.7  0.00003  0.27997  0.003447  0.00101  0.009381  0.002085   

         mg24  
0    0.004077  
1    0.004077  
2    0.004077  
3    0.004077  
4    0.004077  
..        ...  
784  0.004077  
785  0.004077  
786  0.004077  
787  0.004077  
788  0.004077  

[789 rows x 15 columns]
snippet.python
fig, ax = plt.subplots(1, 1, figsize=(10, 7))
ax.plot(np.exp(df.lnR.values), np.exp(df.lnd.values))
[<matplotlib.lines.Line2D at 0x7f18a3815310>]

png

snippet.python
df.lnd.values
array([-1.20543046e+01, -1.19803014e+01, -1.19345230e+01, -1.18991469e+01,
       -1.18729673e+01, -1.18352586e+01, -1.17875802e+01, -1.17425961e+01,
       -1.17104371e+01, -1.16795644e+01, -1.16498235e+01, -1.16211936e+01,
       -1.15845539e+01, -1.15495476e+01, -1.15160410e+01, -1.14839175e+01,
       -1.14530720e+01, -1.14234095e+01, -1.13948454e+01, -1.13673042e+01,
       -1.13407178e+01, -1.13150242e+01, -1.12901676e+01, -1.12543714e+01,
       -1.12091030e+01, -1.11664127e+01, -1.11260329e+01, -1.10971010e+01,
       -1.10784320e+01, -1.10512962e+01, -1.10165632e+01, -1.09793457e+01,
       -1.09400546e+01, -1.09027450e+01, -1.08672411e+01, -1.08333910e+01,
       -1.08010534e+01, -1.07700960e+01, -1.07404034e+01, -1.07118806e+01,
       -1.06844486e+01, -1.06580348e+01, -1.06325690e+01, -1.06079849e+01,
       -1.05842223e+01, -1.05612287e+01, -1.05389578e+01, -1.05068533e+01,
       -1.04661650e+01, -1.04277107e+01, -1.03912601e+01, -1.03566162e+01,
       -1.03236106e+01, -1.02921016e+01, -1.02619709e+01, -1.02331096e+01,
       -1.02054126e+01, -1.01787843e+01, -1.01531461e+01, -1.01164667e+01,
       -1.00703707e+01, -1.00271829e+01, -9.98653663e+00, -9.94813166e+00,
       -9.92059398e+00, -9.90283239e+00, -9.87700895e+00, -9.84380862e+00,
       -9.81192139e+00, -9.78117316e+00, -9.75140707e+00, -9.72249034e+00,
       -9.69431483e+00, -9.66679386e+00, -9.63985998e+00, -9.61346463e+00,
       -9.57500003e+00, -9.52513337e+00, -9.47713137e+00, -9.43937681e+00,
       -9.41119172e+00, -9.37028665e+00, -9.31783058e+00, -9.26779882e+00,
       -9.22002727e+00, -9.17436677e+00, -9.13067210e+00, -9.08879756e+00,
       -9.04861028e+00, -9.00999579e+00, -8.95487196e+00, -8.88583910e+00,
       -8.83707523e+00, -8.80591653e+00, -8.76103791e+00, -8.70426478e+00,
       -8.65068969e+00, -8.61238688e+00, -8.58770670e+00, -8.55188168e+00,
       -8.50612167e+00, -8.44147418e+00, -8.38093770e+00, -8.34268834e+00,
       -8.30595246e+00, -8.27061988e+00, -8.22005722e+00, -8.17206840e+00,
       -8.14142788e+00, -8.09732923e+00, -8.04162826e+00, -7.98910722e+00,
       -7.93944473e+00, -7.89237027e+00, -7.84761664e+00, -7.80496459e+00,
       -7.76423709e+00, -7.70643970e+00, -7.65207716e+00, -7.61759597e+00,
       -7.56825301e+00, -7.50639028e+00, -7.46262410e+00, -7.43460072e+00,
       -7.40742103e+00, -7.38103444e+00, -7.33666532e+00, -7.27678099e+00,
       -7.22060177e+00, -7.18059935e+00, -7.15488346e+00, -7.11763257e+00,
       -7.07017281e+00, -7.02503276e+00, -6.98198126e+00, -6.92098210e+00,
       -6.86361312e+00, -6.82728151e+00, -6.77535156e+00, -6.72605129e+00,
       -6.69459120e+00, -6.64933482e+00, -6.59217398e+00, -6.53830961e+00,
       -6.49982898e+00, -6.47504192e+00, -6.43907141e+00, -6.39314528e+00,
       -6.32830981e+00, -6.26760636e+00, -6.22927154e+00, -6.19246229e+00,
       -6.15706431e+00, -6.10642933e+00, -6.05838440e+00, -6.02771257e+00,
       -5.98356950e+00, -5.92782950e+00, -5.87531910e+00, -5.83782640e+00,
       -5.81367759e+00, -5.77863899e+00, -5.73393570e+00, -5.69136040e+00,
       -5.65072772e+00, -5.61187616e+00, -5.57466216e+00, -5.52165928e+00,
       -5.45560891e+00, -5.40915386e+00, -5.37952997e+00, -5.33694444e+00,
       -5.28326993e+00, -5.22999688e+00, -5.17726436e+00, -5.12767874e+00,
       -5.09234266e+00, -5.06960523e+00, -5.03664527e+00, -4.99466602e+00,
       -4.95476088e+00, -4.91674690e+00, -4.88046908e+00, -4.84579986e+00,
       -4.81262681e+00, -4.78084455e+00, -4.73556758e+00, -4.67923947e+00,
       -4.63970006e+00, -4.61450377e+00, -4.59017181e+00, -4.56665335e+00,
       -4.53280064e+00, -4.49010741e+00, -4.44994198e+00, -4.41205960e+00,
       -4.37625099e+00, -4.34233203e+00, -4.31009142e+00, -4.27939376e+00,
       -4.23606011e+00, -4.18281375e+00, -4.14588373e+00, -4.12254001e+00,
       -4.08914954e+00, -4.04732626e+00, -4.00787895e+00, -3.97055930e+00,
       -3.93515476e+00, -3.90148321e+00, -3.86938877e+00, -3.83873719e+00,
       -3.80941116e+00, -3.78130651e+00, -3.74132974e+00, -3.70343772e+00,
       -3.67937164e+00, -3.64489695e+00, -3.60127547e+00, -3.56016753e+00,
       -3.52146139e+00, -3.48489265e+00, -3.45024266e+00, -3.41732834e+00,
       -3.38599354e+00, -3.35610216e+00, -3.32740776e+00, -3.29981828e+00,
       -3.27336936e+00, -3.24797391e+00, -3.22355369e+00, -3.20003839e+00,
       -3.16638953e+00, -3.12388087e+00, -3.08388851e+00, -3.04629578e+00,
       -3.01083796e+00, -2.97714650e+00, -2.94505571e+00, -2.91456026e+00,
       -2.88552011e+00, -2.85769012e+00, -2.83097658e+00, -2.80540965e+00,
       -2.78090083e+00, -2.75726617e+00, -2.73444519e+00, -2.71248104e+00,
       -2.69131429e+00, -2.67080080e+00, -2.65090106e+00, -2.62232500e+00,
       -2.58610515e+00, -2.55190450e+00, -2.51951583e+00, -2.48875994e+00,
       -2.45948405e+00, -2.43155405e+00, -2.40485326e+00, -2.37927787e+00,
       -2.35473700e+00, -2.33114970e+00, -2.30844521e+00, -2.28656035e+00,
       -2.26543906e+00, -2.24503054e+00, -2.22528912e+00, -2.20617313e+00,
       -2.18764501e+00, -2.16967035e+00, -2.14369921e+00, -2.11070557e+00,
       -2.07943238e+00, -2.04970653e+00, -2.02137687e+00, -1.99431239e+00,
       -1.96839959e+00, -1.94353990e+00, -1.91964750e+00, -1.89664779e+00,
       -1.87447557e+00, -1.85307329e+00, -1.83238973e+00, -1.81237889e+00,
       -1.79299921e+00, -1.77421279e+00, -1.75598473e+00, -1.73828281e+00,
       -1.72107724e+00, -1.70434047e+00, -1.68804698e+00, -1.67217307e+00,
       -1.65669676e+00, -1.63415425e+00, -1.60534820e+00, -1.57780285e+00,
       -1.55140036e+00, -1.52603784e+00, -1.50162624e+00, -1.47808885e+00,
       -1.45535871e+00, -1.43337663e+00, -1.41208982e+00, -1.39145070e+00,
       -1.37141501e+00, -1.35194213e+00, -1.33299518e+00, -1.31454058e+00,
       -1.29654760e+00, -1.27898802e+00, -1.26183600e+00, -1.24506785e+00,
       -1.22866160e+00, -1.21259679e+00, -1.19685438e+00, -1.18141662e+00,
       -1.16626697e+00, -1.15138999e+00, -1.13677132e+00, -1.12239776e+00,
       -1.10825715e+00, -1.09433831e+00, -1.08063089e+00, -1.06712536e+00,
       -1.05381286e+00, -1.04068495e+00, -1.02773353e+00, -1.00854808e+00,
       -9.86741406e-01, -9.65299377e-01, -9.41350065e-01, -9.17900368e-01,
       -8.94910843e-01, -8.72345908e-01, -8.50173364e-01, -8.28363599e-01,
       -8.06889115e-01, -7.85724437e-01, -7.64845940e-01, -7.44232097e-01,
       -7.23863448e-01, -7.03721821e-01, -6.83790143e-01, -6.64053468e-01,
       -6.44500904e-01, -6.25122786e-01, -6.05909899e-01, -5.86854003e-01,
       -5.67951277e-01, -5.49200386e-01, -5.30601254e-01, -5.12153961e-01,
       -4.93846314e-01, -4.75658236e-01, -4.57571261e-01, -4.39568847e-01,
       -4.21632332e-01, -4.03737484e-01, -3.85858302e-01, -3.67966885e-01,
       -3.50037090e-01, -3.32050279e-01, -3.13986770e-01, -2.95823452e-01,
       -2.77537972e-01, -2.59118109e-01, -2.40548320e-01, -2.21807318e-01,
       -2.02885918e-01, -1.83800469e-01, -1.64568774e-01, -1.45207921e-01,
       -1.25738277e-01, -1.06185738e-01, -8.65794327e-02, -6.69456065e-02,
       -4.73042308e-02, -2.76765068e-02, -8.08401964e-03,  1.14601113e-02,
        3.09495802e-02,  5.03764930e-02,  6.97317485e-02,  8.90112982e-02,
        1.08218318e-01,  1.27355361e-01,  1.46424116e-01,  1.65426127e-01,
        1.84366679e-01,  2.03253190e-01,  2.22093346e-01,  2.40895201e-01,
        2.59666865e-01,  2.78414952e-01,  2.97145653e-01,  3.15865387e-01,
        3.34581008e-01,  3.53295242e-01,  3.72003240e-01,  3.90700706e-01,
        4.09385496e-01,  4.28056562e-01,  4.46708777e-01,  4.65336750e-01,
        4.83936472e-01,  5.02507279e-01,  5.21051848e-01,  5.39571709e-01,
        5.58066342e-01,  5.76537818e-01,  5.94989688e-01,  6.13424148e-01,
        6.31843107e-01,  6.50251189e-01,  6.68651969e-01,  6.87046735e-01,
        7.05433312e-01,  7.23802086e-01,  7.42142559e-01,  7.60445218e-01,
        7.78701300e-01,  7.96902312e-01,  8.15039811e-01,  8.33105407e-01,
        8.51090870e-01,  8.68990080e-01,  8.86797807e-01,  9.04507646e-01,
        9.22112013e-01,  9.39607141e-01,  9.56992302e-01,  9.74266828e-01,
        9.91432189e-01,  1.00850154e+00,  1.02549166e+00,  1.04241762e+00,
        1.05929297e+00,  1.07613142e+00,  1.09294731e+00,  1.10975411e+00,
        1.12655973e+00,  1.14336828e+00,  1.16018413e+00,  1.17701217e+00,
        1.19385621e+00,  1.21071981e+00,  1.22760629e+00,  1.24451686e+00,
        1.26144922e+00,  1.27840166e+00,  1.29537373e+00,  1.31236701e+00,
        1.32938441e+00,  1.34642860e+00,  1.36350202e+00,  1.38060719e+00,
        1.39774783e+00,  1.41492927e+00,  1.43215763e+00,  1.44943639e+00,
        1.46676769e+00,  1.48415417e+00,  1.50159906e+00,  1.51910383e+00,
        1.53666898e+00,  1.55429474e+00,  1.57198064e+00,  1.58972397e+00,
        1.60752175e+00,  1.62537132e+00,  1.64326976e+00,  1.66121259e+00,
        1.67919520e+00,  1.69721339e+00,  1.71526358e+00,  1.73334280e+00,
        1.75144769e+00,  1.76957427e+00,  1.78771850e+00,  1.80587817e+00,
        1.82405138e+00,  1.84223606e+00,  1.86043085e+00,  1.87863734e+00,
        1.89685747e+00,  1.91509273e+00,  1.93334423e+00,  1.95161310e+00,
        1.96990070e+00,  1.98820851e+00,  2.00653713e+00,  2.02488575e+00,
        2.04325357e+00,  2.06164016e+00,  2.08004606e+00,  2.09847240e+00,
        2.11691973e+00,  2.13538782e+00,  2.15387592e+00,  2.17238334e+00,
        2.19090981e+00,  2.20945590e+00,  2.22802399e+00,  2.24661663e+00,
        2.26523580e+00,  2.28388251e+00,  2.30255664e+00,  2.32125858e+00,
        2.33998954e+00,  2.35875049e+00,  2.37754085e+00,  2.39635991e+00,
        2.41520689e+00,  2.43408057e+00,  2.45297898e+00,  2.47189982e+00,
        2.49084072e+00,  2.50980100e+00,  2.52878138e+00,  2.54778243e+00,
        2.56680442e+00,  2.58584717e+00,  2.60491067e+00,  2.62399524e+00,
        2.64310118e+00,  2.66222659e+00,  2.68136852e+00,  2.70052393e+00,
        2.71969043e+00,  2.73886780e+00,  2.75805649e+00,  2.77725704e+00,
        2.79647053e+00,  2.81569872e+00,  2.83494316e+00,  2.85420504e+00,
        2.87348534e+00,  2.89278528e+00,  2.91210655e+00,  2.93145102e+00,
        2.95081892e+00,  2.97020943e+00,  2.98962114e+00,  3.00905234e+00,
        3.02850189e+00,  3.04796898e+00,  3.06745311e+00,  3.08695399e+00,
        3.10647140e+00,  3.12600523e+00,  3.14555558e+00,  3.16512308e+00,
        3.18470824e+00,  3.20431111e+00,  3.22393125e+00,  3.24356801e+00,
        3.26322115e+00,  3.28289084e+00,  3.30257719e+00,  3.32227964e+00,
        3.34199737e+00,  3.36172924e+00,  3.38147437e+00,  3.40123195e+00,
        3.42100112e+00,  3.44078156e+00,  3.46057417e+00,  3.48037997e+00,
        3.50019962e+00,  3.52003361e+00,  3.53988293e+00,  3.55974889e+00,
        3.57963307e+00,  3.59953640e+00,  3.61945935e+00,  3.63940251e+00,
        3.65936626e+00,  3.67934921e+00,  3.69934940e+00,  3.71936498e+00,
        3.73939452e+00,  3.75943724e+00,  3.77949266e+00,  3.79956056e+00,
        3.81964108e+00,  3.83973395e+00,  3.85983794e+00,  3.87995182e+00,
        3.90007744e+00,  3.92021823e+00,  3.93784008e+00,  3.95297184e+00,
        3.96811470e+00,  3.98581063e+00,  4.00603135e+00,  4.02626783e+00,
        4.04651957e+00,  4.06678590e+00,  4.08706568e+00,  4.10735757e+00,
        4.12766047e+00,  4.14797326e+00,  4.16574002e+00,  4.18098731e+00,
        4.19879818e+00,  4.21915001e+00,  4.23951716e+00,  4.25989973e+00,
        4.27517425e+00,  4.29050175e+00,  4.31092247e+00,  4.33135911e+00,
        4.35181112e+00,  4.37227741e+00,  4.39791111e+00,  4.42608038e+00,
        4.44915109e+00,  4.46968795e+00,  4.49023944e+00,  4.51080419e+00,
        4.52621981e+00,  4.54167524e+00,  4.55968827e+00,  4.57772990e+00,
        4.59835136e+00,  4.61898516e+00,  4.63962943e+00,  4.66028281e+00,
        4.67835438e+00,  4.69385626e+00,  4.71195556e+00,  4.73264251e+00,
        4.75333964e+00,  4.77404587e+00,  4.78957229e+00,  4.79993208e+00,
        4.81548404e+00,  4.83362192e+00,  4.85177929e+00,  4.87254159e+00,
        4.88811982e+00,  4.90371922e+00,  4.91931954e+00,  4.92972908e+00,
        4.94274993e+00,  4.96099370e+00,  4.98186380e+00,  4.99752877e+00,
        5.00797928e+00,  5.01843391e+00,  5.02889224e+00,  5.03935393e+00,
        5.04981884e+00,  5.06028688e+00,  5.07075795e+00,  5.08123189e+00,
        5.09170849e+00,  5.09957184e+00,  5.10481579e+00,  5.11268401e+00,
        5.12318288e+00,  5.13368894e+00,  5.14420210e+00,  5.15472229e+00,
        5.16524948e+00,  5.17578366e+00,  5.18632482e+00,  5.19687294e+00,
        5.20742797e+00,  5.21798981e+00,  5.22855838e+00,  5.23913359e+00,
        5.24971531e+00,  5.26030345e+00,  5.27089790e+00,  5.28149860e+00,
        5.29210553e+00,  5.30271800e+00,  5.31332696e+00,  5.32391998e+00,
        5.33448802e+00,  5.34502542e+00,  5.35552953e+00,  5.36600040e+00,
        5.37644030e+00,  5.38425680e+00,  5.38945770e+00,  5.39724572e+00,
        5.40762430e+00,  5.41799723e+00,  5.42837321e+00,  5.43876117e+00,
        5.44916990e+00,  5.45960759e+00,  5.47008128e+00,  5.48059626e+00,
        5.49115529e+00,  5.49910991e+00,  5.50442137e+00,  5.51239840e+00,
        5.52306702e+00,  5.53374788e+00,  5.54443390e+00,  5.55512494e+00,
        5.56582093e+00,  5.57652183e+00,  5.58722756e+00,  5.59793809e+00,
        5.60865335e+00,  5.61937328e+00,  5.63009783e+00,  5.64082695e+00,
        5.65156057e+00,  5.65962446e+00,  5.66766926e+00,  5.67841392e+00,
        5.68916291e+00,  5.69991617e+00,  5.71067364e+00,  5.72143528e+00,
        5.73220104e+00,  5.74297088e+00,  5.75374473e+00,  5.76452255e+00,
        5.77530431e+00,  5.78340862e+00,  5.79148404e+00,  5.80227541e+00,
        5.81307056e+00,  5.82386943e+00,  5.83467199e+00,  5.84547820e+00,
        5.85628801e+00,  5.86710138e+00,  5.87791826e+00,  5.88873861e+00,
        5.89956238e+00,  5.91038953e+00,  5.91853611e+00,  5.92395233e+00,
        5.93205311e+00,  5.94289011e+00,  5.95373029e+00,  5.96457361e+00,
        5.97542004e+00,  5.98626952e+00,  5.99712202e+00,  6.00797748e+00,
        6.01883589e+00,  6.02969718e+00,  6.04056133e+00,  6.04875266e+00,
        6.05418720e+00,  6.06229645e+00,  6.07316893e+00,  6.08404411e+00,
        6.09492193e+00,  6.10580234e+00,  6.11668529e+00,  6.12757070e+00,
        6.13845850e+00,  6.14934859e+00,  6.16024086e+00,  6.17113515e+00,
        6.18203126e+00,  6.19292888e+00,  6.20382757e+00,  6.21472661e+00,
        6.23031266e+00,  6.24768301e+00,  6.25624005e+00,  6.26279731e+00,
        6.26980947e+00,  6.27426257e+00,  6.27692630e+00,  6.27880361e+00,
        6.27996892e+00,  6.28068411e+00,  6.28111445e+00,  6.28136574e+00,
        6.28155411e+00,  6.28174442e+00,  6.28189030e+00,  6.28198218e+00,
        6.28204006e+00,  6.28207652e+00,  6.28209949e+00,  6.28211396e+00,
        6.28212611e+00])

python