-
Notifications
You must be signed in to change notification settings - Fork 641
/
Copy pathmpb_data_analysis.py
80 lines (56 loc) · 1.91 KB
/
mpb_data_analysis.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
import os
import sys
import matplotlib.pyplot as plt
import numpy as np
import meep as mp
from meep import mpb
examples_dir = os.path.realpath(os.path.dirname(__file__))
sys.path.insert(0, examples_dir)
def tri_rods():
# Import the ModeSolver defined in the mpb_tri_rods.py example
from mpb_tri_rods import ms as tr_ms
efields = []
# Band function to collect the efields
def get_efields(tr_ms, band):
efields.append(tr_ms.get_efield(band))
tr_ms.run_tm(
mpb.output_at_kpoint(
mp.Vector3(1 / -3, 1 / 3), mpb.fix_efield_phase, get_efields
)
)
# Create an MPBData instance to transform the efields
md = mpb.MPBData(rectify=True, resolution=32, periods=3)
converted = []
for f in efields:
# Get just the z component of the efields
f = f[..., 0, 2]
converted.append(md.convert(f))
tr_ms.run_te()
eps = tr_ms.get_epsilon()
plt.imshow(eps.T, interpolation="spline36", cmap="binary")
plt.axis("off")
plt.show()
md = mpb.MPBData(rectify=True, resolution=32, periods=3)
rectangular_data = md.convert(eps)
plt.imshow(rectangular_data.T, interpolation="spline36", cmap="binary")
plt.axis("off")
plt.show()
for i, f in enumerate(converted):
plt.subplot(331 + i)
plt.contour(rectangular_data.T, cmap="binary")
plt.imshow(np.real(f).T, interpolation="spline36", cmap="RdBu", alpha=0.9)
plt.axis("off")
plt.show()
def diamond():
# Import the ModeSolver from the mpb_diamond.py example
from mpb_diamond import ms as d_ms
dpwr = []
def get_dpwr(ms, band):
dpwr.append(ms.get_dpwr(band))
d_ms.run(mpb.output_at_kpoint(mp.Vector3(0, 0.625, 0.375), get_dpwr))
md = mpb.MPBData(rectify=True, periods=2, resolution=32)
converted_dpwr = [md.convert(d) for d in dpwr]
# TODO: Plot
if __name__ == "__main__":
tri_rods()
diamond()