# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Index of Refraction of Silicon
#
# Figure 6.4 from Chapter 6 of *Interstellar and Intergalactic Medium* by <NAME>, 2021, 
# Cambridge University Press.
#
# Plot of the real and imaginary components of the index of refraction of silicon at T=300 K.
# Data are from [Green 2008, Solar Energy Materials and Solar Cells, 92, 1305](https://www.sciencedirect.com/science/article/pii/S0927024808002158), Table 1 (doi: 10.1016/j.solmat.2008.06.009)
#

# +
# %matplotlib inline

import os
import sys
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)
# -

# ## Standard Plot Format
#
# Setup the standard plotting format and make the plot. Fonts and resolution adopted follow CUP style.
#

# +
figName = 'Fig6_4'

# 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 = 8
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}'

# -

# ## Silicon index of refraction
#
# Data from Green 1980...
#
# Data are multicolumn ASCII text with # comments and a data header.  We use
#  * lamr - wavelength in $\mu$m for n$_r$
#  * nr - real part of the index of refraction (n$_r$)
#  * lami - wavelength in $\mu$m for n$_i$
#  * ni - imaginary part of the index of refraction (n$_i$)
#

# +
dataFile = 'Green2008_Si300K.txt'

# data file has a text header, colhead1  colhead2 ... colheadN

data = pd.read_csv(dataFile,sep=r'\s+',comment='#')

lamr = np.array(data['lamr'])
nr = np.array(data['nr'])

lami = np.array(data['lami'])
ni = np.array(data['ni'])

# -

# ## Plot the refraction index
#
# Real part as a solid line, imaginary part as a dotted line, labeled.

# +
xMin = 0.2 # microns
xMax = 1.45
yMin = -0.01
yMax = 7.5

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(0.2))
ax.xaxis.set_minor_locator(MultipleLocator(0.1))
plt.xlabel(r'$\lambda$ [$\mu$m]',fontsize=axisFontSize)

plt.ylim(yMin,yMax)
ax.yaxis.set_major_locator(MultipleLocator(1))
ax.yaxis.set_minor_locator(MultipleLocator(0.5))
plt.ylabel(r'Index of refraction',fontsize=axisFontSize)

# Real part

plt.plot(lamr,nr,'-',color='black',lw=1.2,zorder=10)
plt.text(0.41,6.0,r'Real ($n_{\rm r}$)',fontsize=labelFontSize,ha='left',color='black')

# imaginary part

plt.plot(lami,ni,':',color='black',lw=1.2,zorder=10)
plt.text(0.38,2.5,r'Imaginary ($n_{\rm i}$)',fontsize=labelFontSize,ha='left',color='black')

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

StarcoderdataJupyterScriptsDedupFiltered