def change_module(widget, value):
        if value == "History":
            frame.set_state_attribute("select_plot", states_mesa[1:], options={"":"mesa_w_data", "HR-Diagram":"hrd", "Plot":"plot", "Kippenhahn":"kippenhahn", "Kippenhahan contour":"kip_cont", "TCRhoC plot":"tcrhoc", "Get data":"get_data"})
            frame.set_state_attribute("contain_model_select", states_mesa, visible=False)
            frame.set_attributes("contain_model_select", visible=False)
        elif value == "Profile":
            frame.set_attributes("load_data", disabled=True)
            frame.set_state_attribute("select_plot", states_mesa[1:], options={"":"mesa_w_data", "Plot":"plot", "Get data":"get_data"})

            mass = float(frame.get_attribute("mass", "value"))
            Z = float(frame.get_attribute("Z", "value"))
            dir = frame.get_attribute("address_bar", "value")
            if manual_data_select:
                mdir, mmodel = frame.get_state_data("model_data")
                if (mdir != dir) or (mmodel == None):
                    clear_output()
                    pre_data = ms.mesa_profile(dir)
                    mmodel = pre_data.model
                    frame.set_state_data("model_data", (dir, mmodel))
            else:
                mmass, mZ, mmodel = frame.get_state_data("model_data")
                if (mmass != mass) or (mZ != Z) or (mmodel == None):
                    clear_output()
                    pre_data = ms.mesa_profile(mass=mass, Z=Z)
                    mmodel = pre_data.model
                    frame.set_state_data("model_data", (mass, Z, mmodel))

            frame.set_state_attribute("contain_model_select", states_mesa, visible=True)
            frame.set_attributes("contain_model_select", visible=True)
            frame.set_attributes("model_select", value=str(mmodel[-1]))
            frame.set_attributes("load_data", disabled=False)
        else:
            frame.set_state_attribute("contain_model_select", states_mesa, visible=False)
            frame.set_attributes("contain_model_select", visible=False)
    def change_module(widget, value):
        if value == "History":
            frame.set_state_attribute("select_plot",
                                      states_mesa[1:],
                                      options={
                                          "": "mesa_w_data",
                                          "HR-Diagram": "hrd",
                                          "Plot": "plot",
                                          "Kippenhahn": "kippenhahn",
                                          "Kippenhahan contour": "kip_cont",
                                          "TCRhoC plot": "tcrhoc",
                                          "Get data": "get_data"
                                      })
            frame.set_state_attribute("contain_model_select",
                                      states_mesa,
                                      visible=False)
            frame.set_attributes("contain_model_select", visible=False)
        elif value == "Profile":
            frame.set_attributes("load_data", disabled=True)
            frame.set_state_attribute("select_plot",
                                      states_mesa[1:],
                                      options={
                                          "": "mesa_w_data",
                                          "Plot": "plot",
                                          "Get data": "get_data"
                                      })

            mass = float(frame.get_attribute("mass", "value"))
            Z = float(frame.get_attribute("Z", "value"))
            dir = frame.get_attribute("address_bar", "value")
            if manual_data_select:
                mdir, mmodel = frame.get_state_data("model_data")
                if (mdir != dir) or (mmodel == None):
                    clear_output()
                    pre_data = ms.mesa_profile(dir)
                    mmodel = pre_data.model
                    frame.set_state_data("model_data", (dir, mmodel))
            else:
                mmass, mZ, mmodel = frame.get_state_data("model_data")
                if (mmass != mass) or (mZ != Z) or (mmodel == None):
                    clear_output()
                    pre_data = ms.mesa_profile(mass=mass, Z=Z)
                    mmodel = pre_data.model
                    frame.set_state_data("model_data", (mass, Z, mmodel))

            frame.set_state_attribute("contain_model_select",
                                      states_mesa,
                                      visible=True)
            frame.set_attributes("contain_model_select", visible=True)
            frame.set_attributes("model_select", value=str(mmodel[-1]))
            frame.set_attributes("load_data", disabled=False)
        else:
            frame.set_state_attribute("contain_model_select",
                                      states_mesa,
                                      visible=False)
            frame.set_attributes("contain_model_select", visible=False)
    def load(widget):
        clear_output()
        data = None
        mass = float(frame.get_attribute("mass", "value"))
        Z = float(frame.get_attribute("Z", "value"))
        dir = frame.get_attribute("address_bar", "value")
        if frame.get_attribute("model_select", "value") != "":
            model = int(frame.get_attribute("model_select", "value"))
        else:
            model = 1
        module = frame.get_attribute("select_module", "value")
        if module == "H5 out":
            if manual_data_select:
                data = mp.se(dir)
            else:
                data = mp.se(mass=mass, Z=Z)
            frame.set_state("nugrid_w_data")
            properties = ["mass", "radius", "rho", "temperature"]
            frame.set_attributes("xaxis",
                                 options=properties + data.se.isotopes)
            frame.set_attributes("yaxis",
                                 options=properties + data.se.isotopes)
        elif module == "History":
            if manual_data_select:
                data = ms.history_data(dir)
            else:
                data = ms.history_data(mass=mass, Z=Z)
            frame.set_state("mesa_w_data")
            frame.set_attributes("xaxis", options=sorted(data.cols.keys()))
            frame.set_attributes("yaxis", options=sorted(data.cols.keys()))
        elif module == "Profile":
            if manual_data_select:
                data = ms.mesa_profile(dir, num=model)
            else:
                data = ms.mesa_profile(mass=mass, Z=Z, num=model)
            frame.set_state("mesa_w_data")
            frame.set_attributes("xaxis", options=sorted(data.cols.keys()))
            frame.set_attributes("yaxis", options=sorted(data.cols.keys()))
        else:
            nugrid_or_mesa = frame.get_attribute("select_nugrid_mesa", 'value')
            if nugrid_or_mesa == "NuGrid":
                frame.set_state("nugrid")
            elif nugrid_or_mesa == "Mesa":
                frame.set_state("mesa")

        frame.set_state_data("class_instance", data)
        frame.set_attributes("select_plot", selected_label="")
 def mass_Z_handler(name, value):
     if frame.get_attribute("contain_model_select", "visible"):
         mass = float(frame.get_attribute("mass", "value"))
         Z = float(frame.get_attribute("Z", "value"))
         dir = frame.get_attribute("address_bar", "value")
         if manual_data_select:
             mdir, mmodel = frame.get_state_data("model_data")
             if (mdir != dir) or (mmodel == None):
                 clear_output()
                 pre_data = ms.mesa_profile(dir)
                 frame.set_state_data("model_data", (dir, pre_data.model))
         else:
             mmass, mZ, mmodel = frame.get_state_data("model_data")
             if (mmass != mass) or (mZ != Z) or (mmodel == None):
                 clear_output()
                 pre_data = ms.mesa_profile(mass=mass, Z=Z)
                 frame.set_state_data("model_data", (mass, Z, pre_data.model))
 def load(widget):
     clear_output()
     data = None
     mass = float(frame.get_attribute("mass", "value"))
     Z = float(frame.get_attribute("Z", "value"))
     dir = frame.get_attribute("address_bar", "value")
     if frame.get_attribute("model_select", "value") != "":
         model = int(frame.get_attribute("model_select", "value"))
     else:
         model = 1
     module = frame.get_attribute("select_module", "value")
     if module == "H5 out":
         if manual_data_select:
             data = mp.se(dir)
         else:
             data = mp.se(mass=mass, Z=Z)
         frame.set_state("nugrid_w_data")
         properties = ["mass", "radius", "rho", "temperature"]
         frame.set_attributes("xaxis", options=properties+data.se.isotopes)
         frame.set_attributes("yaxis", options=properties+data.se.isotopes)
     elif module == "History":
         if manual_data_select:
             data = ms.history_data(dir)
         else:
             data = ms.history_data(mass=mass, Z=Z)
         frame.set_state("mesa_w_data")
         frame.set_attributes("xaxis", options=sorted(data.cols.keys()))
         frame.set_attributes("yaxis", options=sorted(data.cols.keys()))
     elif module == "Profile":
         if manual_data_select:
             data = ms.mesa_profile(dir, num=model)
         else:
             data = ms.mesa_profile(mass=mass, Z=Z, num=model)
         frame.set_state("mesa_w_data")
         frame.set_attributes("xaxis", options=sorted(data.cols.keys()))
         frame.set_attributes("yaxis", options=sorted(data.cols.keys()))
     else:
         nugrid_or_mesa = frame.get_attribute("select_nugrid_mesa", 'value')
         if nugrid_or_mesa == "NuGrid":
             frame.set_state("nugrid")
         elif nugrid_or_mesa == "Mesa":
             frame.set_state("mesa")
     
     frame.set_state_data("class_instance", data)
     frame.set_attributes("select_plot", selected_label="")
 def mass_Z_handler(name, value):
     if frame.get_attribute("contain_model_select", "visible"):
         mass = float(frame.get_attribute("mass", "value"))
         Z = float(frame.get_attribute("Z", "value"))
         dir = frame.get_attribute("address_bar", "value")
         if manual_data_select:
             mdir, mmodel = frame.get_state_data("model_data")
             if (mdir != dir) or (mmodel == None):
                 clear_output()
                 pre_data = ms.mesa_profile(dir)
                 frame.set_state_data("model_data", (dir, pre_data.model))
         else:
             mmass, mZ, mmodel = frame.get_state_data("model_data")
             if (mmass != mass) or (mZ != Z) or (mmodel == None):
                 clear_output()
                 pre_data = ms.mesa_profile(mass=mass, Z=Z)
                 frame.set_state_data("model_data",
                                      (mass, Z, pre_data.model))
Beispiel #7
0
profileN = [100, 1000, 1500, 2000, 2500]



fig = plt.figure(figsize=(8.267, 11.692))

# gridspec inside gridspec
gs = gridspec.GridSpec(5, 4, wspace=0.1, hspace=0.1)

for i in range(4):
	h=ms.history_data(model_paths[i])
	for j in range(5):
		ax = plt.subplot(gs[j,i])
		print i,j
		p=ms.mesa_profile(model_paths[i],profileN[j],num_type='nearest_model')
		mass = p.get('mass') * u.Msun # solar mass
		dm = copy.deepcopy(mass)
		dm[:-1] = mass[:-1]-mass[1:]

		r = p.get('radius') * u.Rsun# solar radius
		dr = copy.deepcopy(r)
		dr[:-1] = r[:-1]-r[1:]
		csound = p.get('csound') * u.cm/u.s #cm/s
		t_sc = dr/(csound)
		mdot_sc =  dm/t_sc
		t_ff = math.pi/2. * r**(3./2.) / np.sqrt(2.*const.G*(mass))
		mdot_ff = dm/t_ff

		plt.semilogy(mass.to('Msun').value,mdot_ff.to('Msun/yr').value,label="$local\ dm/dt_{free\ fall}$",linewidth=2)
		plt.semilogy(mass.to('Msun').value,mdot_sc.to('Msun/yr').value, label="$local\ dm/dt_{sound\ crossing}$",linewidth=2)
