2 from __future__
import division
3 from numpy
import sqrt
, cos
, sin
, arctan
, exp
, abs, pi
, conj
4 from scipy
import array
, dot
, sum
7 """ A Jones vector class to represent polarized EM waves """
8 def __init__(self
,Jarray
=array([1,0])):
13 """ Jones vector size """
14 return sqrt(dot(self
.toArray().conj(),self
.toArray()).real
)
17 """ Normalized Jones vector """
22 raise Exception('Zero-sized Jones vector cannot be normalized')
25 except Exception as inst
:
31 """ Convert into array format """
32 return array([self
.Jx
, self
.Jy
])
35 """ Rotated Jones vector
38 phi - rotation angle in radians (clockwise is positive)
40 R
= array([[cos(phi
), sin(phi
)], \
41 [-sin(phi
), cos(phi
)]])
42 return JonesVector(dot(R
, self
.toArray()))
44 def waveplate(self
,G
):
45 """ Waveplate with arbitrary retardance
46 Slow axis (or "c axis") is along X
49 G - retartandance in phase units
50 (e.g. one wavelength retardance is G = 2 * pi)
52 W0
= array([[exp(-1j
*G
/2), 0], \
54 return JonesVector(dot(W0
, self
.toArray()))
56 def waveplateRot(self
,phi
,G
):
57 """ Waveplate matrix with arbitrary rotation
60 phi - rotation angle in radians
61 (clockwise is positive)
62 G - retardance in phase units
63 (e.g. one wavelength retardance is G = 2 * pi)
65 return self
.rotate(phi
).waveplate(G
).rotate(-phi
)
68 """ Polarizer matrix """
69 P
= array([[cos(phi
)**2, cos(phi
)*sin(phi
)], \
70 [sin(phi
)*cos(phi
), sin(phi
)**2]])
71 return JonesVector(dot(P
, self
.toArray()))
73 def mirrormetal(self
,n
,k
,th
):
74 """ Reflection off a metal mirror
75 Incoming and reflected beams are assumed to be in the X plane
78 W0
= array([[dr
[3]*exp(-1j
*dr
[1]), 0],\
79 [0, dr
[2]*exp(-1j
*dr
[0])]])
80 return JonesVector(dot(W0
, self
.toArray()))
83 """ Intensity from electric field vector """
84 return real(self
.Jx
)**2 + real(self
.Jy
)**2
88 """ Calculate phase shift and reflectance of a metal in the s and p directions"""
89 u
= sqrt(0.5 *((n
**2 - k
**2 - sin(th
)**2) + sqrt( (n
**2 - k
**2 - sin(th
)**2)**2 + 4*n
**2*k
**2 )))
90 v
= sqrt(0.5*(-(n
**2 - k
**2 - sin(th
)**2) + sqrt( (n
**2 - k
**2 - sin(th
)**2)**2 + 4*n
**2*k
**2 )))
91 ds
= arctan(2*v
*cos(th
)/(u
**2+v
**2-cos(th
)**2));
92 dp
= arctan(2*v
*cos(th
)*(n
**2-k
**2-2*u
**2)/(u
**2+v
**2-(n
**2+k
**2)**2*cos(th
)**2));
95 rs
= abs((cos(th
) - (u
+v
*1j
))/(cos(th
) + (u
+v
*1j
)))
96 rp
= abs(((n
**2 + k
**2)*cos(th
) - (u
+v
*1j
))/((n
**2 + k
**2)*cos(th
) + (u
+v
*1j
)));
97 return array([ds
, dp
, rs
, rp
])