include peak detection in scheludko
This commit is contained in:
parent
56aac01151
commit
ccd1f2c1f0
7 changed files with 100 additions and 82 deletions
|
@ -15,13 +15,23 @@ plt.rcParams.update({
|
|||
|
||||
from .io import load_spectrum
|
||||
from .fft import *
|
||||
from .scheludko import *
|
||||
from .minmax import *
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def plot_spectrum(lambdas, intensities, title=''):
|
||||
|
||||
plt.figure(figsize=(10, 6),dpi =600)
|
||||
plt.plot(lambdas, intensities, 'o-', markersize=2)
|
||||
plt.xlabel(r'$\lambda$ (nm)')
|
||||
plt.ylabel(r'$I^*$')
|
||||
plt.title(title)
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
def plot_xy(file_path, plot=True):
|
||||
try:
|
||||
|
@ -62,40 +72,26 @@ def finds_peak(lambdas, intensities, min_peak_prominence, min_peak_distance=10,
|
|||
Distance minimale entre les pics.
|
||||
"""
|
||||
|
||||
smoothed_intensities = intensities
|
||||
|
||||
|
||||
|
||||
# Trouver les maxima et minima sur le signal lissé
|
||||
peaks_max, _ = find_peaks(smoothed_intensities, prominence=min_peak_prominence, distance=min_peak_distance)
|
||||
peaks_min, _ = find_peaks(-smoothed_intensities, prominence=min_peak_prominence, distance=min_peak_distance)
|
||||
|
||||
peaks_max, _ = find_peaks(intensities, prominence=min_peak_prominence, distance=min_peak_distance)
|
||||
peaks_min, _ = find_peaks(-intensities, prominence=min_peak_prominence, distance=min_peak_distance)
|
||||
|
||||
if plot:
|
||||
plt.figure(figsize=(10, 6),dpi =600)
|
||||
plt.plot(lambdas, smoothed_intensities, 'o-', markersize=2, label="Smoothed data")
|
||||
plt.plot(lambdas[peaks_max], smoothed_intensities[peaks_max], 'ro')
|
||||
plt.plot(lambdas[peaks_min], smoothed_intensities[peaks_min], 'ro')
|
||||
plt.plot(lambdas, intensities, 'o-', markersize=2, label="Smoothed data")
|
||||
plt.plot(lambdas[peaks_max], intensities[peaks_max], 'ro')
|
||||
plt.plot(lambdas[peaks_min], intensities[peaks_min], 'ro')
|
||||
plt.xlabel(r'$\lambda$ (nm)')
|
||||
plt.ylabel(r'$I^*$')
|
||||
plt.legend()
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
|
||||
# Nombre total d’extremums
|
||||
total_extrema = len(peaks_max) + len(peaks_min)
|
||||
if total_extrema >= 15:
|
||||
print('Number of extrema', total_extrema,'.')
|
||||
print('FFT method')
|
||||
|
||||
if total_extrema <= 15 and total_extrema > 4:
|
||||
print('Number of extrema', total_extrema,'.')
|
||||
print('OOSpectro method')
|
||||
|
||||
if total_extrema <= 4:
|
||||
print('Number of extrema', total_extrema,'.')
|
||||
print('Scheludko method')
|
||||
|
||||
return total_extrema, peaks_min, peaks_max
|
||||
|
||||
return peaks_min, peaks_max
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -3,10 +3,10 @@ import os.path
|
|||
from .analysis import *
|
||||
from .io import load_spectrum
|
||||
|
||||
def auto(DATA_FOLDER, FILE_NAME, plot=None):
|
||||
def auto(spectrum_file, plot=None):
|
||||
|
||||
|
||||
spectre_file = os.path.join(DATA_FOLDER, FILE_NAME)
|
||||
spectre_file = spectrum_file
|
||||
|
||||
##### Affichage du spectre brut et récupération des Intesités brutes#####
|
||||
|
||||
|
@ -32,17 +32,20 @@ def auto(DATA_FOLDER, FILE_NAME, plot=None):
|
|||
prominence = 0.03
|
||||
##### Find Peak #####
|
||||
|
||||
total_extrema, peaks_min, peaks_max = finds_peak(lambdas, smoothed_intensities,
|
||||
peaks_min, peaks_max = finds_peak(lambdas, smoothed_intensities,
|
||||
min_peak_prominence=prominence,
|
||||
plot=plot)
|
||||
plot=False)
|
||||
|
||||
##### Epaisseur selon la methode #####
|
||||
|
||||
#thickness_FFT = thickness_from_fft(lambdas,smoothed_intensities,refractive_index=1.33)
|
||||
|
||||
|
||||
total_extrema = len(peaks_max) + len(peaks_min)
|
||||
|
||||
if total_extrema > 15 and total_extrema > 4:
|
||||
print('Apply method FFT')
|
||||
thickness_FFT = thickness_from_fft(lambdas,smoothed_intensities,
|
||||
thickness_FFT = thickness_from_fft(lambdas, smoothed_intensities,
|
||||
refractive_index=indice,
|
||||
plot=plot)
|
||||
thickness = thickness_FFT.thickness
|
||||
|
@ -51,7 +54,7 @@ def auto(DATA_FOLDER, FILE_NAME, plot=None):
|
|||
|
||||
if total_extrema <= 15 and total_extrema > 4:
|
||||
print('Apply method minmax')
|
||||
thickness_minmax = thickness_from_minmax(lambdas,smoothed_intensities,
|
||||
thickness_minmax = thickness_from_minmax(lambdas, smoothed_intensities,
|
||||
refractive_index=indice,
|
||||
min_peak_prominence=prominence,
|
||||
plot=plot)
|
||||
|
@ -61,8 +64,8 @@ def auto(DATA_FOLDER, FILE_NAME, plot=None):
|
|||
if total_extrema <= 4 and total_extrema >= 2: #& 2peak minimum:
|
||||
print('Apply method Scheludko')
|
||||
thickness = thickness_from_scheludko(lambdas, smoothed_intensities,
|
||||
peaks_min, peaks_max,
|
||||
refractive_index=indice,
|
||||
min_peak_prominence=prominence,
|
||||
plot=plot)
|
||||
print(f'thickness: {thickness:.2f} nm')
|
||||
|
||||
|
@ -70,8 +73,8 @@ def auto(DATA_FOLDER, FILE_NAME, plot=None):
|
|||
print('Apply method ordre0')
|
||||
|
||||
thickness = thickness_for_order0(lambdas, smoothed_intensities,
|
||||
peaks_min, peaks_max,
|
||||
refractive_index=indice,
|
||||
min_peak_prominence=prominence,
|
||||
plot=plot)
|
||||
|
||||
print(f'thickness: {thickness:.2f} nm')
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import numpy as np
|
||||
|
||||
from .io import load_spectrum
|
||||
|
||||
from scipy.optimize import curve_fit
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
@ -12,8 +12,9 @@ plt.rcParams.update({
|
|||
'legend.fontsize': 23,
|
||||
})
|
||||
|
||||
|
||||
from .io import load_spectrum
|
||||
from .utils import OptimizeResult
|
||||
from .analysis import finds_peak
|
||||
|
||||
def thickness_scheludko_at_order(wavelengths,
|
||||
intensity,
|
||||
|
@ -114,9 +115,8 @@ def Delta_fit(xdata, thickness, interference_order):
|
|||
|
||||
def thickness_from_scheludko(lambdas,
|
||||
smoothed_intensities,
|
||||
peaks_min,
|
||||
peaks_max,
|
||||
refractive_index,
|
||||
min_peak_prominence,
|
||||
plot=None):
|
||||
"""
|
||||
|
||||
|
@ -129,10 +129,6 @@ def thickness_from_scheludko(lambdas,
|
|||
DESCRIPTION.
|
||||
smoothed_intensities : TYPE
|
||||
DESCRIPTION.
|
||||
peaks_min : TYPE
|
||||
DESCRIPTION.
|
||||
peaks_max : TYPE
|
||||
DESCRIPTION.
|
||||
refractive_index : TYPE
|
||||
DESCRIPTION.
|
||||
plot : TYPE, optional
|
||||
|
@ -144,9 +140,13 @@ def thickness_from_scheludko(lambdas,
|
|||
DESCRIPTION.
|
||||
|
||||
"""
|
||||
|
||||
max_tested_order = 12
|
||||
r_index = refractive_index
|
||||
|
||||
peaks_min, peaks_max = finds_peak(lambdas, smoothed_intensities,
|
||||
min_peak_prominence=min_peak_prominence,
|
||||
plot=False)
|
||||
|
||||
|
||||
lambda_min = lambdas[peaks_min[-1]]
|
||||
lambda_max = lambdas[peaks_max[-1]]
|
||||
|
@ -169,11 +169,12 @@ def thickness_from_scheludko(lambdas,
|
|||
plt.ylabel(r'$h$ ($\mathrm{{nm}}$)')
|
||||
plt.xlabel(r'$\lambda$ ($ \mathrm{nm} $)')
|
||||
|
||||
for m in range(0, 9):
|
||||
|
||||
for m in range(0, max_tested_order+1):
|
||||
h_values = thickness_scheludko_at_order(lambdas_masked, intensities_masked, m, r_index_masked)
|
||||
|
||||
if plot:
|
||||
plt.plot(lambdas_masked, h_values,'.', markersize =3, label=f"Épaisseur du film (Scheludko, m={m})")
|
||||
plt.plot(lambdas_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")
|
||||
|
@ -213,15 +214,20 @@ def thickness_from_scheludko(lambdas,
|
|||
|
||||
def thickness_for_order0(lambdas,
|
||||
smoothed_intensities,
|
||||
peaks_min,
|
||||
peaks_max,
|
||||
refractive_index,
|
||||
min_peak_prominence,
|
||||
plot=None):
|
||||
|
||||
|
||||
File_I_min = 'tests/spectre_trou/000043641.xy'
|
||||
r_index = refractive_index
|
||||
|
||||
peaks_min, peaks_max = finds_peak(lambdas, smoothed_intensities,
|
||||
min_peak_prominence=min_peak_prominence,
|
||||
plot=False)
|
||||
|
||||
|
||||
|
||||
|
||||
lambdas_I_min, intensities_I_min = load_spectrum(File_I_min, lambda_min=450)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue