<jupyter_start><jupyter_text>Lecture-06-3-SI Transfer Matrix Method* author : <NAME>* Data : 2019/12/17<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np<jupyter_output><empty_output><jupyter_text>From this section, because the code in the previous sections is too much, we packed all the previous code into a python module in a directory (**"optics"**). An in the following, we are going to use python module to calculate the example in **Lecture 6-3** again. If you have interest, you can open the file to see the code.<jupyter_code>from optics.TransferMatrix import cal_r_tau_from_structure, cal_field_z, plot_fun, cal_field_z_2
n1, n2 = 1.5, 1.0
theta1 = np.linspace(0, np.pi/2 , 100)
wavelength = 520
e0, mu0 = 1.0, 1.0

c = 1/np.sqrt(e0*mu0)
ko = 2*np.pi/wavelength
w = c * ko
k1, k2 = n1*ko, n2*ko

kx = k1 * np.sin(theta1)
ky = np.zeros( kx.shape )

# calculation by transfer matrix
thickness_list = [0, 0]
er_list = [n1**2, n2**2] 
tau_s_E_TM, r_s_E_TM, _, _ = cal_r_tau_from_structure( kx, ky, thickness_list, ko, er_list, mode='TE')
tau_p_H_TM, r_p_H_TM, _, _ = cal_r_tau_from_structure( kx, ky, thickness_list, ko, er_list, mode='TM')
## plot data
fig, axes = plt.subplots(2,2)
plt.rcParams['figure.figsize'] = [15, 10]

axes[0,0].plot( theta1*180/np.pi, np.abs( r_s_E_TM ), 'ro-', linewidth=2.0)
axes[0,0].plot( theta1*180/np.pi, np.abs( r_p_H_TM ), 'bo-', linewidth=2.0)
axes[0,0].set_xlabel(r'$\theta_i$ (deg.)', fontsize=20)
axes[0,0].set_ylabel(r'$|\gamma|$', fontsize=20)
axes[0,0].legend(['TE', 'TM'], fontsize=20)
plt.xlim( 0, 90);

axes[0,1].plot( theta1*180/np.pi, np.angle( r_s_E_TM, deg=True ), 'ro-', linewidth=2.0)
axes[0,1].plot( theta1*180/np.pi, np.angle( r_p_H_TM, deg=True ), 'bo-', linewidth=2.0)
axes[0,1].set_xlabel(r'$\theta_i$ (deg.)', fontsize=20)
axes[0,1].set_ylabel(r'$\angle\gamma$', fontsize=20)
axes[0,1].legend(['TE', 'TM'], fontsize=20)
plt.xlim( 0, 90);
plt.ylim( -185, 185);

axes[1,0].plot( theta1*180/np.pi, np.abs( tau_s_E_TM ), 'ro-', linewidth=2.0)
axes[1,0].plot( theta1*180/np.pi, np.abs( tau_p_H_TM ), 'bo-', linewidth=2.0)
axes[1,0].set_xlabel(r'$\theta_i$ (deg.)', fontsize=20)
axes[1,0].set_ylabel(r'$|\tau|$', fontsize=20)
axes[1,0].legend(['TE', 'TM'], fontsize=20)
plt.xlim( 0, 90);

axes[1,1].plot( theta1*180/np.pi, np.angle( tau_s_E_TM, deg=True ), 'ro-', linewidth=2.0)
axes[1,1].plot( theta1*180/np.pi, np.angle( tau_p_H_TM, deg=True ), 'bo-', linewidth=2.0)
axes[1,1].set_xlabel(r'$\theta_i$ (deg.)', fontsize=20)
axes[1,1].set_ylabel(r'$\angle\tau$', fontsize=20)
axes[1,1].legend(['TE', 'TM'], fontsize=20)
plt.xlim( 0, 90);
plt.ylim( -185, 185);
theta1 = np.array( [0, 30, 60], dtype=np.float )/180*np.pi
kx = k1 * np.sin(theta1)
ky = np.zeros( kx.shape )
z_list = np.linspace(-520, 520, 1000)
Ep_zlist, En_zlist, _, _, _ = cal_field_z( kx, ky, z_list, thickness_list, ko, er_list , mode='TE', Fp = 1.0)
Hp_zlist, Hn_zlist, _, _, _ = cal_field_z( kx, ky, z_list, thickness_list, ko, er_list , mode='TM', Fp = 1.0)

tau_s_E_TM, r_s_E_TM, _, _ = cal_r_tau_from_structure( kx, ky, thickness_list, ko, er_list, mode='TE')
tau_p_H_TM, r_p_H_TM, _, _ = cal_r_tau_from_structure( kx, ky, thickness_list, ko, er_list, mode='TM')
# incidence angle = 0
plot_fun(Ep_zlist, En_zlist, Hp_zlist, Hn_zlist, z_list, kxIdx=0)
# incidence angle = 30
plot_fun(Ep_zlist, En_zlist, Hp_zlist, Hn_zlist, z_list, kxIdx=1)
# incidence angle = 60
plot_fun(Ep_zlist, En_zlist, Hp_zlist, Hn_zlist, z_list, kxIdx=2)
theta1 = np.array( [0, 30, 60], dtype=np.float )/180*np.pi
kx = k1 * np.sin(theta1)
ky = np.zeros( kx.shape )
z_list = np.linspace(-520, 520, 1000)
Ep_zlist, En_zlist, _, _, _ = cal_field_z_2( kx, ky, z_list, thickness_list, ko, er_list , mode='TE', Fp = 1.0)
Hp_zlist, Hn_zlist, _, _, _ = cal_field_z_2( kx, ky, z_list, thickness_list, ko, er_list , mode='TM', Fp = 1.0)
# incidence angle = 0
plot_fun(Ep_zlist, En_zlist, Hp_zlist, Hn_zlist, z_list, kxIdx=0)
# incidence angle = 30
plot_fun(Ep_zlist, En_zlist, Hp_zlist, Hn_zlist, z_list, kxIdx=1)
# incidence angle = 60
plot_fun(Ep_zlist, En_zlist, Hp_zlist, Hn_zlist, z_list, kxIdx=2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18474861679095503, 'fraction_numerical': 0.06278566273755112, 'mean_word_length': 5.548031496062992, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '186030', 'license': 'MIT', 'n_tokens_mistral': 2106, 'n_tokens_neox': 1920, 'n_words': 404, 'path': 'Lecture-06-3-SI Transfer Matrix Method.ipynb', 'repo_name': 'd04943016/PlanarOpticsLecture', 'size': '4162'}