import python_hwp_model
import numpy as nm
import pylab

# this code remakes Figure 8.1 in Sean Bryan's thesis about half-wave plates
# http://arxiv.org/pdf/1402.2591v1.pdf

# calculate HWP mueller matrix elements for nominal thicknesses of everything
freq,T,rho,c,s,R,tau,h,q = python_hwp_model.calculate_hwp_mueller_matrix(use_preset_thickness_and_index='150GHz', \
                                                                         cooled=True, \
                                                                         freq=nm.arange(0.0,300.0,0.1))

# calculate for an ideal retarder designed for 150 GHz
T_ideal = nm.ones_like(freq)
rho_ideal = nm.zeros_like(freq)
c_ideal = nm.cos(nm.pi*(freq/150.0))
s_ideal = nm.sin(nm.pi*(freq/150.0))

# plot the mueller matrix elements
pylab.figure(1,figsize=(9,6))
pylab.clf()
pylab.subplot(2,2,1)
pylab.plot(freq,T,'b',label='Sapphire Slab + AR')
pylab.plot(freq,T_ideal,'--r',label='Ideal Retarder')
pylab.ylim((-1.05,1.05))
pylab.xlabel('Frequency [GHz]')
pylab.title('T')
pylab.fill([130.0,160.0,160.0,130.0], [-1.05,-1.05,1.05,1.05], 'k', alpha=0.2, edgecolor='k',label='Spider 150 GHz Band')
pylab.legend(loc='lower right')

pylab.subplot(2,2,2)
import python_hwp_model
import numpy as nm

# this code calculates and displays the band-averaged HWP mueller matrix elements
# while varying the thickness of one of the AR coat layers
# leaving the other thickness unchanged

# calculate HWP mueller matrix elements for nominal thicknesses of everything
freq,T,rho,c,s,R,tau,h,q = python_hwp_model.calculate_hwp_mueller_matrix(use_preset_thickness_and_index=False, \
                                                     freq=nm.linspace(85,105,2100), \
                                                     n_ar=1.951, \
                          d_ar_near=0.427, \
                          d_ar_far=0.427, \
                          n_gap=1.0, \
                          d_gap_near=0.000, \
                          d_gap_far=0.000, \
                          d_hwp=4.930, \
                          n_s=3.336, \
                          n_f=3.019)

# print the band-averaged mueller matrix elements (from 85 GHz to 105 GHz)
print 'Nominal AR Coat Thicknesses (both are 427 microns):'
print '(Agrees with top row of Table 8.2 in my thesis astro-ph/1402.2591)'
print 'T   = ' + str(nm.mean(T))
print 'rho = ' + str(nm.mean(rho))
print 'c   = ' + str(nm.mean(c))
print 's   = ' + str(nm.mean(s))
print ' '
print 'Reflection = ' + str(nm.mean(R))
print ' '
print ' '
import python_hwp_model
import numpy as nm
import pylab

# this code remakes Figure 8.1 in Sean Bryan's thesis about half-wave plates
# http://arxiv.org/pdf/1402.2591v1.pdf

# calculate HWP mueller matrix elements for nominal thicknesses of everything
freq,T,rho,c,s,R,tau,h,q = python_hwp_model.calculate_hwp_mueller_matrix(use_preset_thickness_and_index='150GHz', \
                                                                         cooled=True, \
                                                                         freq=nm.arange(0.0,300.0,0.1))

# calculate for an ideal retarder designed for 150 GHz
T_ideal = nm.ones_like(freq)
rho_ideal = nm.zeros_like(freq)
c_ideal = nm.cos(nm.pi * (freq / 150.0))
s_ideal = nm.sin(nm.pi * (freq / 150.0))

# plot the mueller matrix elements
pylab.figure(1, figsize=(9, 6))
pylab.clf()
pylab.subplot(2, 2, 1)
pylab.plot(freq, T, 'b', label='Sapphire Slab + AR')
pylab.plot(freq, T_ideal, '--r', label='Ideal Retarder')
pylab.ylim((-1.05, 1.05))
pylab.xlabel('Frequency [GHz]')
pylab.title('T')
pylab.fill([130.0, 160.0, 160.0, 130.0], [-1.05, -1.05, 1.05, 1.05],
           'k',
           alpha=0.2,
           edgecolor='k',
import python_hwp_model
import numpy as nm

# this code calculates and displays the band-averaged HWP mueller matrix elements
# while varying the thickness of one of the AR coat layers
# leaving the other thickness unchanged

# calculate HWP mueller matrix elements for nominal thicknesses of everything
freq,T,rho,c,s,R,tau,h,q = python_hwp_model.calculate_hwp_mueller_matrix(use_preset_thickness_and_index=False, \
	                                                    freq=nm.linspace(85,105,2100), \
	                                                    n_ar=1.951, \
                										d_ar_near=0.427, \
                										d_ar_far=0.427, \
                										n_gap=1.0, \
                										d_gap_near=0.000, \
                										d_gap_far=0.000, \
                										d_hwp=4.930, \
                										n_s=3.336, \
                										n_f=3.019)

# print the band-averaged mueller matrix elements (from 85 GHz to 105 GHz)
print 'Nominal AR Coat Thicknesses (both are 427 microns):'
print '(Agrees with top row of Table 8.2 in my thesis astro-ph/1402.2591)'
print 'T   = ' + str(nm.mean(T))
print 'rho = ' + str(nm.mean(rho))
print 'c   = ' + str(nm.mean(c))
print 's   = ' + str(nm.mean(s))
print ' '
print 'Reflection = ' + str(nm.mean(R))
print ' '
print ' '