-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathzernike_lens_comparison.py
44 lines (34 loc) · 1015 Bytes
/
zernike_lens_comparison.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
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import holograms as hg
"""
NOTE THAT TO GET THIS TO RUN PROPERLY I HAD TO CHANGE THE LENS HOLOGRAM CODE
SO THAT IT DIDN'T MODULO THE HOLOGRAM BEFORE RETURNING IT. I'VE NOW REVERTED
THIS CHANGE.
"""
def linear(x,x0,m):
return (x-x0)*m
amps = np.linspace(-2,2,11)
diff_sums = []
l = hg.lenses.focal_plane_shift(4,265,251)
l = hg.apertures.circ(l,265,251,247)
for amp in amps:
z = hg.zernike(2,0,amp,265,251,247)
z = z - z[256,256]
z = hg.apertures.circ(z,265,251,247)
diff = l-z
diff_sums.append(diff.sum())
popt,pcov = curve_fit(linear,amps,diff_sums)
z = hg.zernike(2,0,popt[0],265,251,247)
z = z - z[256,256]
z = hg.apertures.circ(z,265,251,247)
plt.imshow(l%1,vmin=0,vmax=1)
plt.show()
plt.imshow(z%1,vmin=0,vmax=1)
plt.show()
plt.scatter(amps,diff_sums)
plt.plot(amps,linear(amps,*popt),c='C1')
plt.xlabel('Zernike amplitude')
plt.ylabel('sum(lens-Zernike)')
print(popt[0])