Beispiel #8
0
			break


## Find constants a_n, c_n and d_n
a_n = []
c_n = []
d_n = []
for i in range(7):
	a_n.append(1/(-3./t[Xi_1[i]] * theta_prime[i][Xi_1[i]]))
	c_n.append(9/(4*np.pi)*a_n[-1]**2/t[Xi_1[i]]/(N[i]+1))
	d_n.append(c_n[-1]*(4*np.pi)**(4./3)/a_n[-1]**(4./3)/3**(4./3))



## Load MESA data!
pro = ms.mesa_profile('mesa_zams/LOGS',750)

R = pro.get('logR')		# log10 R / Rsun
P = pro.get('logP')		# log10 P in cgs units of pressure dyne / cm2 = barye
Rho = pro.get('logRho')	# log10 Rho in cgs units g /cm3
T = pro.get('logT')		# log10 T in cgs units Kelvin

# Plot Pressure Profile
plot = True
if plot == True:
	fig,ax = mp.subplots()
	p1, = ax.plot(10**(R)/(10**R).max(),10**(P)/(10**P).max(),'b')
	ax.grid()
	ax.set_xlabel('Radius / Rsun',fontsize=15)
	ax.set_ylabel('Pressure / P_c',fontsize=15)
Beispiel #9
0
def mesa_profileplot(vars, lognum, type='', prefix='profile'):
    #from matplotlib.transforms import offset_copy
    """
    python routine to read and plot profile files
    vars:   a vector of names 
            var[0] is name of x variable
            var[1] is name of first y variable
            var[2] is name of second y variable, etc.
    """
    clf()
    Msun = 1.988e+33
    Rsun = 6.955e+10
    gconst = 6.67e-8
    xvar = vars[0]
    a1 = ms.mesa_profile('.', lognum, num_type='log_num', log_prefix=prefix)
    Teff0 = a1.header_attr.get('Teff')
    Mass = a1.header_attr.get('star_mass')
    Mh = a1.header_attr.get('star_mass_h1')
    Mhe = a1.header_attr.get('star_mass_he4')
    Mh = Mh / Mass
    Mhe = Mhe / Mass
    rad = a1.get('radius')
    radius = rad[0]
    logg = np.log10(gconst * Mass * Msun / (Rsun * radius)**2)
    lMh = round(np.log10(Mh), 3)
    lMhe = round(np.log10(Mhe), 3)
    Mass = round(Mass, 4)
    Teff = int(round(Teff0, 0))
    flab = r'$T_{\rm eff}$' + r'$={0} \, K,  \, M_\star/M_\odot={1},\,$'.format(
        Teff, Mass)
    #flab2=r'$\log \,M_{\rm H}/M_\star=' + '{0}$, '.format(lMh) + '$\, M_{\\rm He}=' + '{0}$'.format(lMhe)
    flab2 = r'$\log M_{\rm  H}/M_\star\,=' + '{0},\,$ '.format(lMh)
    flab3 = r'$\log M_{\rm He}/M_\star=' + '{0}$ '.format(lMhe)
    flab = flab + flab2 + flab3
    fig = figure(1, frameon=False)
    ax = fig.add_subplot(111)
    plt.text(0.50,
             1.06,
             flab,
             horizontalalignment='center',
             verticalalignment='center',
             transform=ax.transAxes,
             size='large')
    if xvar == 'phi':
        r = a1.get('radius')
        N2 = a1.get('brunt_N2')
        aN = np.sqrt(np.abs(N2))
        ndim = np.size(r)
        dr = 0 * r
        phi = 0 * r
        dr[1:ndim - 1] = r[1:ndim - 1] - r[2:ndim]
        dr[0] = 0.
        phi[0] = 0.
        for i in np.arange(1, ndim):
            phi[i] = phi[i - 1] + dr[i] * aN[i] / r[i]
        phi = phi / phi[ndim - 1]
        x = 1. - phi
    else:
        x = a1.get(xvar)
    n = np.size(vars)
    for i in np.arange(1, n):
        yvar = vars[i]
        y1 = a1.get(yvar)
        if type == 'sl':
            semilogy(x, y1)
            #semilogy(x,y1,'o')
        else:
            plot(x, y1)
    if n == 2:
        ylabel(yvar)
    else:
        leg = vars[1:]
        legend(leg, 'best', fancybox=True, shadow=False)
    x1, x2 = xlim()
    if xvar == 'logxq':
        x1 = -18
        xlim(0.5, -18)
        xlabel(r'$\log (1-M_r/M_\star)$', size='x-large')
    elif xvar == 'phi':
        xlim(-0.025, 1.025)
        xlabel(r'$\Phi$', size='xx-large')
    else:
        dx = x2 - x1
        x1s = x1 - 0.05 * dx
        x2s = x2 + 0.05 * dx
        xlim(x1s, x2s)
        xlabel(xvar)
    y1, y2 = ylim()
    dy = y2 - y1
    y1s = y1 - 0.05 * dy
    y2s = y2 + 0.05 * dy
    ylim(y1s, y2s)
Beispiel #10
0
mod_number_1 = model_number_1[index1]
st_age_1 = star_age_1[index1]

mod_number_2 = model_number_2[index2]
st_age_2 = star_age_2[index2]

st_age = np.concatenate((st_age_1, st_age_2), axis=0)

prof_1 = np.empty(
    (len(mod_number_1), 1), dtype=object
)  #error return without exception set avoided with dtype=object
for i in range(len(mod_number_1)):
    for path, dirs, files in os.walk(
            dir1):  #os.walk avoids [Errno21] Is a directory
        prof_1[i:, ] = ms.mesa_profile(dir1, mod_number_1[i])

prof_2 = np.empty(
    (len(mod_number_2), 1), dtype=object
)  #error return without exception set avoided with dtype=object
for i in range(len(mod_number_2)):
    for path, dirs, files in os.walk(
            dir2):  #os.walk avoids [Errno21] Is a directory
        prof_2[i:, ] = ms.mesa_profile(dir2, mod_number_2[i])

prof = np.concatenate(
    (prof_1, prof_2), axis=0
)[:, 0]  # Remove "dtype=object" from the final profiles to get the information

# Profile variables. Add as many as desired
Beispiel #11
0
    idx[i] = (prof_index[i][0][0:])
    idxa[i], idxb[i], idxc[i] = idx[i].split(
    )  # Take the elements from the string
    idxa[i] = float(idxa[i])  # Convert them to floating point numbers
    index[i] = np.where(model_number == idxa[i])[0][0]

mod_number = model_number[index]
st_age = star_age[index]

prof = np.empty(
    (len(mod_number), 1), dtype=object
)  #error return without exception set avoided with dtype=object
for i in range(len(mod_number)):
    for path, dirs, files in os.walk(
            direc):  #os.walk avoids [Errno21] Is a directory
        prof[i:, ] = ms.mesa_profile(direc, mod_number[i])

