#

# Rainbows_Exercise_1.py

#

# Plot separately the refractive indices of

# water and air, based on peer-reviewed literature

#

# The refractive index of water is taken from

# Eq. 3 of P.D.T Huibers, Applied Optics,

# Vol. 36, No. 16, pp. 3785-3787 (1997).

#

# The refractive index of air is taken from

# Eq. 1 of P.E. Ciddor, Applied Optics,

# Vol. 35, No. 9, pp. 1566-1573 (1996).

#

# Written by:

#

# Ernest R. Behringer

# Department of Physics and Astronomy

# Eastern Michigan University

# Ypsilanti, MI 48197

# (734) 487-8799

# ebehringe@emich.edu

#

# 20160109 by ERB add plots of index versus wavelength

#

from pylab import figure,plot,xlim,xlabel,ylim,ylabel,grid,title,show

from numpy import linspace

# Define the index of refraction function for water

def water_index(wavelength):

n_H2O = 1.31279 + 15.762/wavelength - 4382.0/(wavelength**2) + 1.1455e6/(wavelength**3)

return(n_H2O)

# Define the index of refraction function for air

# Note: wavelength is supposed to be in micrometers

def air_index_minus_one(wavelength):

term1 = 0.05792105/(238.0185 - 1.0e6/(wavelength**2))

term2 = 0.00167917/(57.362 - 1.0e6/(wavelength**2))

return(term1+term2)

# Inputs

lambda_lo = 400.0 # low value of the wavelength [nm]

lambda_hi = 700.0 # high value of the wavelength [nm]

npts = 301 # number of points for the array of wavelengths

# Generate the array of wavelengths

wavelengths = linspace(lambda_lo,lambda_hi,npts)

# Calculate the refractive indices

n_water = water_index(wavelengths)

n_air = 1.0 + air_index_minus_one(wavelengths)

#----------------------------------------------------------------------

# Start a new figure. This will be a plot of

# refractive index of water versus wavelength.

figure()

# Set the limits of the horizontal axis

xlim(lambda_lo,lambda_hi)

# Label the horizontal axis

xlabel("$\\lambda$ [nm]", size = 16)

# Set the limits of the vertical axis

ylim(1.325,1.345)

# Label the vertical axis

ylabel("$n_{water}$", size = 16)

# Draw a grid

grid(True)

# Make the title

title("$n_{water}$ versus wavelength $\\lambda$\n Appl. Opt. Vol. 36, Pg. 3785 (1997)")

# Plot the refractive index of water versus wavelength

plot(wavelengths,n_water,"m-")

show()

#----------------------------------------------------------------------

# Start a new figure. This will be a plot of

# refractive index of air versus wavelength.

figure()

# Set the limits of the horizontal axis

xlim(lambda_lo,lambda_hi)

# Label the horizontal axis

xlabel("$\\lambda$ [nm]", size = 16)

# Set the limits of the vertical axis

ylim(2.75e-4,2.85e-4)

# Label the vertical axis

ylabel("$n_{air} - 1$", size = 16)

# Draw a grid

grid(True)

# Make the title

title("$n_{air} - 1$ versus wavelength $\lambda$\n Appl. Opt. Vol. 35, Pg. 1566 (1996)")

# Plot the refractive index of air minus one

plot(wavelengths,air_index_minus_one(wavelengths),"m-")

show()