10-Absorption (template)#

We start by importing the modules

  • Numpy – operations on arrays and matrixes (and pi)

  • Matplotlib pyplot – plotting library

  • Matplotlin patches – module that enables patches in plots

  • Astropy units – defined quantities with units. We also import the CDS conversions

import numpy as np

import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import matplotlib as mpl
%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 0x128508d60>

0. To execute: Below is a little function that created a gradiant of color between two curves, according to a certain function.#

def rect(ax,x,y,w,h,c):
    #ax = plt.gca()
    polygon = plt.Rectangle((x,y),w,h,color=c)
    ax.add_patch(polygon)

def rainbow_fill_between(ax, X, Y1, Y2, colors=None, 
                         cmap=mpl.colormaps["Reds"],**kwargs):
    plt.plot(X,Y1,lw=0)  # Plot so the axes scale correctly

    dx = X[1]-X[0]
    N  = X.size

    #Pad a float or int to same size as x
    if (type(Y2) is float or type(Y2) is int):
        Y2 = np.array([Y2]*N)

    #No colors -- specify linear
    if colors is None:
        colors = []
        for n in range(N):
            colors.append(cmap(n/float(N)))
    #Varying only in x
    elif len(colors.shape) == 1:
        colors = cmap((colors-colors.min())
                      /(colors.max()-colors.min()))
    #Varying only in x and y
    else:
        cnp = np.array(colors)
        colors = np.empty([colors.shape[0],colors.shape[1],4])
        for i in range(colors.shape[0]):
            for j in range(colors.shape[1]):
                colors[i,j,:] = cmap((cnp[i,j]-cnp[:,:].min())
                                    /(cnp[:,:].max()-cnp[:,:].min()))

    colors = np.array(colors)

    #Create the patch objects
    for (color,x,y1,y2) in zip(colors,X,Y1,Y2):
        rect(ax,x,y2,dx,y1-y2,color,**kwargs)

1. In class: Imagine an ray of light entering a slab of constant density and opacity.#

  • The lenght of the slab (\(d\)) is 4 length units.

  • The product of the opacity and the density give a fraction of \(\kappa\rho\) = 0.25 per unit of length.

a. Find and plot the intensity as the ray crosses the slab.#

TODO : Starting from the \(dI_\lambda\) equation, derive the equation for \(I(s)\) for a constant density and opacity. Show your work here. Add a curve of \(I(s)\) to the plot in the code below.

b. Find and plot the optical depth everywhere in the slab.#

TODO : Integrate the equation for \(d\tau\) to find \(\tau(s)\). Show your work here. Add a curve of \(\tau(s)\) to the plot in the code below.



Don't forget to add axis labels and legends to your plots
fig, ax = plt.subplots(1,1, figsize=(9,4))
ax.set_ylim(0, 1.2)
ax.set_xlim(-1,5)

# For the first graph, I want a patch with constant color
cmap = mpl.colormaps["Reds"]
rgba = cmap(0.5) # pick the color in the center of the color map
rec = mpatches.Rectangle( (0, 0), 4 , 1.2, fc=rgba) # Create a shaded rectangle
r = ax.add_patch(rec) # add the rectangle to the plot
t = ax.text(5.2, 0.5, 'Observer is here', style='italic',
        bbox={'facecolor':'red', 'pad':5})



#---------------------------------------
# a. Intensity




#---------------------------------------
# b. optical depth





#--------------------------
# For a legend, add label='text' to the ax.plot command
# for which you would like a legend entry, and uncomment
# the following line:
#ax.legend(loc=0)
../_images/5664de19a573894da8f44c8a94c54830fea1f04760ec01a7e4455bf8a4ebbe8c.png

TODO: Please write a small paragraph with an interpretation of the result obtained:

2. At home: Imagine now that the density in the slab changes such that:#

\[\rho(s) = \rho_o \left( 1- \frac{s}{d} \right),\]

where \(d\) is the length of the slab.

TODO:

a. Find an expression for \(I(s)\) if the density changed as above and if the opacity remains constant. Make your integral unit-less before integrating. Show your work here.

b. Analytically, find what the value of \(\rho_o \kappa\) has to be for the final intensity to be the same as that of #1. Show your work here

c. In the graph below, plot the intensity as a function of position.

d. Find an expression for the optical depth everywhere in the slab. Make your integral unit-less before integrating. Show your work here.

e. In the graph below, add a curve for \(\tau(s)\).

fig, ax = plt.subplots(1,1, figsize=(9,4))

ax.set_ylim(0, 1.2)
ax.set_xlim(-1,5)

# Create a patch with a gradient to illustrate
# the change in density
X=np.linspace(0,4,100)
Y1=np.copy(X)*0
Y2=np.copy(X)*0+4
g = 1.0-np.copy(X/4)
r = rainbow_fill_between(ax,X,Y1,Y2,colors=g)
t = ax.text(5.2, 0.5, 'Observer is here', style='italic',
        bbox={'facecolor':'red', 'pad':5})

#---------------------------------------
#---------------------------------------
# At home




#--------------------------
l = ax.legend(loc=0)
No artists with labels found to put in legend.  Note that artists whose label start with an underscore are ignored when legend() is called with no argument.
../_images/452ae20cbc0487da886c46b014258de54fbbb571a49e5daa59b1dbc4b4ce3acc.png

TODO: Please write a small paragraph with an interpretation of the result obtained:

3. Reading assignement: “what can we measure about stars” – part 4#

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 mass of a star.

TODO: Have a look at section 18.2 Measuring Stellar Masses of the Open Stack Astronomy online textbook, and write a short conceptual paragraph about how astronomer can determine the masses of stars.