# Stromgren Sphere

Figure 4.2 from Chapter 4 of *Interstellar and Intergalactic Medium* by Ryden & Pogge, 2021, 
Cambridge University Press.


Plot the radius of a Stromgren sphere as a function of time scaled by the recombination time.


```python
%matplotlib inline

import math
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, LogLocator, NullFormatter

import warnings
warnings.filterwarnings('ignore',category=UserWarning, append=True)
warnings.filterwarnings('ignore',category=RuntimeWarning, append=True)
```

## Standard Plot Format

Setup the standard plotting format and make the plot. Fonts and resolution adopted follow CUP style.


```python
figName = 'Fig4_2' 

# 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}'
```

## Stromgren Sphere

The radius of a Stromgren sphere grows in time as a function
\begin{equation}
R(t) = R_{S}\left(1-e^{t/t_{rec}}\right)^{1/3}
\end{equation}

where $R_{S}$ is the Stromgren radius, $t_{rec}=1/n_e\alpha$ is the recombination time given electron 
density $n_e$ and recombination coefficient $\alpha$.

We perform the calculation for 0 to 4 recombination times.


```python
# do the calculation

ttrec = np.linspace(0.0,4.0,1001)
rrs = np.power((1.0-np.exp(-ttrec)),(1.0/3.0))

# plotting limits

xMin = -0.02 # t/t_rec
xMax = 4.0

yMin = 0.0 # R/R_S
yMax = 1.1

# make the plot

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')

plt.xlim(xMin,xMax)
ax.xaxis.set_major_locator(MultipleLocator(0.5))
plt.xlabel('$t/t_{rec}$',fontsize=axisFontSize)

plt.ylim(yMin,yMax)
ax.yaxis.set_major_locator(MultipleLocator(0.2))
plt.ylabel(r'$R/R_S$',fontsize=axisFontSize)

plt.plot(ttrec,rrs,lw=1.5,color='black',zorder=10)

# plot and create file

plt.plot()
plt.savefig(plotFile,bbox_inches='tight',facecolor='white')
```

042f42030d2e993b5acadc3e96af297c36dff11c
ipynb
Jupyter Notebook
Chapter4/Fig4_2_StromgrenSphere.ipynb
CambridgeUniversityPress/Interstellar-and-Intergalactic-Medium
6d19cd4a517126e0f4737ba0f338117098224d92
CC0-1.0 CC-BY-4.0
2021-04-20T07:26:10.000Z
2022-02-24T11:02:47.000Z
Chapter4/Fig4_2_StromgrenSphere.ipynb
CambridgeUniversityPress/Interstellar-and-Intergalactic-Medium
6d19cd4a517126e0f4737ba0f338117098224d92
CC0-1.0 CC-BY-4.0
Chapter4/Fig4_2_StromgrenSphere.ipynb
CambridgeUniversityPress/Interstellar-and-Intergalactic-Medium
6d19cd4a517126e0f4737ba0f338117098224d92
CC0-1.0 CC-BY-4.0
Qwen/Qwen-72B
1. YES
2. YES