forked from Sterncat/opticspy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jones.py
56 lines (41 loc) · 1.35 KB
/
jones.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""Simple Jones Vector class
see http://en.wikipedia.org/wiki/Jones_calculus
currently does not normalize the output
"""
from __future__ import division as __division__
import numpy as __np__
from numpy import pi as __pi__
def rotator(angle):
s = __np__.sin(angle)
c = __np__.cos(angle)
return __np__.matrix([[c,-s],[s,c]])
class Component(__np__.matrix):
def __new__(self,matrix):
return super(Component,self).__new__(self,matrix)
def rotate(self, angle):
return rotator(angle)*self*rotator(-angle)
def HalfWavePlate():
return Component([[1,0],[0,-1]])
def QuaterWavePlate():
return Component([[1,0],[0,1j]])
def Birefringence( w1, w2):
return Component([[__np__.exp(1j*w1),0],[0,__np__.exp(1j*w2)]])
def Hpol():
return __np__.matrix([[1],[0]])
def Vpol():
return __np__.matrix([[0],[1]])
def D1pol():
return __np__.matrix([[1],[1]])/__np__.sqrt(2)
def D2pol():
return __np__.matrix([[1],[-1]])/__np__.sqrt(2)
def C1pol():
return __np__.matrix([[1],[1j]])/__np__.sqrt(2)
def C2pol():
return __np__.matrix([[1],[-1j]])/__np__.sqrt(2)
def PolarizerH():
return Component(Hpol()*Hpol().T)
def PolarizerV():
return Component(Vpol()*Vpol().T)
if __name__ == "__main__":
#Usage example
print(QuaterWavePlate().rotate(__pi__/4)*HalfWavePlate().rotate(__pi__/8)*D1pol())