def getThicknesses(l=0.5, periods=2):
    widths = []
    stack = [air] + [Ta2O5, MgF2] * 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
    for i in range(periods * 2):
        phase_diff = _np.mod(
            p0 - _np.mod(phase + _np.angle(-IM[i + 1][1, 0] / IM[i + 1][1, 1]),
                         2 * _const.pi), 2 * _const.pi)
        if (phase_diff == 0):
            phase_diff = 2 * _const.pi
        width = l * phase_diff / (4 * _const.pi * TM.getLayer(i)[0].getRealN(l)
                                  )  # 4pi/l *n*d = phase_diff
        widths.append(width)
        phase = _np.mod(
            phase + phase_diff +
            _np.angle(1 - (IM[i + 1][1, 0] / IM[i + 1][1, 1])**2),
            2 * _const.pi
        )  # Phase change of thransmission through the ith interface and back

    return (stack, widths)
def update(val):
    theta = st.val
    transmissions_p = TransferMatrix(stack,
                                     d).solveTransmission(wl, theta, True)
    transmissions_s = TransferMatrix(stack,
                                     d).solveTransmission(wl, theta, False)
    reflectance_p = transmissions_p[:, 0] / (transmissions_p[:, 0] +
                                             transmissions_p[:, 1])
    reflectance_s = transmissions_s[:, 0] / (transmissions_s[:, 0] +
                                             transmissions_s[:, 1])
    p.set_ydata(reflectance_p)
    s.set_ydata(reflectance_s)
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()
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)
def update(val):
    thickness = sd.val
    comp_transmissions = TransferMatrix(stack, d).solveTransmission(
        wl, 0, True, True)

    normalisedSource = _np.abs(
        _np.sum([
            _np.exp(1j * i * BK7.getRealN(wl) * thickness * 4 * _const.pi / wl)
            * comp_transmissions[:, 0]**(2 * i) * comp_transmissions[:, 1]
            for i in range(50)
        ],
                axis=0))**2
    #normalisedSource = normalisedSource/_np.max(normalisedSource)
    l.set_ydata(normalisedSource)
Exemple #6
0
#!/usr/bin/ipython3
import material_table as _mtbl
import numpy as _np
import matplotlib.pyplot as plt
from TMM import TransferMatrix
from matplotlib.widgets import Slider
from scipy.optimize import curve_fit

air = _mtbl.MaterialTable.fromMaterial('Vacuum')
BK7 = _mtbl.MaterialTable.fromMaterial('BK7')

# Task 8
plt.ion()

fitfunc = lambda l, d, *n: TransferMatrix([
    air, _mtbl.MaterialTable.fromArray(wls[::2], n), BK7
], _np.abs(d)).solveTransmission(wls, 0, False)[:, 0]

wls = _np.arange(0.4, 1, 0.005)

fit, cov = curve_fit(fitfunc, wls, 0, p0=[0.14] + [1.0] * (int(len(wls) / 2)))

fig, ax = plt.subplots()
plt.subplots_adjust(left=0.25, bottom=0.25)
plt.set_cmap('gnuplot')
plt.plot(wls, fitfunc(wls, *fit))
plt.ylim([0, 0.2])
plt.ylabel('Reflectance')
plt.xlabel("$\lambda$ [$\mu$m]")
plt.grid()
plt.show()
        widths.append(width)
        phase = _np.mod(
            phase + phase_diff +
            _np.angle(1 - (IM[i + 1][1, 0] / IM[i + 1][1, 1])**2),
            2 * _const.pi
        )  # Phase change of thransmission through the ith interface and back

    return (stack, widths)


fig, ax = plt.subplots()
plt.subplots_adjust(left=0.25, bottom=0.25)
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
    i += 1
transmissions_p = TransferMatrix(stack, d).solveTransmission(wl, 0, True)
transmissions_s = TransferMatrix(stack, d).solveTransmission(wl, 0, False)
reflectance_p = transmissions_p[:, 0] / (transmissions_p[:, 0] +
                                         transmissions_p[:, 1])
