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)
|
||||
|
||||
|
||||
|
||||
"""
|
||||
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):
|
||||
"""
|
||||
|
||||
Compute the Delta values.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
@ -95,8 +80,8 @@ def Delta(wavelengths, thickness, interference_order, refractive_index):
|
|||
|
||||
Returns
|
||||
-------
|
||||
TYPE
|
||||
DESCRIPTION.
|
||||
ndarray
|
||||
Delta values.
|
||||
|
||||
"""
|
||||
|
||||
|
@ -125,7 +110,6 @@ def Delta(wavelengths, thickness, interference_order, refractive_index):
|
|||
return (A * (1 + alpha)) / (1 + A * alpha)
|
||||
|
||||
|
||||
|
||||
def Delta_fit(xdata, thickness, interference_order):
|
||||
"""
|
||||
Wrapper on Delta() for curve_fit.
|
||||
|
@ -133,7 +117,7 @@ def Delta_fit(xdata, thickness, interference_order):
|
|||
Parameters
|
||||
----------
|
||||
xdata : tuple
|
||||
(wavelengths, n)
|
||||
(wavelengths, refractive_index)
|
||||
thickness : array_like (or float)
|
||||
Film thickness.
|
||||
interference_order : int
|
||||
|
@ -145,8 +129,8 @@ def Delta_fit(xdata, thickness, interference_order):
|
|||
Delta values.
|
||||
|
||||
"""
|
||||
lambdas, n = xdata
|
||||
return Delta(lambdas, thickness, interference_order, n)
|
||||
lambdas, r_index = xdata
|
||||
return Delta(lambdas, thickness, interference_order, r_index)
|
||||
|
||||
|
||||
|
||||
|
@ -197,53 +181,60 @@ def thickness_from_scheludko(wavelengths,
|
|||
r_index_masked = r_index[mask]
|
||||
intensities_masked = intensities[mask]
|
||||
|
||||
|
||||
min_ecart = np.inf
|
||||
best_m = None
|
||||
meilleure_h = None
|
||||
best_h = None
|
||||
|
||||
if plot:
|
||||
plt.figure(figsize=(10, 6),dpi =600)
|
||||
plt.figure(figsize=(10, 6), dpi=300)
|
||||
plt.ylabel(r'$h$ ($\mathrm{{nm}}$)')
|
||||
plt.xlabel(r'$\lambda$ ($ \mathrm{nm} $)')
|
||||
|
||||
|
||||
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:
|
||||
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)
|
||||
ecart = np.max(h_values) - np.min(h_values)
|
||||
|
||||
print(f"Écart pour m={m} : {ecart:.3f} nm")
|
||||
|
||||
if ecart < min_ecart:
|
||||
min_ecart = ecart
|
||||
best_m = m
|
||||
meilleure_h = h_values
|
||||
best_h = h_values
|
||||
|
||||
if plot:
|
||||
plt.plot(wavelengths_masked, h_values,'.', markersize=3, label=f"Épaisseur du film (Scheludko, m={m})")
|
||||
|
||||
|
||||
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))
|
||||
# Delta
|
||||
num = intensities_masked - np.min(intensities_masked)
|
||||
denom = np.max(intensities_masked) - np.min(intensities_masked)
|
||||
DeltaVrai = num / denom
|
||||
|
||||
DeltaScheludko = Delta(wavelengths_masked, np.mean(meilleure_h), best_m, r_index_masked)
|
||||
#print(np.mean(meilleure_h),np.std(meilleure_h))
|
||||
# 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))
|
||||
|
||||
if plot:
|
||||
plt.figure(figsize=(10, 6), dpi=600)
|
||||
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(meilleure_h):.1f} \pm {np.std(meilleure_h):.1f}\ \mathrm{{nm}})$')
|
||||
DeltaScheludko = Delta(wavelengths_masked,
|
||||
np.mean(best_h),
|
||||
best_m,
|
||||
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]
|
||||
|
||||
|
||||
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.ylabel(r'$\Delta$')
|
||||
plt.xlabel(r'$\lambda$ ($ \mathrm{nm} $)')
|
||||
|
@ -258,19 +249,19 @@ def thickness_for_order0(wavelengths,
|
|||
min_peak_prominence,
|
||||
plot=None):
|
||||
|
||||
|
||||
# TODO :
|
||||
# Load "trou"
|
||||
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
|
||||
|
||||
peaks_min, peaks_max = finds_peak(wavelengths, intensities,
|
||||
min_peak_prominence=min_peak_prominence,
|
||||
plot=False)
|
||||
min_peak_prominence=min_peak_prominence,
|
||||
plot=False)
|
||||
|
||||
|
||||
|
||||
|
||||
wavelengths_I_min, intensities_I_min = load_spectrum(File_I_min, lambda_min=450)
|
||||
|
||||
lambda_unique = wavelengths[peaks_max[0]]
|
||||
|
||||
|
||||
|
@ -281,9 +272,8 @@ def thickness_for_order0(wavelengths,
|
|||
intensities_masked = intensities[mask]
|
||||
intensities_I_min_masked =intensities_I_min[mask]
|
||||
|
||||
min_ecart = np.inf
|
||||
best_m = None
|
||||
meilleure_h = None
|
||||
# best_m = None
|
||||
# best_h = None
|
||||
|
||||
|
||||
m = 0
|
||||
|
@ -294,37 +284,38 @@ def thickness_for_order0(wavelengths,
|
|||
Imin=intensities_I_min_masked)
|
||||
|
||||
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)")
|
||||
|
||||
ecart = np.max(h_values) - np.min(h_values)
|
||||
|
||||
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
|
||||
|
||||
|
||||
DeltaVrai = (intensities_masked -np.min(intensities_I_min_masked))/(np.max(intensities_masked) -np.min(intensities_I_min_masked))
|
||||
|
||||
#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))
|
||||
|
||||
DeltaScheludko = Delta(wavelengths_masked, np.mean(best_h), best_m, r_index_masked)
|
||||
#print(np.mean(best_h),np.std(best_h))
|
||||
|
||||
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,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)
|
||||
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]
|
||||
|
||||
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.ylabel(r'$\Delta$')
|
||||
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