06-MeanMolecularWeight (template)#
We start by importing the modules
Numpy – operations on arrays and matrixes (and pi)
Matplotlib pyplot – plotting library
Astropy units – defined quantities with units. We also import the CDS conversions
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from astropy import constants as const
import astropy.units as u
from astropy.units import cds
cds.enable()
<astropy.units.core._UnitContext at 0x10815a760>
1. In class: Solar abundances#
In the 05-Grevesse.txt file, you will find a tabulation of the solar abundances for the first 30 elements that looks like this:
# Abundance from Grevesse Z A Element NumberFraction logAbund X 1 1.0079 H 1.00E+00 1.20E+01 7.04E-01 2 4.0026 He 1.00E-01 1.10E+01 2.80E-01 3 6.941 Li 1.26E-11 1.10E+00 6.10E-11 4 9.0122 Be 2.51E-11 1.40E+00 1.58E-10 ....
a. We will first learn how to read in a data file, using a Numpy function#
dtype="i8,f8,|U8,f8,f8,f8"
# If using "S8" for the element string,
# numpy will use bytestring, which need to be decoded
# before using in mathplotlib -- using U8 here instead
url = 'https://raw.githubusercontent.com/veropetit/PHYS633-F2024/main/Book/L06-MeanMolecularWeight/06-Grevesse.txt'
#---------------------------------------
#---------------------------------------
# In class
# How to read a data file
[('Z', '<i8'), ('A', '<f8'), ('Element', '<U8'), ('NumberFraction', '<f8'), ('logAbund', '<f8'), ('X', '<f8')]
b. Now let’s see what the abundance pattern looks like#
fig, ax = plt.subplots(1,1, figsize=(10,4))
ax.set_ylim(0,0.01)
#---------------------------------------
#---------------------------------------
# In class
# We can set the labels in the plots to the name of the elements!
(0.0, 0.01)

TODO: Please write a small paragraph with an interpretation of the result obtained:
2. In class: what is the mean molecular weight for solar abundance?#
Let’s calculate the value for the mean molecular weight using the \(X_i\) in our abundance table.
We found that:
with
and
Let’s consider two cases:
a. The gas is completely neutral#
TODO: write a few words about how the equations above can be simplified for a completely neutral gas
b. The gas is completely ionized#
TODO: write a few words about how the equations above can be simplified for a completely ionized gas
#---------------------------------------
#---------------------------------------
# In class
TODO: Please write a small paragraph with an interpretation of the result obtained:
3. At home: What will \(\mu\) be at the center of the Sun once all the H is converted into He?#
TODO: Make a calulation of the mean molecular weight in the core of the Sun, once all of the hydrogen has been converted into helium (remember, at the surface of the Sun where there is no nuclear reactions: \(X\)=70%, \(Y\)=28%, and \(Z\)=2%)
You can use the approximations I gave in the last slide of the PDF class notes
You can use the code cell below as a calculator, or you can do the calculation by hand.
#---------------------------------------
#---------------------------------------
# At home
TODO: Please write a small paragraph with an interpretation of the result obtained:
4. At home: Finally, let’s check what the mean molecular weight looks like inside of the sun#
a. Let’s use the MESA model to look at \(\mu\) as a function of radius inside of the Sun.#
TODO: Based on the MESA model for the Sun, I provide an array
mu
that contains the mean molecular weigth. Create a plot of the mean molecular weight as a function of \(r/R_\star\). The corresponding array for the \(r/R_\star\) is calledr_rs
b. In the interpretation, explain the shape of the curve#
You might find it interesting to look at the variation of the temperature data['logT']
to help you with your interpretation – you might find it enlightening!
def read_model(file):
# Here's a function that reads it the MESA model.
cols = np.array([1,2,3,4,5,9,29,66])-1
return np.genfromtxt(file, skip_header=5, names=True, usecols = cols)
# Reading the model
data = read_model('https://raw.githubusercontent.com/veropetit/PHYS633-F2024/main/Book/L06-MeanMolecularWeight/06-MESAdatafile.txt')
# Calculating mu using the density (in cgs), the temperature (in K) and the gas pressure
mu = 10**data['logRho'] * u.g / u.cm**3 * const.k_B * 10**data['logT'] * u.K / (10**data['logPgas']*u.Ba) / const.u
mu = mu.decompose() # Should be unitless.
r_rs = 10**(data['logR']-data['logR'][0])
#---------------------------------------
#---------------------------------------
# At home
TODO: Please write a small paragraph with an interpretation of the result obtained:
5. Reading assignement: “what can we measure about stars” – part 3#
In this graduate course, we are making an advanced physical and mathematical model of star.
But it is still good to learn and/or remind ourselves about which physical characteristics of stars we can actually measure. You might have covered some of this in some details in previous physics or astro courses (at UD PHYS 133, 144, 333, or 469) – but it is still a good idea to have a quick look at the suggested reading below before crafting your paragraph.
One other thing that can be measured is the composition of a star’s surface.
TODO: Have a look at section 5.3 Spectroscopy in Astronomy, 5.4 The Structure of the Atom and/or 5.5 Formation of Spectral Lines of the Open Stack Astronomy online textbook, and write a short conceptual paragraph about how astronomer can determine the composition of stars through spectra.