reflectance_s = transmissions_s[:, 0] / (transmissions_s[:, 0] +
                                         transmissions_s[:, 1])
p, = plt.plot(wl, reflectance_p)
s, = plt.plot(wl, reflectance_s)
plt.legend(['p polarisation', 's polarisation'])
plt.ylabel('Reflectance')
    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
    for i in range(periods * 2):
        phase_diff = _np.mod(
            p0 - _np.mod(phase + _np.angle(-IM[i + 1][1, 0] / IM[i + 1][1, 1]),
                         2 * _const.pi), 2 * _const.pi)
        if (phase_diff < 1e-6):
            phase_diff = 2 * _const.pi
        width = l * phase_diff / (4 * _const.pi * TM.getLayer(i)[0].getRealN(l)
                                  )  # 4pi/l *n*d = phase_diff
        widths.append(width)
        phase = _np.mod(
            phase + phase_diff +
            _np.angle(1 - (IM[i + 1][1, 0] / IM[i + 1][1, 1])**2),
            2 * _const.pi
        )  # Phase change of thransmission through the ith interface and back

    return (stack, widths)


fig2 = plt.figure()
stack, d = getThicknesses(0.6, 10)
transmissions = TransferMatrix(stack, d).solveTransmission(wl, 0, True)
reflectance = transmissions[:, 0] / (transmissions[:, 0] + transmissions[:, 1])
plt.plot(wl, reflectance)
plt.ylabel('Reflectance')
plt.xlabel("$\lambda$ [$\mu$m]")
plt.ylim([0, 1])
plt.show()
Exemple #9
0
		phase_diff = _np.mod(p0 - _np.mod(phase + _np.angle(-IM[i+1][1,0]/IM[i+1][1,1]),2*_const.pi),2*_const.pi)
		if (phase_diff < 1e-6):
			phase_diff = 2*_const.pi
		width = l*phase_diff/(4*_const.pi*TM.getLayer(i)[0].getRealN(l)) # 4pi/l *n*d = phase_diff
		widths.append(width)
		phase = _np.mod(phase+phase_diff+_np.angle(1-(IM[i+1][1,0]/IM[i+1][1,1])**2),2*_const.pi) # Phase change of thransmission through the ith interface and back

	return (stack,widths)



fig2 = plt.figure()
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
	i += 1
transmissions = TransferMatrix(stack,d).solveTransmission(wl,0,True)
reflectance = transmissions[:,0]/(transmissions[:,0] + transmissions[:,1])
plt.plot(wl,reflectance)
plt.ylabel('Reflectance')
plt.xlabel("$\lambda$ [$\mu$m]")
plt.ylim([0,1])
plt.show()

# Task 15
def update(val):
	n = sn.val
	d = sd.val
	l[0].set_ydata(TransferMatrix([air,_mtbl.MaterialTable.fromValue(n),BK7],d).solveTransmission(wls,0,False)[:,0])
	fig.canvas.draw_idle()
Exemple #11
0
BK7 = MaterialTable.fromMaterial('BK7', 0.4, 1)
MgF2 = MaterialTable.fromMaterial('MgF2', 0.4, 1)
Ta2O5 = MaterialTable.fromMaterial('Ta2O5', 0.4, 1)

stack = [Ta2O5, MgF2] * 2
stack.append(BK7)
stack.insert(0, air)

ds = _np.arange(0.01, 0.2, 0.001)

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

phases = _np.array(
    _np.mod([[
        _np.angle(
            TransferMatrix(stack, [d] * 4).trackSingleBeam(
                [-1, 0, 1, 2, 3], w, 0, False)) for w in wl
    ] for d in ds], 2 * _const.pi))

fig, ax = plt.subplots()
plt.subplots_adjust(left=0.25, bottom=0.25)
l = plt.plot(wl, phases[5])
plt.legend([-1, 0, 1, 2, 3])
axd = plt.axes([0.25, 0.15, 0.65, 0.03])
sd = Slider(axd, 'd', ds[0], ds[-1], valinit=ds[5], valstep=0.001)


def update(val):
    did = _np.where(_np.abs(ds - sd.val) <= 1e-6)[0][0]
    [i.set_ydata(phases[did, :, l.index(i)]) for i in l]
    fig.canvas.draw_idle()
        width = l * phase_diff / (4 * _const.pi * TM.getLayer(i)[0].getRealN(l)
                                  )  # 4pi/l *n*d = phase_diff
        widths.append(width)
        phase = _np.mod(
            phase + phase_diff +
            _np.angle(1 - (IM[i + 1][1, 0] / IM[i + 1][1, 1])**2),
            2 * _const.pi
        )  # Phase change of thransmission through the ith interface and back

    return (stack, widths)


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
    i += 1

fig, ax = plt.subplots()
plt.subplots_adjust(left=0.25, bottom=0.25)

comp_transmissions = TransferMatrix(stack,
                                    d).solveTransmission(wl, 0, True, True)

normalisedSource = _np.abs(
    _np.sum([
        _np.exp(1j * i * BK7.getRealN(wl) * 0.633 * 4 * _const.pi / wl) *
air = MaterialTable.fromMaterial('air', 0.4, 1)
BK7 = MaterialTable.fromMaterial('BK7', 0.4, 1)
MgF2 = MaterialTable.fromMaterial('MgF2', 0.4, 1)
Ta2O5 = MaterialTable.fromMaterial('Ta2O5', 0.4, 1)

stack = [Ta2O5, MgF2]

initStack = stack * 2
initStack.append(BK7)
initStack.insert(0, air)

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

fig, ax = plt.subplots()
plt.subplots_adjust(left=0.25, bottom=0.25)
TM = TransferMatrix(initStack, [0.01, 0.01] * 2)
l = plt.plot(
    wl,
    _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()
ns = _np.arange(1, 2, 0.01)
thicknesses = _np.arange(0.01, 0.5, 0.01)
wls = _np.arange(0.4, 1, 0.005)
thetas = _np.arange(0, _const.pi, 0.1)

customMaterials = [_mtbl.MaterialTable.fromValue(n) for n in ns]
transmission = []
for i in range(ns.size):
    temp_d_data = []
    for d in thicknesses:
        temp_theta_data = []
        for t in thetas:
            temp_theta_data.append([
                d,
                TransferMatrix([air, customMaterials[i], BK7],
                               d).solveTransmission(wls, t, False)[:, 0]
            ])
        temp_d_data.append(temp_theta_data)
    transmission.append(temp_d_data)
transmission = _np.array(transmission)

fig, ax = plt.subplots()
plt.subplots_adjust(left=0.25, bottom=0.25)
plt.set_cmap('gnuplot')
l = plt.plot(wls, transmission[5, 2, 7, 1])
plt.ylim([0, 0.2])
plt.ylabel('Reflectance')
plt.xlabel('$\lambda$ [$\mu$m]')
plt.grid()
axn = plt.axes([0.25, 0, 0.65, 0.03])
axd = plt.axes([0.25, 0.05, 0.65, 0.03])
#!/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()
from matplotlib.widgets import Slider


air = _mtbl.MaterialTable.fromMaterial('Vacuum')
BK7 = _mtbl.MaterialTable.fromMaterial('BK7')

# Task 8
plt.ion()


wls = _np.arange(0.4,1,0.005)

fig,ax = plt.subplots()
plt.subplots_adjust(left=0.25, bottom=0.25)
plt.set_cmap('gnuplot')
l = plt.plot(wls,TransferMatrix([air,_mtbl.MaterialTable.fromValue(1.1),BK7],0.15).solveTransmission(wls,0,False)[:,0])
plt.ylim([0,0.2])
plt.grid()
axn = plt.axes([0.25, 0.1, 0.65, 0.03])
axd = plt.axes([0.25, 0.15, 0.65, 0.03])
sn = Slider(axn, 'n',1,2,valinit=1.1,valstep=0.01)
sd = Slider(axd, 'd',0.01,0.5,valinit=0.15,valstep=0.01)

def update(val):
	n = sn.val
	d = sd.val
	l[0].set_ydata(TransferMatrix([air,_mtbl.MaterialTable.fromValue(n),BK7],d).solveTransmission(wls,0,False)[:,0])
	fig.canvas.draw_idle()

sn.on_changed(update)
sd.on_changed(update)
Exemple #17
0
	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
	for i in range(periods*2):
		phase_diff = _np.mod(p0 - _np.mod(phase + _np.angle(-IM[i+1][1,0]/IM[i+1][1,1]),2*_const.pi),2*_const.pi)
		if (phase_diff < 1e-6):
			phase_diff = 2*_const.pi
		width = l*phase_diff/(4*_const.pi*TM.getLayer(i)[0].getRealN(l)) # 4pi/l *n*d = phase_diff
		widths.append(width)
		phase = _np.mod(phase+phase_diff+_np.angle(1-(IM[i+1][1,0]/IM[i+1][1,1])**2),2*_const.pi) # Phase change of thransmission through the ith interface and back

	return (stack,widths)

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
	i += 1

thetas = _np.linspace(0,_const.pi/2,25)[:-2] # fix so 1/0 doesnt happen
T = TransferMatrix(stack,d).solveTransmission(wl,thetas,[True,False])

cmap = plt.get_cmap('gnuplot')
fig, (ax1,ax2) = plt.subplots(2,1,sharex=True)
pc = ax1.pcolormesh(wl,thetas,T[:,:,0,0].transpose(),cmap=cmap)
ax1.set_ylabel("$\\theta$ [rad]")
pc = ax2.pcolormesh(wl,thetas,T[:,:,1,0].transpose(),cmap=cmap)
ax2.set_xlabel("$\lambda$ [$\mu$m]")
Exemple #18
0
import scipy.constants as _const
from scipy.optimize import curve_fit
from scipy.interpolate import interp1d
plt.ion()

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])
import scipy.constants as _const
from scipy.optimize import curve_fit
import matplotlib.colors as colors

plt.ion()

air = MaterialTable.fromMaterial('air', 0.4, 1)
BK7 = MaterialTable.fromMaterial('BK7', 0.4, 1)
Au = MaterialTable.fromMaterial('Au', 0.4, 1)

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

depths = _np.linspace(0, 11, 1000)
Is = TransferMatrix([air] + [BK7, Au] * 5 + [BK7],
                    [0.5, 0.1] * 5).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.xlabel("$\lambda$ [$\mu$m]")
plt.ylabel("z [$\mu$m]")
plt.colorbar()
plt.show()
plt.figure()
plt.pcolormesh(wl, depths, Is[:, :, 1].transpose(), cmap=cmap, norm=norm)
plt.colorbar()
plt.ylabel("z [$\mu$m]")
plt.xlabel("$\lambda$ [$\mu$m]")
Exemple #20
0
#!/usr/bin/ipython3
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()
#!/usr/bin/ipython3
import material_table as _mtbl
import numpy as _np
import matplotlib.pyplot as plt
from TMM import TransferMatrix
from matplotlib.widgets import Slider
from scipy.optimize import curve_fit

air = _mtbl.MaterialTable.fromMaterial('Vacuum')
BK7 = _mtbl.MaterialTable.fromMaterial('BK7')

# Task 8
plt.ion()

fitfunc = lambda l, d: TransferMatrix([
    air, _mtbl.MaterialTable.fromValue(1.24), BK7
], _np.abs(d)).solveTransmission(wls, 0, False)[:, 0]

wls = _np.arange(0.4, 1, 0.005)

fit, cov = curve_fit(fitfunc, wls, 0, p0=[0.14])

fig, ax = plt.subplots()
plt.subplots_adjust(left=0.25, bottom=0.25)
plt.set_cmap('gnuplot')
plt.plot(wls, fitfunc(wls, *fit))
plt.ylim([0, 0.2])
plt.ylabel('Reflectance')
plt.xlabel("$\lambda$ [$\mu$m]")
plt.grid()
plt.show()