Commit 1ef18da2 authored by Lucas Laplanche's avatar Lucas Laplanche
Browse files

ajout curve fit ftir

parent b10f577c
import numpy as np
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from scipy.optimize import curve_fit
from tqdm import tqdm
import ftir as ft
import optic as op
import pandas_tools as pdt
import structure_macro as stm
......@@ -13,7 +15,11 @@ import transfer_matrix_method as tmm
def reflectivity_from_growth_speed_2x2(delta_speed=0.05, start_wavelength=700e-9, stop_wavelength=1000e-9, electric_field=0., n_points=300):
def reflectivity_from_growth_speed_2x2(delta_speed=0.05,
start_wavelength=700e-9,
stop_wavelength=1000e-9,
electric_field=0.,
n_points=300):
# reflectivity computation parameters
wavelength = np.linspace(start_wavelength, stop_wavelength, num=n_points)
r = np.zeros(len(wavelength))
......@@ -87,9 +93,10 @@ def reflectivity_from_growth_speed_2x2(delta_speed=0.05, start_wavelength=700e-9
fig.show()
def reflectivity_from_growth_speed_1x2(bypass_dbr=True, delta_speed=0.1, start_wavelength=700e-9, stop_wavelength=1000e-9, electric_field=0., n_points=200):
def reflectivity_from_growth_speed_1x2(start_wavelength=700e-9,
stop_wavelength=1000e-9,
electric_field=0.,
n_points=200):
# reflectivity computation parameters
wavelength = np.linspace(start_wavelength, stop_wavelength, num=n_points)
r = np.zeros(len(wavelength))
......@@ -109,11 +116,10 @@ def reflectivity_from_growth_speed_1x2(bypass_dbr=True, delta_speed=0.1, start_w
for i in tqdm(range(len(cell_list))):
for j in range(len(cell_list[i])):
argument = {cell_names[i]: cell_list[i][j]}
argument = stm.eam_vcsel_classic_arguments() | {cell_names[i]: cell_list[i][j]}
sl = sls.structure_eam_vcsel(**argument)
sl = sls.structure_eam(bypass_dbr=bypass_dbr,
**argument,
v_ga6=90)
for k in range(len(wavelength)):
sl = op.algaas_super_lattice_refractive_index(sl, electric_field, wavelength[k])
......@@ -121,7 +127,7 @@ def reflectivity_from_growth_speed_1x2(bypass_dbr=True, delta_speed=0.1, start_w
n = sl['refractive_index'].to_numpy(dtype=np.complex128)
d = sl['thickness'].to_numpy(dtype=np.complex128)
r[k] = op.reflection(n, d, wavelength[k])
r[k] = tmm.reflection(n, d, wavelength[k])
# add the traces
fig.add_trace(
......@@ -161,9 +167,12 @@ def reflectivity_from_growth_speed_1x2(bypass_dbr=True, delta_speed=0.1, start_w
fig.show()
def reflectivity_from_growth_speed(v_ga6, v_ga11, v_al5, v_al12, start_wavelength=700e-9, stop_wavelength=1000e-9, electric_field=0., n_points=300):
def reflectivity_from_growth_speed(v_ga6, v_ga11, v_al5, v_al12,
start_wavelength=700e-9,
stop_wavelength=1000e-9,
electric_field=0.,
n_points=300,
figure=True):
# reflectivity computation parameters
wavelength = np.linspace(start_wavelength, stop_wavelength, num=n_points)
r = np.zeros(len(wavelength))
......@@ -187,121 +196,107 @@ def reflectivity_from_growth_speed(v_ga6, v_ga11, v_al5, v_al12, start_wavelengt
r[k] = tmm.reflection(n, d, wavelength[k])
# figure parameters
# create a figure
fig = go.Figure()
# add the traces
fig.add_trace(
go.Scatter(
x=wavelength,
y=r,
name='v_ga6 = ' +str(v_ga6) +' , '
+'v_ga11 = ' +str(v_ga11) +' , '
+'v_al5 = ' +str(v_al5) +' , '
+'v_al12 = ' +str(v_al12),
if figure:
# figure parameters
# create a figure
fig = go.Figure()
# add the traces
fig.add_trace(
go.Scatter(
x=wavelength,
y=r,
name='v_ga6 = ' +str(v_ga6) +' , '
+'v_ga11 = ' +str(v_ga11) +' , '
+'v_al5 = ' +str(v_al5) +' , '
+'v_al12 = ' +str(v_al12),
)
)
)
# create axis objects
fig.update_layout(
xaxis=dict(
title='wavelength [m]'
),
yaxis=dict(
title='reflectivity [1]',
titlefont=dict(
color='#1f77b4'
# create axis objects
fig.update_layout(
xaxis=dict(
title='wavelength [m]'
),
tickfont=dict(
color='#1f77b4'
yaxis=dict(
title='reflectivity [1]',
titlefont=dict(
color='#1f77b4'
),
tickfont=dict(
color='#1f77b4'
)
)
)
)
# update layout properties
fig.update_layout(
title_text='reflectivity as a function of wavelength',
width=1600,
)
# show the figure
fig.show()
# update layout properties
fig.update_layout(
title_text='reflectivity as a function of wavelength',
width=1600,
)
# show the figure
fig.show()
def reflectivity_from_growth_speed_slider(delta_speed=0.1, start_wavelength=700e-9, stop_wavelength=1000e-9, electric_field=0., n_points=300):
def reflectivity_from_growth_speed_slider(delta_speed=0.05,
n_points_slider=20,
start_wavelength=700e-9,
stop_wavelength=1000e-9,
tmm_resolution=100):
# reflectivity computation parameters
wavelength = np.linspace(start_wavelength, stop_wavelength, num=n_points)
wavelength = np.linspace(start_wavelength, stop_wavelength, num=tmm_resolution)
r = np.zeros(len(wavelength))
# epitaxy structure parameters
speed_array = np.array([1. - delta_speed, 1. + delta_speed])
v_ga6 = 100 * speed_array
v_ga11 = 850 * speed_array
v_al5 = 900 * speed_array
v_al12 = 150 * speed_array
cell_list = [v_ga6, v_ga11, v_al5, v_al12]
cell_names = ['v_ga6', 'v_ga11', 'v_al5', 'v_al12']
# create the vector of different speeds [1]
speed_vector = np.linspace(1. -delta_speed, 1. +delta_speed, num=n_points_slider)
v_ga6_arr = 100.*speed_vector
argument = stm.eam_vcsel_classic_arguments()
# create figure
fig = go.Figure()
sl = sls.structure_eam_vcsel(**argument)
# add traces, one for each slider step
for v_ga6 in tqdm(v_ga6_arr):
# arguments to create the corresponding structure
cells_arg = {'v_ga6': v_ga6,}
argument = stm.eam_vcsel_classic_arguments() | cells_arg
for k in tqdm(range(len(wavelength))):
sl = op.algaas_super_lattice_refractive_index(sl, electric_field, wavelength[k])
# create the structure
sl = sls.structure_eam_vcsel(**argument)
n = sl['refractive_index'].to_numpy(dtype=np.complex128)
d = sl['thickness'].to_numpy(dtype=np.complex128)
# calculate the reflectivity
for k in range(len(wavelength)):
sl = op.algaas_super_lattice_refractive_index(sl, 0., wavelength[k])
r[k] = tmm.reflection(n, d, wavelength[k])
n = sl['refractive_index'].to_numpy(dtype=np.complex128)
d = sl['thickness'].to_numpy(dtype=np.complex128)
r[k] = tmm.reflection(n, d, wavelength[k])
# figure parameters
# create a figure
fig = go.Figure()
# add the traces
fig.add_trace(
go.Scatter(
x=wavelength,
y=r,
name='v_ga6 = ' +str(v_ga6) +' , '
+'v_ga11 = ' +str(v_ga11) +' , '
+'v_al5 = ' +str(v_al5) +' , '
+'v_al12 = ' +str(v_al12),
)
)
# create axis objects
fig.update_layout(
xaxis=dict(
title='wavelength [m]'
),
yaxis=dict(
title='reflectivity [1]',
titlefont=dict(
color='#1f77b4'
),
tickfont=dict(
color='#1f77b4'
# add the trace with the current growth speed configuration
fig.add_trace(
go.Scatter(
visible=False,
x=wavelength,
y=r,
name='v_ga6 = ' +str(v_ga6),
)
)
)
# update layout properties
# make first trace visible
fig.data[1].update(visible=True)
fig.update_layout(
title_text='reflectivity as a function of wavelength',
width=1600,
sliders=slider_generator('Ga6', fig.data, n_points_slider)
)
# show the figure
fig.show()
......@@ -372,6 +367,86 @@ def reflectivity_heatmap(bypass_dbr=True,
def growth_speed_fit(delta_speed=0.1,
start_wavelength=700e-9,
stop_wavelength=1000e-9,
tmm_resolution=100):
# initial guess
v_ga6 = 100.
v_ga11 = 850.
v_al5 = 900.
v_al12 = 150.
# initial guess object
v0 = v_ga6, v_ga11, v_al5, v_al12
# lower boundaries
v_ga6_min = (1 -delta_speed) * v_ga6
v_ga11_min = (1 -delta_speed) * v_ga11
v_al5_min = (1 -delta_speed) * v_al5
v_al12_min = (1 -delta_speed) * v_al12
# higher boundaries
v_ga6_max = (1 +delta_speed) * v_ga6
v_ga11_max = (1 +delta_speed) * v_ga11
v_al5_max = (1 +delta_speed) * v_al5
v_al12_max = (1 +delta_speed) * v_al12
# boundaries object
bounds = ([v_ga6_min, v_ga11_min, v_al5_min, v_al12_min], [v_ga6_max, v_ga11_max, v_al5_max, v_al12_max])
# curve fit
# don't forget to choose in reflectivity_alias(..) the correct sl structure
# according to the type of data you import from the ftir (it should be the same structure of course !)
wavelength, r_to_fit = ft.import_ftir_mbe_maison('A1397_centre.dat')
# slice and shrink the arrays
wavelength, r_to_fit = resize_w_r_length(wavelength, r_to_fit, start_wavelength, stop_wavelength, tmm_resolution)
values = curve_fit(reflectivity_alias, wavelength, r_to_fit, v0, bounds=bounds)
# print computed values
print('v_ga6 = ', values[0])
print('v_ga11 = ', values[1])
print('v_al5 = ', values[2])
print('v_al12 = ', values[3])
def reflectivity_alias(wavelength, v_ga6, v_ga11, v_al5, v_al12):
# reflectivity array
r = np.zeros(len(wavelength))
# super lattice structure
# arguments
cells_arg = {'v_ga6' : v_ga6,
'v_ga11' : v_ga11,
'v_al5' : v_al5,
'v_al12' : v_al12,}
argument = stm.eam_vcsel_classic_arguments() | cells_arg
# create the structure
sl = sls.structure_eam_vcsel(**argument)
# calculate the reflectivity
for k in range(len(wavelength)):
sl = op.algaas_super_lattice_refractive_index(sl, 0., wavelength[k])
n = sl['refractive_index'].to_numpy(dtype=np.complex128)
d = sl['thickness'].to_numpy(dtype=np.complex128)
r[k] = tmm.reflection(n, d, wavelength[k])
# return the reflectivity
return r
def row_num(x):
if x>=2:
return 2
......@@ -385,4 +460,57 @@ def col_num(x):
return 1
# odd
else:
return 2
\ No newline at end of file
return 2
def slider_generator(slider_name, slider_array, n_points_slider):
steps = []
for i in range(len(slider_array)):
step = dict(
method='update',
args=[{'visible': [False] * len(slider_array)},
{'title': slider_name + str(slider_array[i])}], # layout attribute
)
step['args'][0]['visible'][i] = True # toggle i'th trace to 'visible'
steps.append(step)
slider = [dict(
active=10,
currentvalue={'prefix': 'Ga6: '},
pad={'t': n_points_slider},
steps=steps
)]
return slider
def resize_w_r_length(w, r, start_wavelength, stop_wavelength, tmm_resolution):
# get the indices of the boundaries
# calculate the difference array
difference_array = np.absolute(w - start_wavelength)
# find the index of minimum element from the array
idx_700 = difference_array.argmin()
difference_array = np.absolute(w - stop_wavelength)
idx_1000 = difference_array.argmin()
# slice the arrays
w = w[idx_700:idx_1000]
r = r[idx_700:idx_1000]
# get the length of the array
l = w.shape[0]
# create an evenly spaced array of indices of length tmm_resolution
indices = np.floor(np.linspace(0, l -1, num = tmm_resolution)).astype(int)
# shrink the arrays
w = w[indices]
r = r[indices]
return w, r
......@@ -45,8 +45,8 @@ def import_ftir_mbe_maison(file, document_folder=True, linux=True):
else:
file = 'Z:\\Documents\\mesures\\ftir_salle_blanche\\' +file
wavelength = np.loadtxt(file, usecols=0)
reflectivity = np.loadtxt(file, usecols=1)
wavelength = np.array(np.loadtxt(file, usecols=0)) * 1e-9 # [nm] -> [m]
reflectivity = np.array(np.loadtxt(file, usecols=1))
return wavelength, reflectivity
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment