def update(val): d1 = sd1.val d2 = sd2.val n = int(sn.val) s = stack * n s.append(BK7) s.insert(0, air) TM = TransferMatrix(s, [d1, d2] * n) yval = _np.mod( _np.angle(TM.trackSingleBeam([-1, 0, 1, 2, 3], wl, 0, False)), 2 * _const.pi) [curve.set_ydata(yval[:, i]) for i, curve in enumerate(l)] reflectance.set_ydata(TM.solveTransmission(wl, 0, True)[:, 0]) fig.canvas.draw_idle() fig2.canvas.draw_idle()
import material_table as _mtbl import numpy as _np import matplotlib.pyplot as plt from TMM import TransferMatrix air = _mtbl.MaterialTable.fromMaterial('air') gold = _mtbl.MaterialTable.fromMaterial('Au') BK7 = _mtbl.MaterialTable.fromMaterial('BK7') # Task 10 transferredI = [] wavelengths = _np.arange(0.4, 1, 0.001) for i in range(1, 21): TM = TransferMatrix([air, gold, BK7], i * 10 * 1e-3) transferredI.append([i * 10, TM.solveTransmission(wavelengths, 0, True)]) transferredI = _np.array(transferredI) plt.figure() for i in range(len(transferredI)): plt.plot(wavelengths, transferredI[i, 1][:, 1], label=str(transferredI[i, 0]) + 'nm') plt.legend() plt.ylabel('Transmittance') plt.xlabel("$\lambda$ [$\mu$m]") plt.yscale('log') plt.show() plt.figure() for i in range(len(transferredI)):
AlAs = MaterialTable.fromCsv('AlAs.txt', delimiter='\t', skiprows=1, wavelength_multiplier=1e-3) SiO2 = MaterialTable.fromCsv('SiO2.txt', delimiter='\t', skiprows=1, wavelength_multiplier=1e-3) air = MaterialTable.fromMaterial('air') TM = TransferMatrix([air, AlAs, SiO2, air], [0.01, 0.25]) ref = _np.loadtxt('air-AlAs_10-SiO2_250-air.csv', skiprows=1, delimiter='\t') ref[:, 0] *= 1e-3 wl = ref[:, 0] r, t = TM.solveTransmission(wl, 0, True).transpose() fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True) ax2.plot(wl, t - ref[:, 1]) ax2.set_ylabel('Difference [a.u.]') ax2.set_ylim([-5e-4, 5e-4]) ax1.plot(wl, ref[:, 1]) ax1.plot(wl, t) ax1.set_ylabel('Transmittance [a.u.]') ax2.set_xlabel("$\lambda$ [$\mu$m]") ax1.set_ylim([0.5, 1]) ax2.grid() ax1.grid() plt.show()
_np.mod(_np.angle(TM.trackSingleBeam([-1, 0, 1, 2, 3], wl, 0, False)), 2 * _const.pi)) plt.legend([-1, 0, 1, 2, 3]) plt.ylim([0, 2 * _const.pi]) axn = plt.axes([0.25, 0.12, 0.65, 0.03]) axd1 = plt.axes([0.25, 0.07, 0.65, 0.03]) axd2 = plt.axes([0.25, 0.02, 0.65, 0.03]) sd1 = Slider(axd1, 'd1', 0.001, 0.5, valinit=0.01, valstep=0.001) sd2 = Slider(axd2, 'd2', 0.001, 0.5, valinit=0.01, valstep=0.001) sn = Slider(axn, 'n', 2, 100, valinit=2, valstep=1) plt.show() fig2 = plt.figure() reflectance, = plt.plot(wl, TM.solveTransmission(wl, 0, True)[:, 0]) plt.ylim([0, 1]) plt.show() def update(val): d1 = sd1.val d2 = sd2.val n = int(sn.val) s = stack * n s.append(BK7) s.insert(0, air) TM = TransferMatrix(s, [d1, d2] * n) yval = _np.mod( _np.angle(TM.trackSingleBeam([-1, 0, 1, 2, 3], wl, 0, False)), 2 * _const.pi)