<jupyter_start><jupyter_text>Extinction Efficiency FactorFigure 6.5 from Chapter 6 of *Interstellar and Intergalactic Medium* by <NAME>, 2021, Cambridge University Press.Plot the efficiency factor Q$_{ext}$ for two values of the real index of refraction, $n_r=1.5$ (glass) and $n_r=1.33$ (water ice).Uses van de Hulst's method to compute Mie scattering in the astrophysically interesting limit that thespherical scatterer is large compared to the wavelength of light ($2\pi a >> \lambda$) and only moderatelyrefractive and absorptive at wavelengths of interest ($|n-1|<1$).  In this limit, the solution for the purescattering case yeilds an efficiency factor\begin{equation}   Q_{ext} = Q_{sca}\approx 2-\frac{4}{\varrho}\sin\varrho + \frac{4}{\varrho^2}(1-\cos\varrho)\end{equation}where\begin{equation}   \varrho = 2\left(\frac{2\pi a}{\lambda}\right)|n_r-1|\end{equation}in the short-wavelength limit this function approaches the limiting value of $Q_{ext}=2.0$.<jupyter_code>%matplotlib inline

import os
import sys
import math
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, LogLocator, NullFormatter

import warnings
warnings.filterwarnings('ignore',category=UserWarning, append=True)<jupyter_output><empty_output><jupyter_text>Standard Plot FormatSetup the standard plotting format and make the plot. Fonts and resolution adopted follow CUP style.<jupyter_code>figName = 'Fig6_5' 

# graphic aspect ratio = width/height

aspect = 4.0/3.0 # 4:3

# Text width in inches - don't change, this is defined by the print layout

textWidth = 6.0 # inches

# output format and resolution

figFmt = 'png'
dpi = 600

# Graphic dimensions 

plotWidth = dpi*textWidth
plotHeight = plotWidth/aspect
axisFontSize = 10
labelFontSize = 6
lwidth = 0.5
axisPad = 5
wInches = textWidth 
hInches = wInches/aspect

# Plot filename

plotFile = f'{figName}.{figFmt}'

# LaTeX is used throughout for markup of symbols, Times-Roman serif font

plt.rc('text', usetex=True)
plt.rc('font', **{'family':'serif','serif':['Times-Roman'],'weight':'bold','size':'16'})

# Font and line weight defaults for axes

matplotlib.rc('axes',linewidth=lwidth)
matplotlib.rcParams.update({'font.size':axisFontSize})

# axis and label padding

plt.rcParams['xtick.major.pad'] = f'{axisPad}'
plt.rcParams['ytick.major.pad'] = f'{axisPad}'
plt.rcParams['axes.labelpad'] = f'{axisPad}'<jupyter_output><empty_output><jupyter_text>Scattering Efficiency FactorDo the computation for real two indices of refraction * $n_r=1.5$ - typical of glass (fused silica) at visible wavelengths * $n_r=1.33$ - typical of pure water ice at visible wavelenths parameterize using $x=2\pi a/\lambda$.<jupyter_code># Range of x

xMin = 0.01
xMax = 14.0
x = np.linspace(xMin,xMax,501)

yMin = 0.0
yMax = 4.0

# glass (fused silica)

nr = 1.5
rho = 2.0*x*(nr-1.0)
Qext1 = 2.0 - (4.0/rho)*np.sin(rho)+(4.0/(rho*rho))*(1-np.cos(rho))

# pure water ice 

nr = 1.33
rho = 2.0*x*(nr-1.0)
Qext2 = 2.0 - (4.0/rho)*np.sin(rho)+(4.0/(rho*rho))*(1-np.cos(rho))<jupyter_output><empty_output><jupyter_text>Make the plotPlot $n_r$=1.5 (glass) as a solid line, $n_r$=1.33 (ice) as a dotted line, with $Q_{ext}$=2.0 for reference(see text).<jupyter_code>fig,ax = plt.subplots()

fig.set_dpi(dpi)
fig.set_size_inches(wInches,hInches,forward=True)

ax.tick_params('both',length=6,width=lwidth,which='major',direction='in',top='on',right='on')
ax.tick_params('both',length=3,width=lwidth,which='minor',direction='in',top='on',right='on')

# Limits

plt.xlim(xMin,xMax)
ax.xaxis.set_major_locator(MultipleLocator(2))
ax.xaxis.set_minor_locator(MultipleLocator(1))
plt.xlabel(r'$x=2\pi a/\lambda$',fontsize=axisFontSize)

plt.ylim(yMin,yMax)
ax.yaxis.set_major_locator(MultipleLocator(1))
ax.yaxis.set_minor_locator(MultipleLocator(0.5))
plt.ylabel(r'Q$_{\rm ext}$',fontsize=axisFontSize)

# glass (nr=1.5)

plt.plot(x,Qext1,'-',color='black',lw=1.0,zorder=10)
plt.text(4.0,3.2,r'$n_{r}$=1.5',fontsize=axisFontSize,ha='right',color='black')

# ice (nr=1.33)

plt.plot(x,Qext2,':',color='black',lw=1.0,zorder=10)
plt.text(7.5,3.0,r'$n_{r}$=1.33',fontsize=axisFontSize,ha='left',color='black')

# large x asymptote at Qext=2

plt.hlines(2.0,xMin,xMax,ls='--',color='black',lw=0.5,zorder=8)

plt.plot()
plt.savefig(plotFile,bbox_inches='tight',facecolor='white')<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup