formattage
This commit is contained in:
parent
d321fce459
commit
d5fae56eb4
1 changed files with 60 additions and 69 deletions
|
@ -63,24 +63,9 @@ def thickness_scheludko_at_order(wavelengths,
|
||||||
return prefactor * (term1 + term2)
|
return prefactor * (term1 + term2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
Calculates the Delta value for arrays of wavelengths, thicknesses h and r_indexs n.
|
|
||||||
|
|
||||||
Parameters:
|
|
||||||
- wavelengths: array_like (or float), wavelengths λ
|
|
||||||
- thickness : array_like (or float), thicknesses h
|
|
||||||
- interference_order : int, interference order
|
|
||||||
- refractive_index : array_like (or float), refractive r_indexs n
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
- delta: ndarray of corresponding Δ values
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def Delta(wavelengths, thickness, interference_order, refractive_index):
|
def Delta(wavelengths, thickness, interference_order, refractive_index):
|
||||||
"""
|
"""
|
||||||
|
Compute the Delta values.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
@ -95,8 +80,8 @@ def Delta(wavelengths, thickness, interference_order, refractive_index):
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
TYPE
|
ndarray
|
||||||
DESCRIPTION.
|
Delta values.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -125,7 +110,6 @@ def Delta(wavelengths, thickness, interference_order, refractive_index):
|
||||||
return (A * (1 + alpha)) / (1 + A * alpha)
|
return (A * (1 + alpha)) / (1 + A * alpha)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def Delta_fit(xdata, thickness, interference_order):
|
def Delta_fit(xdata, thickness, interference_order):
|
||||||
"""
|
"""
|
||||||
Wrapper on Delta() for curve_fit.
|
Wrapper on Delta() for curve_fit.
|
||||||
|
@ -133,7 +117,7 @@ def Delta_fit(xdata, thickness, interference_order):
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
xdata : tuple
|
xdata : tuple
|
||||||
(wavelengths, n)
|
(wavelengths, refractive_index)
|
||||||
thickness : array_like (or float)
|
thickness : array_like (or float)
|
||||||
Film thickness.
|
Film thickness.
|
||||||
interference_order : int
|
interference_order : int
|
||||||
|
@ -145,8 +129,8 @@ def Delta_fit(xdata, thickness, interference_order):
|
||||||
Delta values.
|
Delta values.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
lambdas, n = xdata
|
lambdas, r_index = xdata
|
||||||
return Delta(lambdas, thickness, interference_order, n)
|
return Delta(lambdas, thickness, interference_order, r_index)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -197,53 +181,60 @@ def thickness_from_scheludko(wavelengths,
|
||||||
r_index_masked = r_index[mask]
|
r_index_masked = r_index[mask]
|
||||||
intensities_masked = intensities[mask]
|
intensities_masked = intensities[mask]
|
||||||
|
|
||||||
|
|
||||||
min_ecart = np.inf
|
min_ecart = np.inf
|
||||||
best_m = None
|
best_m = None
|
||||||
meilleure_h = None
|
best_h = None
|
||||||
|
|
||||||
if plot:
|
if plot:
|
||||||
plt.figure(figsize=(10, 6),dpi =600)
|
plt.figure(figsize=(10, 6), dpi=300)
|
||||||
plt.ylabel(r'$h$ ($\mathrm{{nm}}$)')
|
plt.ylabel(r'$h$ ($\mathrm{{nm}}$)')
|
||||||
plt.xlabel(r'$\lambda$ ($ \mathrm{nm} $)')
|
plt.xlabel(r'$\lambda$ ($ \mathrm{nm} $)')
|
||||||
|
|
||||||
|
|
||||||
for m in range(0, max_tested_order+1):
|
for m in range(0, max_tested_order+1):
|
||||||
h_values = thickness_scheludko_at_order(wavelengths_masked, intensities_masked, m, r_index_masked)
|
h_values = thickness_scheludko_at_order(wavelengths_masked,
|
||||||
|
intensities_masked,
|
||||||
|
m, r_index_masked)
|
||||||
|
|
||||||
if plot:
|
ecart = np.max(h_values) - np.min(h_values)
|
||||||
plt.plot(wavelengths_masked, h_values,'.', markersize=3, label=f"Épaisseur du film (Scheludko, m={m})")
|
|
||||||
ecart = np.max(h_values)-np.min(h_values)
|
|
||||||
|
|
||||||
print(f"Écart pour m={m} : {ecart:.3f} nm")
|
print(f"Écart pour m={m} : {ecart:.3f} nm")
|
||||||
|
|
||||||
if ecart < min_ecart:
|
if ecart < min_ecart:
|
||||||
min_ecart = ecart
|
min_ecart = ecart
|
||||||
best_m = m
|
best_m = m
|
||||||
meilleure_h = h_values
|
best_h = h_values
|
||||||
|
|
||||||
|
|
||||||
DeltaVrai = (intensities_masked -np.min(intensities_masked))/(np.max(intensities_masked) -np.min(intensities_masked))
|
|
||||||
#DeltaVrai = (intensities_raw_masked -np.min(intensities_raw_masked))/(np.max(intensities_raw_masked) -np.min(intensities_raw_masked))
|
|
||||||
|
|
||||||
DeltaScheludko = Delta(wavelengths_masked, np.mean(meilleure_h), best_m, r_index_masked)
|
|
||||||
#print(np.mean(meilleure_h),np.std(meilleure_h))
|
|
||||||
|
|
||||||
if plot:
|
if plot:
|
||||||
plt.figure(figsize=(10, 6), dpi=600)
|
plt.plot(wavelengths_masked, h_values,'.', markersize=3, label=f"Épaisseur du film (Scheludko, m={m})")
|
||||||
plt.plot(wavelengths_masked, DeltaVrai,
|
|
||||||
'bo-', markersize=2, label=r'$\mathrm{{Smoothed}}\ \mathrm{{Data}}$')
|
|
||||||
plt.plot(wavelengths_masked, DeltaScheludko,
|
# Delta
|
||||||
'go-', markersize=2, label = rf'$\mathrm{{Scheludko}}\ (h = {np.mean(meilleure_h):.1f} \pm {np.std(meilleure_h):.1f}\ \mathrm{{nm}})$')
|
num = intensities_masked - np.min(intensities_masked)
|
||||||
|
denom = np.max(intensities_masked) - np.min(intensities_masked)
|
||||||
|
DeltaVrai = num / denom
|
||||||
|
|
||||||
|
# DeltaVrai = (intensities_masked -np.min(intensities_masked))/(np.max(intensities_masked) -np.min(intensities_masked))
|
||||||
|
# DeltaVrai = (intensities_raw_masked -np.min(intensities_raw_masked))/(np.max(intensities_raw_masked) -np.min(intensities_raw_masked))
|
||||||
|
|
||||||
|
DeltaScheludko = Delta(wavelengths_masked,
|
||||||
|
np.mean(best_h),
|
||||||
|
best_m,
|
||||||
|
r_index_masked)
|
||||||
|
|
||||||
|
|
||||||
xdata = (wavelengths_masked, r_index_masked)
|
xdata = (wavelengths_masked, r_index_masked)
|
||||||
popt, pcov = curve_fit(lambda x, h: Delta_fit(x, h, m), xdata, DeltaVrai, p0=[np.mean(meilleure_h)])
|
popt, pcov = curve_fit(lambda x, h: Delta_fit(x, h, m), xdata, DeltaVrai, p0=[np.mean(best_h)])
|
||||||
fitted_h = popt[0]
|
fitted_h = popt[0]
|
||||||
|
|
||||||
|
|
||||||
if plot:
|
if plot:
|
||||||
plt.plot(wavelengths_masked, Delta(wavelengths_masked, fitted_h, best_m, r_index_masked ), 'ro-',markersize=2, label=rf'$\mathrm{{Fit}}\ (h = {fitted_h:.1f}\pm {np.sqrt(pcov[0][0]):.1f} \ \mathrm{{nm}})$')
|
Delta_values = Delta(wavelengths_masked, fitted_h, best_m, r_index_masked)
|
||||||
|
|
||||||
|
plt.figure(figsize=(10, 6), dpi=300)
|
||||||
|
plt.plot(wavelengths_masked, DeltaVrai,
|
||||||
|
'bo-', markersize=2, label=r'$\mathrm{{Smoothed}}\ \mathrm{{Data}}$')
|
||||||
|
plt.plot(wavelengths_masked, DeltaScheludko,
|
||||||
|
'go-', markersize=2, label = rf'$\mathrm{{Scheludko}}\ (h = {np.mean(best_h):.1f} \pm {np.std(best_h):.1f}\ \mathrm{{nm}})$')
|
||||||
|
plt.plot(wavelengths_masked, Delta_values, 'ro-',markersize=2, label=rf'$\mathrm{{Fit}}\ (h = {fitted_h:.1f}\pm {np.sqrt(pcov[0][0]):.1f} \ \mathrm{{nm}})$')
|
||||||
plt.legend()
|
plt.legend()
|
||||||
plt.ylabel(r'$\Delta$')
|
plt.ylabel(r'$\Delta$')
|
||||||
plt.xlabel(r'$\lambda$ ($ \mathrm{nm} $)')
|
plt.xlabel(r'$\lambda$ ($ \mathrm{nm} $)')
|
||||||
|
@ -258,8 +249,11 @@ def thickness_for_order0(wavelengths,
|
||||||
min_peak_prominence,
|
min_peak_prominence,
|
||||||
plot=None):
|
plot=None):
|
||||||
|
|
||||||
|
# TODO :
|
||||||
|
# Load "trou"
|
||||||
File_I_min = 'tests/spectre_trou/000043641.xy'
|
File_I_min = 'tests/spectre_trou/000043641.xy'
|
||||||
|
wavelengths_I_min, intensities_I_min = load_spectrum(File_I_min, lambda_min=450)
|
||||||
|
|
||||||
r_index = refractive_index
|
r_index = refractive_index
|
||||||
|
|
||||||
peaks_min, peaks_max = finds_peak(wavelengths, intensities,
|
peaks_min, peaks_max = finds_peak(wavelengths, intensities,
|
||||||
|
@ -268,9 +262,6 @@ def thickness_for_order0(wavelengths,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
wavelengths_I_min, intensities_I_min = load_spectrum(File_I_min, lambda_min=450)
|
|
||||||
|
|
||||||
lambda_unique = wavelengths[peaks_max[0]]
|
lambda_unique = wavelengths[peaks_max[0]]
|
||||||
|
|
||||||
|
|
||||||
|
@ -281,9 +272,8 @@ def thickness_for_order0(wavelengths,
|
||||||
intensities_masked = intensities[mask]
|
intensities_masked = intensities[mask]
|
||||||
intensities_I_min_masked =intensities_I_min[mask]
|
intensities_I_min_masked =intensities_I_min[mask]
|
||||||
|
|
||||||
min_ecart = np.inf
|
# best_m = None
|
||||||
best_m = None
|
# best_h = None
|
||||||
meilleure_h = None
|
|
||||||
|
|
||||||
|
|
||||||
m = 0
|
m = 0
|
||||||
|
@ -294,37 +284,38 @@ def thickness_for_order0(wavelengths,
|
||||||
Imin=intensities_I_min_masked)
|
Imin=intensities_I_min_masked)
|
||||||
|
|
||||||
if plot:
|
if plot:
|
||||||
plt.figure(figsize=(10, 6), dpi=600)
|
plt.figure(figsize=(10, 6), dpi=300)
|
||||||
plt.plot(wavelengths_masked, h_values, label=r"Épaisseur du film (Scheludko, m=0)")
|
plt.plot(wavelengths_masked, h_values, label=r"Épaisseur du film (Scheludko, m=0)")
|
||||||
|
|
||||||
ecart = np.max(h_values) - np.min(h_values)
|
|
||||||
best_m = m
|
best_m = m
|
||||||
meilleure_h = h_values
|
best_h = h_values
|
||||||
|
|
||||||
|
# Delta
|
||||||
|
num = intensities_masked - np.min(intensities_I_min_masked)
|
||||||
|
denom = np.max(intensities_masked) - np.min(intensities_I_min_masked)
|
||||||
|
DeltaVrai = num / denom
|
||||||
|
|
||||||
|
DeltaScheludko = Delta(wavelengths_masked, np.mean(best_h), best_m, r_index_masked)
|
||||||
DeltaVrai = (intensities_masked -np.min(intensities_I_min_masked))/(np.max(intensities_masked) -np.min(intensities_I_min_masked))
|
#print(np.mean(best_h),np.std(best_h))
|
||||||
|
|
||||||
#DeltaVrai = (intensities_masked -np.min(intensities_masked))/(np.max(intensities_masked) -np.min(intensities_masked))
|
|
||||||
|
|
||||||
DeltaScheludko = Delta(wavelengths_masked, np.mean(meilleure_h), best_m, r_index_masked)
|
|
||||||
#print(np.mean(meilleure_h),np.std(meilleure_h))
|
|
||||||
|
|
||||||
|
|
||||||
if plot:
|
if plot:
|
||||||
plt.figure(figsize=(10, 6), dpi=600)
|
plt.figure(figsize=(10, 6), dpi=300)
|
||||||
plt.plot(wavelengths_masked,DeltaVrai,'bo-', markersize=2,label=r'$\mathrm{{Raw}}\ \mathrm{{Data}}$')
|
plt.plot(wavelengths_masked,DeltaVrai,'bo-', markersize=2,label=r'$\mathrm{{Raw}}\ \mathrm{{Data}}$')
|
||||||
plt.plot(wavelengths_masked,DeltaScheludko,'ro-', markersize=2,label = rf'$\mathrm{{Scheludko}}\ (h = {np.mean(meilleure_h):.1f} \pm {np.std(meilleure_h):.1f}\ \mathrm{{nm}})$')
|
plt.plot(wavelengths_masked,DeltaScheludko,'ro-', markersize=2,label = rf'$\mathrm{{Scheludko}}\ (h = {np.mean(best_h):.1f} \pm {np.std(best_h):.1f}\ \mathrm{{nm}})$')
|
||||||
|
|
||||||
|
|
||||||
xdata = (wavelengths_masked, r_index_masked)
|
xdata = (wavelengths_masked, r_index_masked)
|
||||||
popt, pcov = curve_fit(lambda x, h: Delta_fit(x, h, m), xdata, DeltaVrai, p0=[np.mean(meilleure_h)])
|
popt, pcov = curve_fit(lambda x, h: Delta_fit(x, h, m), xdata, DeltaVrai, p0=[np.mean(best_h)])
|
||||||
fitted_h = popt[0]
|
fitted_h = popt[0]
|
||||||
|
|
||||||
if plot:
|
if plot:
|
||||||
plt.plot(wavelengths_masked, Delta(wavelengths_masked, fitted_h, best_m, r_index_masked ), 'go-',markersize=2, label=rf'$\mathrm{{Fit}}\ (h = {fitted_h:.1f}\pm {np.sqrt(pcov[0][0]):.1f} \ \mathrm{{nm}})$')
|
Delta_values = Delta(wavelengths_masked, fitted_h, best_m, r_index_masked)
|
||||||
|
plt.plot(wavelengths_masked, Delta_values,
|
||||||
|
'go-', markersize=2,
|
||||||
|
label=rf'$\mathrm{{Fit}}\ (h = {fitted_h:.1f}\pm {np.sqrt(pcov[0][0]):.1f} \ \mathrm{{nm}})$')
|
||||||
plt.legend()
|
plt.legend()
|
||||||
plt.ylabel(r'$\Delta$')
|
plt.ylabel(r'$\Delta$')
|
||||||
plt.xlabel(r'$\lambda$ (nm)')
|
plt.xlabel(r'$\lambda$ (nm)')
|
||||||
|
|
||||||
return OptimizeResult(thickness=fitted_h ,)
|
return OptimizeResult(thickness=fitted_h,)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue