#
# Beam_Profile_Exercise_2.py
#
# This file will generate a filled contour plot of
# the irradiance I(x,y) of the TEM00 Gaussian Mode of a laser
# versus x and y.
#
# This file will also generate a filled contour plot of
# the scaled irradiance I(x,y)/I_max of the TEM00 Gaussian Mode of a laser
# versus scaled x and scaled y.
#
# Written by:
#
# Ernest R. Behringer
# Department of Physics and Astronomy
# Eastern Michigan University
# Ypsilanti, MI 48197
# (734) 487-8799
# ebehringe@emich.edu
#
# with contributions from graduate student
#
# Najwa Sulaiman
# Department of Physics and Astronomy
# Eastern Michigan University
# Ypsilanti, MI 48197
# nsulaima@emich.edu
#
# 20160529 ERB
#
from pylab import xlim,xlabel,ylim,ylabel,show,contourf,colorbar,figure,title
from matplotlib.colors import LinearSegmentedColormap
from numpy import linspace,meshgrid,exp,sqrt,pi,amax
# Define the colormaps for these contour plots.
# For a HeNe laser beam profile, we might want red to be bright
# and black to be dark. This is the color map labeled
# black_red1.
#
# If instead we want white to be dark,
# then we use the color map labeled white_red1.
#
# The first digit in each 3-tuple is the scaled intensity
# (0 for lowest value, 1 for highest value).
# The second two digits are identical and represent the
# R-, G-, or B-value at that scaled intensity. Here,the
# R-value increases linearly with intensity while the
# G- and B-values are always zero.
cdict1 = {'red': ((0.0, 0.0, 0.0),
(1.0, 1.0, 1.0)),
'green': ((0.0, 0.0, 0.0),
(1.0, 0.0, 0.0)),
'blue': ((0.0, 0.0, 0.0),
(1.0, 0.0, 0.0))}
black_red1 = LinearSegmentedColormap('Black_Red1',cdict1)
#
cdict2 = {'red': ((0.0, 1.0, 1.0),
(1.0, 1.0, 1.0)),
'green': ((0.0, 1.0, 1.0),
(1.0, 0.0, 0.0)),
'blue': ((0.0, 1.0, 1.0),
(1.0, 0.0, 0.0))}
white_red1 = LinearSegmentedColormap('White_Red1',cdict2)
#x and y array values to be used later
max_x = 2.0 # maximum value of x position [mm]
min_x = -2.0 # minimum value of x position [mm]
max_y = max_x # maximum value of y position [mm]
min_y = min_x # minimum value of y position [mm]
Npts = 81
x = linspace(min_x,max_x,Npts) #x data point array
y = linspace(min_y,max_y,Npts) #y data point array
# create mesh of points on which irradiance is evaluated
X, Y = meshgrid(x,y)
# Now scale the x and y values by the beam width w0
w0 = 0.5 # beam width w0 [mm]
scaled_x = x/w0
scaled_y = y/w0
#creating grid table for function to be set on
Xsc, Ysc = meshgrid(scaled_x,scaled_y)
# other inputs
P_0 = 1.00 # laser power [mW]
I_0 = 2.00*P_0/(pi*w0*w0) # maximum irradiance [mW/mm2]
I = I_0 * exp(-2.0*(X*X + Y*Y))
# define the scaled irradiance
Imax = amax(I)
Isc = I/Imax
# Generate the contour plot of irradiance
# versus x and y with black as dark and red as bright
figure()
# Use the colormap black_red1
contourf(X,Y,I,100,cmap=black_red1)
# Define the limits of the horizontal axis
xlim(min_x,max_x)
# Label the horizontal axis, with units
xlabel("$x$ [mm]", size = 16)
# Define the limits of the vertical axis
ylim(min_y,max_y)
# Label the vertical axis, with units
ylabel("$y$ [mm]", size = 16)
# Plot title
title('$w_0 = $%s mm, $P_0 = $%s mW'%(w0,P_0))
# Show the colorbar
colorbar(label='Irradiance [mW/mm$^2$]')
show()
# Generate the contour plot of scaled irradiance
# versus scaled x and scaled y with black as dark and red as bright
figure()
# Use the colormap black_red1
contourf(Xsc,Ysc,Isc,100,cmap=black_red1)
# Define the limits of the horizontal axis
xlim(min_x,max_x)
# Label the horizontal axis, with units
xlabel("$\\tilde{x}\equiv x/w_0$", size = 16)
# Define the limits of the vertical axis
ylim(min_y,max_y)
# Label the vertical axis, with units
ylabel("$\\tilde{y}\equiv y/w_0$", size = 16)
# Plot title
title('$w_0 = $%s mm, $P_0 = $%s mW'%(w0,P_0))
# Show the colorbar
colorbar(label='Scaled irradiance')
show()