MCPcopy Create free account
hub / github.com/NanoComp/meep / plot_radiation_pattern_3D

Function plot_radiation_pattern_3D

python/examples/plot_radiation_pattern_dipole.py:15–71  ·  view source on GitHub ↗

Plots the 3D radiation pattern as a contour plot. Args: dipole_pol: the polarization the electric dipole. Either x or y. radial_flux: the radial flux in polar coordinates.

(dipole_pol: str, radial_flux: np.ndarray)

Source from the content-addressed store, hash-verified

13
14
15def plot_radiation_pattern_3D(dipole_pol: str, radial_flux: np.ndarray):
16 """Plots the 3D radiation pattern as a contour plot.
17
18 Args:
19 dipole_pol: the polarization the electric dipole. Either x or y.
20 radial_flux: the radial flux in polar coordinates.
21 """
22 polar_rad = np.linspace(0, 0.5 * np.pi, NUM_POLAR)
23 azimuth_rad = np.linspace(0, 2 * np.pi, NUM_AZIMUTH)
24 x = np.sin(polar_rad[:, np.newaxis]) * np.cos(azimuth_rad)
25 y = np.sin(polar_rad[:, np.newaxis]) * np.sin(azimuth_rad)
26 normalized_radial_flux = radial_flux / np.max(radial_flux)
27
28 if dipole_pol == "x":
29 analytic_radial_flux = np.sin(np.arccos(x)) ** 2
30 elif dipole_pol == "y":
31 analytic_radial_flux = np.sin(np.arccos(y)) ** 2
32
33 fig, ax = plt.subplots(ncols=2, figsize=(8.5, 4), constrained_layout=True)
34
35 _ = ax[0].tricontourf(
36 x.flatten(),
37 y.flatten(),
38 normalized_radial_flux.flatten(),
39 levels=100,
40 cmap="inferno",
41 )
42 ax[0].set_aspect("equal")
43 ax[0].axis(False)
44 ax[0].set_title("Meep")
45
46 im = ax[1].tricontourf(
47 x.flatten(),
48 y.flatten(),
49 analytic_radial_flux.flatten(),
50 levels=100,
51 cmap="inferno",
52 )
53 ax[1].set_aspect("equal")
54 ax[1].axis(False)
55 ax[1].set_title("analytic")
56
57 divider = make_axes_locatable(ax[1])
58 cax = divider.append_axes("right", size="5%", pad=0.1)
59 cbar = fig.colorbar(im, cax=cax, orientation="vertical")
60 cbar.set_ticks(list(np.arange(0, 1.1, 0.2)))
61 cbar.set_ticklabels([f"{t:.1f}" for t in np.arange(0, 1.1, 0.2)])
62
63 fig.suptitle(
64 f"radiation pattern of an $E_{dipole_pol}$ dipole in vacuum", size="x-large"
65 )
66
67 fig.savefig(
68 "dipole_radiation_pattern_3D.png",
69 dpi=150,
70 bbox_inches="tight",
71 )
72

Calls 1

axisMethod · 0.80

Tested by

no test coverage detected