def update(val):
    global Mat1, Mat2
    n1 = sn1.val
    n2 = sn2.val
    Mat1 = MaterialTable.fromValue(n1)
    Mat2 = MaterialTable.fromValue(n2)
    i = 1
    while True:
        stack, d = getThicknesses(0.633, i)
        RT = TransferMatrix(stack, d).solveTransmission(0.633, 0, True)
        Rprime = RT[0] / (RT[0] + RT[1])
        if Rprime > 0.9999:
            print(Rprime, 'at', i)
            break
        if i > 100:
            break
        i += 1
    transmissions = TransferMatrix(stack, d).solveTransmission(wl, 0, True)
    reflectance = transmissions[:, 0] / (transmissions[:, 0] +
                                         transmissions[:, 1])
    l.set_ydata(reflectance)
#!/usr/bin/ipython3
import numpy as _np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
from TMM import TransferMatrix
from material_table import MaterialTable
import scipy.constants as _const
from scipy.optimize import curve_fit
import matplotlib.colors as colors

plt.ion()

a = MaterialTable.fromValue(1)
b = MaterialTable.fromValue(2)

wl = _np.arange(0.4,1,0.001)


depths = _np.linspace(0,6,1000)
Is = TransferMatrix([a] + [a]*2 + [b]*30 + [b],[1]*2 + [0.1]*30).getIntensityProfile(wl,0,False,zs=depths,function=False)
cmap = plt.get_cmap('gnuplot')
norm = colors.LogNorm()
plt.figure()
plt.pcolormesh(wl,depths,Is[:,:,0].transpose(),cmap=cmap,norm=norm)
plt.colorbar()
plt.show()
plt.figure()
plt.pcolormesh(wl,depths,Is[:,:,1].transpose(),cmap=cmap,norm=norm)
plt.colorbar()
plt.show()
#!/usr/bin/ipython3
import numpy as _np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
from TMM import TransferMatrix
from material_table import MaterialTable
import scipy.constants as _const
from scipy.optimize import curve_fit
plt.ion()

air = MaterialTable.fromMaterial('air', 0.4, 1)
BK7 = MaterialTable.fromMaterial('BK7', 0.4, 1)
Mat2 = MaterialTable.fromValue(5)
Mat1 = MaterialTable.fromValue(2)

wl = _np.arange(0.4, 1, 0.001)


def getThicknesses(l=0.5, periods=2):
    global Mat1, Mat2
    widths = []
    stack = [air] + [Mat1, Mat2] * periods + [BK7]
    TM = TransferMatrix(stack, [1, 1] * periods)
    IM = [
        TM.getInterfacialMatrix(i, l, 0, True) for i in range(-1, periods * 2)
    ]
    p0 = _np.mod(_np.angle(-IM[0][1, 0] / IM[0][1, 1]),
                 2 * _const.pi)  # phase from immediate reflection
    phase = _np.mod(
        _np.angle(1 - (IM[0][1, 0] / IM[0][1, 1])**2), 2 * _const.pi
    )  # Phase change of thransmission through the first interface and back