prof = prof[:,
            0]  # Remove "dtype=object" from the final profiles to get the information

# Profile variables. Add as many as desired

logxq = []
radius = []
logT = []
logRho = []
logP = []
lum = []
q = []
ye = []
def mesa_profileplot(vars,lognum,type='',prefix='profile'):
    #from matplotlib.transforms import offset_copy
    """
    python routine to read and plot profile files
    vars:   a vector of names 
            var[0] is name of x variable
            var[1] is name of first y variable
            var[2] is name of second y variable, etc.
    """
    clf()
    Msun=1.988e+33
    Rsun=6.955e+10
    gconst=6.67e-8
    xvar=vars[0]
    a1=ms.mesa_profile('.',lognum,num_type='log_num',log_prefix=prefix)
    Teff0= a1.header_attr.get('Teff')
    Mass= a1.header_attr.get('star_mass')
    Mh= a1.header_attr.get('star_mass_h1')
    Mhe= a1.header_attr.get('star_mass_he4')
    Mh=Mh/Mass
    Mhe=Mhe/Mass
    rad=a1.get('radius')
    radius=rad[0]
    logg = np.log10(gconst*Mass*Msun/(Rsun*radius)**2)
    lMh=round(np.log10(Mh),3)
    lMhe=round(np.log10(Mhe),3)
    Mass=round(Mass,4)
    Teff=int(round(Teff0,0))
    flab=r'$T_{\rm eff}$' + r'$={0} \, K,  \, M_\star/M_\odot={1},\,$'.format(Teff,Mass)
    #flab2=r'$\log \,M_{\rm H}/M_\star=' + '{0}$, '.format(lMh) + '$\, M_{\\rm He}=' + '{0}$'.format(lMhe)
    flab2=r'$\log M_{\rm  H}/M_\star\,=' + '{0},\,$ '.format(lMh) 
    flab3=r'$\log M_{\rm He}/M_\star=' + '{0}$ '.format(lMhe) 
    flab=flab+flab2+flab3
    fig=figure(1,frameon=False)
    ax = fig.add_subplot(111)
    plt.text(0.50, 1.06, flab, horizontalalignment='center', verticalalignment='center',transform = ax.transAxes,size='large')
    if xvar == 'phi':
        r  = a1.get('radius')
        N2  = a1.get('brunt_N2')
        aN = np.sqrt(np.abs(N2))
        ndim=np.size(r)
        dr = 0*r
        phi = 0*r
        dr[1:ndim-1]=r[1:ndim-1]-r[2:ndim]
        dr[0]=0.
        phi[0]=0.
        for i in np.arange(1,ndim):
            phi[i]=phi[i-1] + dr[i]*aN[i]/r[i]
        phi=phi/phi[ndim-1]
        x=1.-phi
    else:
        x  = a1.get(xvar)
    n=np.size(vars)
    for i in np.arange(1,n):
        yvar=vars[i]
        y1 = a1.get(yvar)
        if type == 'sl':
            semilogy(x,y1)
            #semilogy(x,y1,'o')
        else:
            plot(x,y1)
    if n==2:
        ylabel(yvar)
    else:
        leg=vars[1:]
        legend(leg,'best',fancybox=True,shadow=False)
    x1,x2=xlim()
    if xvar == 'logxq':
        x1=-18
        xlim(0.5,-18)
        xlabel(r'$\log (1-M_r/M_\star)$',size='x-large')
    elif xvar == 'phi':
        xlim(-0.025,1.025)
        xlabel(r'$\Phi$',size='xx-large')
    else:
        dx=x2-x1
        x1s=x1-0.05*dx
        x2s=x2+0.05*dx
        xlim(x1s,x2s)
        xlabel(xvar)
    y1,y2=ylim()
    dy=y2-y1
    y1s=y1-0.05*dy
    y2s=y2+0.05*dy
    ylim(y1s,y2s)
Beispiel #13
0
'''
Astro 252 Homework 2
Plotting MESA Profiles
10/3/2015
Nicholas Kern
'''


## Import Modules
import numpy as np
import pylab as mp
import mesa as ms
from matplotlib import rc



## Constants
from cgs_units import *




## Load MESA Data
## Load MESA data!
pro = ms.mesa_profile('mesa_zams2/LOGS',100)

R = pro.get('logR')		# log10 R / Rsun
P = pro.get('logP')		# log10 P in cgs units of pressure dyne / cm2 = barye
Rho = pro.get('logRho')	# log10 Rho in cgs units g /cm3
T = pro.get('logT')		# log10 T in cgs units Kelvin