-
Notifications
You must be signed in to change notification settings - Fork 1
/
testSimulate.py
86 lines (69 loc) · 1.99 KB
/
testSimulate.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
import numpy as np
import time
import matplotlib.pyplot as plt
import T as T
import N as N
from math import sqrt, cos, floor, pi as π
import random
def Generate(X, Y, Z, λ, img):
L = 100
for x in range(X-L, X+L):
for y in range(Y-L, Y+L):
r = sqrt((x-X)**2 + (y-Y)**2 + Z**2)
n = (r-Z)/λ
ϕ = 2*π*(n - floor(n) - 0.5)
img[y][x] = 5e5 * cos(ϕ/2) * Z**2 / (r**4)
#img[y][x] = floor(5e5 * cos(ϕ/2) * Z**2 / (r**4) * random.uniform(1, 1.1))
shape = (700, 756)
imgc = []
for i in range(20):
img = np.ndarray(shape)
Generate(50, 50, 50 + i, 4, img)
imgc.append(img)
img = np.ndarray(shape)
Generate(50, 50, 60, 4, img)
maxn = 20
loopRange = range(1, maxn)
if (True):
ts = []
for loop in loopRange:
beads = []
for i in range(loop):
beads.append(T.Bead(50, 50))
T.XY(beads, [img])
for i in range(20):
T.Calibrate(beads, [imgc[i]], i)
T.ComputeCalibration(beads)
print(loop, beads[0])
start = time.time()
for i in range(100):
T.XYZ(beads, [img])
ts.append(time.time() - start)
print(ts)
plt.plot(loopRange, np.array(ts), marker="o", label="Taichi")
print(np.polynomial.polynomial.polyfit(loopRange[1:], ts[1:], 1))
if (True):
ts = []
for loop in loopRange:
beads = []
for i in range(loop):
beads.append(N.Bead(50, 50))
N.XY(beads, [img])
for i in range(20):
N.Calibrate(beads, [imgc[i]], i)
N.ComputeCalibration(beads)
N.XYZ(beads, [img])
print(loop, beads[0])
start = time.time()
for i in range(100):
N.XYZ(beads, [img])
ts.append(time.time() - start)
print(ts)
plt.plot(loopRange, np.array(ts), marker="o", label="Numpy")
print(np.polynomial.polynomial.polyfit(loopRange[1:], ts[1:], 1))
plt.title("Time to run 100 frames")
plt.ylabel("Time(s)")
plt.xlabel("Bead Number")
plt.grid()
plt.legend()
plt.show()