-
Notifications
You must be signed in to change notification settings - Fork 0
/
comparison.py
137 lines (107 loc) · 3.87 KB
/
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
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
128
129
130
131
132
133
134
135
136
137
import numpy as np
from matplotlib import pyplot as plt
from scipy.integrate import trapz
import argparse
# x = np.linspace(-10, 10, 1000)
# y = np.sin(2*np.pi*x)
# fw = np.fft.fft(y)
# w = np.fft.fftfreq(len(x), x[1]-x[0])
# # y2 = np.fft.ifft(fw)
# # plt.plot(x,y2)
# # plt.show()
# plt.plot(w,fw)
# plt.show()
# plt.plot(x,y)
# plt.show()
def main(args):
ts = [args.padetime, args.dtfttime, args.groundtime]
f = args.file
for t in ts:
with np.load(f'{f}_t={t}.npz') as data:
dft = data['dft']
freqs = data['freqs']
# periods = (5*t)//200
plt.semilogy(freqs, np.abs(dft)**2 / max(np.abs(dft)**2), label=f'$|DTFT|^2$, {t}')
plt.legend()
plt.xlabel('frequency (meep units)')
plt.ylabel('$|DTFT|^2$ (a.u.)')
plt.savefig(f'dft-extension.png')
plt.close()
ring_data = np.load(f'{f}_t={args.groundtime}.npz')
pade_data = np.load(f'pade-data_t={args.padetime}.npz')
freqs = ring_data['freqs']
pade_approx = pade_data['pade_approx']
dft = ring_data['dft']
plt.semilogy(freqs, np.abs(dft)**2 / max(np.abs(dft)**2), label=f'meep, {args.groundtime}')
plt.semilogy(freqs, np.abs(pade_approx)**2 / max(np.abs(pade_approx)**2), label=f'pade, {args.padetime}')
plt.xlabel('frequency (meep units)')
plt.ylabel('$|DTFT|^2$ (a.u.)')
plt.legend()
plt.savefig(f'pade-winning.png')
plt.close()
ring_data = np.load(f'{f}_t={args.padetime}.npz')
pade_data = np.load(f'pade-data_t={args.padetime}.npz')
freqs = ring_data['freqs']
pade_approx = pade_data['pade_approx']
dft = ring_data['dft']
plt.semilogy(freqs, np.abs(dft)**2, label='dtft')
plt.semilogy(freqs, np.abs(pade_approx)**2, label='pade')
plt.xlabel('frequency (meep units)')
plt.ylabel('$|DTFT|^2$')
plt.legend()
plt.savefig('unnormalized.png')
# with np.load(f'ring-data_t={40000}.0.npz') as data:
# ez = data['ez']
# dft = data['dft']
# fcen, df, dt = data['domain']
# freqs = data['freqs']
# print(len(ez))
# t = np.arange(0, len(ez)*dt, dt)
# print(len(t))
# plt.plot(t,ez)
# # plt.semilogy(freqs, np.abs(dft)**2 / max(np.abs(dft)**2), label='normalized dtft: 16 periods')
# plt.xlabel('time (meep units)')
# plt.ylabel('$E_z$')
# plt.savefig(f'time-domain_t={40000}.png')
# plt.close()
# quit()
# with np.load(f'ring-data_t={4000}.0.npz') as data:
# ez = data['ez']
# dft = data['dft']
# fcen, df, dt = data['domain']
# freqs = data['freqs']
# print(len(ez))
# dft_4k = dft
# t = np.arange(0, len(ez)*dt, dt)
# print(len(t))
# plt.semilogy(freqs, np.abs(dft)**2 / max(np.abs(dft)**2), label='normalized dtft: 100 periods')
# plt.legend()
# plt.xlabel('frequency (meep units)')
# plt.ylabel('$|DTFT|^2$ (a.u.)')
# plt.savefig(f'dft-extension.png')
# plt.close()
# ts = [75, 100, 150, 200, 250, 300, 350, 400, 450, 500]
# # ts = [75]
# int_pade = []
# int_dft = []
# for t in ts:
# ring_data = np.load(f'ring-data_t={t}.0.npz')
# pade_data = np.load(f'pade-data_t={t}.0.npz')
# freqs = ring_data['freqs']
# pade_approx = pade_data['pade_approx']
# dft = ring_data['dft']
# int_pade.append(trapz(np.abs(pade_approx)**2 / max(np.abs(pade_approx)**2), freqs))
# int_dft.append(trapz(np.abs(dft)**2 / max(np.abs(dft)**2), freqs))
# # int_dft.append(trapz(np.abs(dft)**2 / max(np.abs(dft)**2), freqs))
# plt.scatter(ts, int_pade)
# plt.scatter(ts, int_dft)
# plt.scatter([*ts, 4000], int_dft)
# plt.show()
if __name__=='__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--padetime', '-pt', type=int, default=200, help='time for pade')
parser.add_argument('--dtfttime', '-dt', type=int, default=4000, help='time for dtft')
parser.add_argument('--groundtime', '-gt', type=int, default=10000, help='time for groundtruth')
parser.add_argument('--file', '-f', type=str, help='file prefix')
args = parser.parse_args()
main(args)