-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanual_test_phase.py
127 lines (111 loc) · 4.59 KB
/
manual_test_phase.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Test of phase Module (Manual)
import numpy as np
import math as math
import data as data
import phase as phase
import matplotlib.pyplot as plt
import statistics
##########################################################
# Test Difference of identical phase # 1
##########################################################
# Generate data to be passed through phase
data_em_test_1 = data.EMdata()
x1 = np.linspace(0, 255, 256)
y1 = np.linspace(0, 255, 256)
mx1, my1 = np.meshgrid(x1, y1)
data_em_test_1.holo_1 = np.sin(mx1 * 2 * np.pi / 16)
data_em_test_1.holo_2_aligned = data_em_test_1.holo_1
data_em_test_1.holo_ref = data_em_test_1.holo_1
# Circle of radius 1 centered around coordinate (192, 128)
r1 = 1
center1 = (144, 128)
# Pass through phase
phase.phase(center1, r1, data_em_test_1)
# Display results
fig_test_1_2d = plt.figure()
fig_test_1_2d_ax1 = fig_test_1_2d.add_subplot(2, 2, 1)
fig_test_1_2d_ax2 = fig_test_1_2d.add_subplot(2, 2, 2)
fig_test_1_2d_ax3 = fig_test_1_2d.add_subplot(2, 2, 3)
fig_test_1_2d_ax4 = fig_test_1_2d.add_subplot(2, 2, 4)
fig_test_1_2d_ax1.imshow(data_em_test_1.phase_1)
fig_test_1_2d_ax2.imshow(data_em_test_1.phase_2)
fig_test_1_2d_ax3.imshow(data_em_test_1.phase_ref)
fig_test_1_2d_ax4.imshow(data_em_test_1.diff_2_1_not_cor)
fig_test_1_2d_ax1.set_title('Unwrap-1')
fig_test_1_2d_ax2.set_title('Unwrap-2')
fig_test_1_2d_ax3.set_title('Unwrap-Ref')
fig_test_1_2d_ax4.set_title('2-1-uncor')
fig_test_1_1d = plt.figure()
fig_test_1_1d_ax1 = fig_test_1_1d.add_subplot(2, 2, 1)
fig_test_1_1d_ax2 = fig_test_1_1d.add_subplot(2, 2, 2)
fig_test_1_1d_ax3 = fig_test_1_1d.add_subplot(2, 2, 3)
fig_test_1_1d_ax4 = fig_test_1_1d.add_subplot(2, 2, 4)
fig_test_1_1d_ax1.plot(data_em_test_1.diff_1_ref[128, :])
# fig_test_1_1d_ax1.set_ylim(-np.pi, np.pi)
fig_test_1_1d_ax2.plot(data_em_test_1.diff_2_ref[128, :])
# fig_test_1_1d_ax2.set_ylim(-np.pi, np.pi)
fig_test_1_1d_ax3.plot(data_em_test_1.diff_2_1_cor[128, :])
# fig_test_1_1d_ax3.set_ylim(-np.pi, np.pi)
fig_test_1_1d_ax4.plot(data_em_test_1.diff_2_1_not_cor[128, :])
# fig_test_1_1d_ax4.set_ylim(-np.pi, np.pi)
fig_test_1_1d_ax1.set_title('1-Ref')
fig_test_1_1d_ax2.set_title('2-Ref')
fig_test_1_1d_ax3.set_title('2-1-cor')
fig_test_1_1d_ax4.set_title('2-1-uncor')
plt.show()
##########################################################
# Test Difference of known phase images # 2
##########################################################
# Generate data to be passed through phase
data_em_test_2 = data.EMdata()
x2 = np.linspace(0, 255, 256)
y2 = np.linspace(0, 255, 256)
mx2, my2 = np.meshgrid(x2, y2)
a2 = 4
b2 = 4.5
data_em_test_2.holo_1 = np.sin(mx2 * 2 * np.pi / a2)
data_em_test_2.holo_2_aligned = np.sin(mx2 * 2 * np.pi / b2)
data_em_test_2.holo_ref = data_em_test_2.holo_1
# Circle of radius 1 centered around coordinate (192, 128)
r2 = 20
center2 = (192, 128)
# Pass through phase
phase.phase(center2, r2, data_em_test_2)
# Display results
fig_test_2_2d = plt.figure()
fig_test_2_2d_ax1 = fig_test_2_2d.add_subplot(2, 2, 1)
fig_test_2_2d_ax2 = fig_test_2_2d.add_subplot(2, 2, 2)
fig_test_2_2d_ax3 = fig_test_2_2d.add_subplot(2, 2, 3)
fig_test_2_2d_ax4 = fig_test_2_2d.add_subplot(2, 2, 4)
fig_test_2_2d_ax1.imshow(data_em_test_2.phase_1)
fig_test_2_2d_ax2.imshow(data_em_test_2.phase_2)
fig_test_2_2d_ax3.imshow(data_em_test_2.phase_ref)
fig_test_2_2d_ax4.imshow(data_em_test_2.diff_2_1_not_cor)
fig_test_2_2d_ax1.set_title('Unwrap-1')
fig_test_2_2d_ax2.set_title('Unwrap-2')
fig_test_2_2d_ax3.set_title('Unwrap-Ref')
fig_test_2_2d_ax4.set_title('2-1-uncor')
fig_test_2_1d = plt.figure()
fig_test_2_1d_ax1 = fig_test_2_1d.add_subplot(2, 2, 1)
fig_test_2_1d_ax2 = fig_test_2_1d.add_subplot(2, 2, 2)
fig_test_2_1d_ax3 = fig_test_2_1d.add_subplot(2, 2, 3)
fig_test_2_1d_ax4 = fig_test_2_1d.add_subplot(2, 2, 4)
fig_test_2_1d_ax1.plot(data_em_test_2.diff_1_ref[128, :])
# fig_test_1_1d_ax1.set_ylim(-np.pi, np.pi)
fig_test_2_1d_ax2.plot(data_em_test_2.diff_2_ref[128, :])
# fig_test_1_1d_ax2.set_ylim(-np.pi, np.pi)
fig_test_2_1d_ax3.plot(data_em_test_2.diff_2_1_cor[128, :])
# fig_test_1_1d_ax3.set_ylim(-np.pi, np.pi)
fig_test_2_1d_ax4.plot(data_em_test_2.diff_2_1_not_cor[128, :])
# fig_test_1_1d_ax4.set_ylim(-np.pi, np.pi)
fig_test_2_1d_ax1.set_title('1-Ref')
fig_test_2_1d_ax2.set_title('2-Ref')
fig_test_2_1d_ax3.set_title('2-1-cor')
fig_test_2_1d_ax4.set_title('2-1-uncor')
slope_th = (2 * np.pi / b2) - (2 * np.pi / a2)
slope_exp = (data_em_test_2.diff_2_1_not_cor[128, 253] - data_em_test_2.diff_2_1_not_cor[128, 2]) / 251
error_slope = abs(slope_th - slope_exp)
print('Theoretical slope ', slope_th)
print('Experimental slope ', slope_exp)
print('Slope error ', error_slope)
plt.show()