simplify finds_peak
This commit is contained in:
parent
022966608a
commit
56aac01151
6 changed files with 66 additions and 88 deletions
15
check.py
15
check.py
|
@ -61,13 +61,16 @@ def check_SV1():
|
||||||
|
|
||||||
spectre_file = os.path.join(DATA_FOLDER, fn)
|
spectre_file = os.path.join(DATA_FOLDER, fn)
|
||||||
|
|
||||||
##### Affichage du spectre brut et récupération des Intesités brutes#####
|
lambdas, raw_intensities = load_spectrum(spectre_file, lambda_min=450)
|
||||||
|
|
||||||
raw_intensities = plot_xy(spectre_file)
|
|
||||||
|
|
||||||
##### Affichage du spectre lissé #####
|
##### Affichage du spectre lissé #####
|
||||||
|
|
||||||
|
#smoothed_intensities, intensities, lambdas = Data_Smoothed(spectre_file)
|
||||||
|
|
||||||
|
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||||
|
|
||||||
smoothed_intensities, intensities, lambdas = Data_Smoothed(spectre_file)
|
|
||||||
|
# smoothed_intensities, intensities, lambdas = Data_Smoothed(spectre_file)
|
||||||
|
|
||||||
##### Indice Optique en fonction de Lambda #####
|
##### Indice Optique en fonction de Lambda #####
|
||||||
|
|
||||||
|
@ -97,4 +100,4 @@ def check_SV1():
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
check_basic()
|
check_basic()
|
||||||
#check_SV1()
|
check_SV1()
|
||||||
|
|
|
@ -48,14 +48,7 @@ def plot_xy(file_path, plot=True):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def finds_peak(lambdas, intensities, min_peak_prominence, min_peak_distance=10, plot=None):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def finds_peak(filename, min_peak_prominence, min_peak_distance=10, plot=None):
|
|
||||||
"""
|
"""
|
||||||
Charge un fichier .xy et affiche les données avec les extrema détectés (minima et maxima).
|
Charge un fichier .xy et affiche les données avec les extrema détectés (minima et maxima).
|
||||||
|
|
||||||
|
@ -68,10 +61,11 @@ def finds_peak(filename, min_peak_prominence, min_peak_distance=10, plot=None):
|
||||||
min_peak_distance : float
|
min_peak_distance : float
|
||||||
Distance minimale entre les pics.
|
Distance minimale entre les pics.
|
||||||
"""
|
"""
|
||||||
# Charger et lisser les données
|
|
||||||
lambdas, intensities = load_spectrum(filename, lambda_min=450)
|
smoothed_intensities = intensities
|
||||||
WIN_SIZE = 11
|
|
||||||
smoothed_intensities = savgol_filter(intensities, WIN_SIZE, 3)
|
|
||||||
|
|
||||||
# Trouver les maxima et minima sur le signal lissé
|
# Trouver les maxima et minima sur le signal lissé
|
||||||
peaks_max, _ = find_peaks(smoothed_intensities, prominence=min_peak_prominence, distance=min_peak_distance)
|
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_min, _ = find_peaks(-smoothed_intensities, prominence=min_peak_prominence, distance=min_peak_distance)
|
||||||
|
@ -84,50 +78,29 @@ def finds_peak(filename, min_peak_prominence, min_peak_distance=10, plot=None):
|
||||||
plt.xlabel(r'$\lambda$ (nm)')
|
plt.xlabel(r'$\lambda$ (nm)')
|
||||||
plt.ylabel(r'$I^*$')
|
plt.ylabel(r'$I^*$')
|
||||||
plt.legend()
|
plt.legend()
|
||||||
plt.tight_layout()
|
plt.tight_layout()
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
# Nombre total d’extremums
|
# Nombre total d’extremums
|
||||||
total_extrema = len(peaks_max) + len(peaks_min)
|
total_extrema = len(peaks_max) + len(peaks_min)
|
||||||
if total_extrema >=15:
|
if total_extrema >= 15:
|
||||||
print('Number of extrema', total_extrema,'.')
|
print('Number of extrema', total_extrema,'.')
|
||||||
print('FFT method')
|
print('FFT method')
|
||||||
|
|
||||||
if total_extrema <=15 and total_extrema >4:
|
if total_extrema <= 15 and total_extrema > 4:
|
||||||
print('Number of extrema', total_extrema,'.')
|
print('Number of extrema', total_extrema,'.')
|
||||||
print('OOSpectro method')
|
print('OOSpectro method')
|
||||||
|
|
||||||
if total_extrema <=4:
|
if total_extrema <= 4:
|
||||||
print('Number of extrema', total_extrema,'.')
|
print('Number of extrema', total_extrema,'.')
|
||||||
print('Scheludko method')
|
print('Scheludko method')
|
||||||
|
|
||||||
return total_extrema, smoothed_intensities, intensities, lambdas, peaks_min, peaks_max
|
return total_extrema, peaks_min, peaks_max
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def smooth_intensities(intensities):
|
||||||
|
|
||||||
def Data_Smoothed(filename):
|
|
||||||
"""
|
|
||||||
Charge un fichier .xy et affiche les données avec les extrema détectés (minima et maxima).
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
filename : str
|
|
||||||
Chemin vers le fichier .xy (2 colonnes : lambda et intensité).
|
|
||||||
min_peak_prominence : float
|
|
||||||
Importance minimale des pics.
|
|
||||||
min_peak_distance : float
|
|
||||||
Distance minimale entre les pics.
|
|
||||||
"""
|
|
||||||
# Charger et lisser les données
|
|
||||||
lambdas, intensities = load_spectrum(filename, lambda_min=450)
|
|
||||||
WIN_SIZE = 11
|
WIN_SIZE = 11
|
||||||
smoothed_intensities = savgol_filter(intensities, WIN_SIZE, 3)
|
smoothed_intensities = savgol_filter(intensities, WIN_SIZE, 3)
|
||||||
|
return smoothed_intensities
|
||||||
return smoothed_intensities, intensities, lambdas
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,13 @@ def auto(DATA_FOLDER, FILE_NAME, plot=None):
|
||||||
|
|
||||||
##### Affichage du spectre brut et récupération des Intesités brutes#####
|
##### Affichage du spectre brut et récupération des Intesités brutes#####
|
||||||
|
|
||||||
raw_intensities = load_spectrum(spectre_file)
|
lambdas, raw_intensities = load_spectrum(spectre_file, lambda_min=450)
|
||||||
|
|
||||||
##### Affichage du spectre lissé #####
|
##### Affichage du spectre lissé #####
|
||||||
|
|
||||||
smoothed_intensities, intensities, lambdas = Data_Smoothed(spectre_file)
|
#smoothed_intensities, intensities, lambdas = Data_Smoothed(spectre_file)
|
||||||
|
|
||||||
|
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||||
|
|
||||||
##### Indice Optique en fonction de Lambda #####
|
##### Indice Optique en fonction de Lambda #####
|
||||||
|
|
||||||
|
@ -30,9 +32,9 @@ def auto(DATA_FOLDER, FILE_NAME, plot=None):
|
||||||
prominence = 0.03
|
prominence = 0.03
|
||||||
##### Find Peak #####
|
##### Find Peak #####
|
||||||
|
|
||||||
total_extrema, smoothed_intensities, raw_intensities, lambdas, peaks_min, peaks_max = finds_peak(spectre_file,
|
total_extrema, peaks_min, peaks_max = finds_peak(lambdas, smoothed_intensities,
|
||||||
min_peak_prominence=prominence,
|
min_peak_prominence=prominence,
|
||||||
plot=plot)
|
plot=plot)
|
||||||
|
|
||||||
##### Epaisseur selon la methode #####
|
##### Epaisseur selon la methode #####
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,9 @@ from numpy.testing import assert_allclose
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from optifik.minmax import thickness_from_minmax
|
from optifik.minmax import thickness_from_minmax
|
||||||
from optifik.analysis import Data_Smoothed
|
|
||||||
from optifik.analysis import finds_peak
|
|
||||||
from optifik.io import load_spectrum
|
from optifik.io import load_spectrum
|
||||||
|
from optifik.analysis import smooth_intensities
|
||||||
|
from optifik.analysis import finds_peak
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
@ -21,17 +21,17 @@ def load():
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("spectrum, expected", load())
|
@pytest.mark.parametrize("spectrum_path, expected", load())
|
||||||
def test_minmax(spectrum, expected):
|
def test_minmax(spectrum_path, expected):
|
||||||
raw_intensities = load_spectrum(spectrum)
|
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||||
|
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||||
smoothed_intensities, intensities, lambdas = Data_Smoothed(spectrum)
|
|
||||||
|
|
||||||
indice = 1.324188 + 3102.060378 / (lambdas**2)
|
indice = 1.324188 + 3102.060378 / (lambdas**2)
|
||||||
prominence = 0.02
|
prominence = 0.02
|
||||||
|
|
||||||
total_extrema, smoothed_intensities, raw_intensities, lambdas, peaks_min, peaks_max = finds_peak(spectrum,
|
total_extrema, peaks_min, peaks_max = finds_peak(lambdas, smoothed_intensities,
|
||||||
min_peak_prominence=prominence)
|
min_peak_prominence=prominence,
|
||||||
|
plot=False)
|
||||||
|
|
||||||
thickness_minmax = thickness_from_minmax(lambdas,
|
thickness_minmax = thickness_from_minmax(lambdas,
|
||||||
smoothed_intensities,
|
smoothed_intensities,
|
||||||
|
|
|
@ -5,7 +5,7 @@ import pytest
|
||||||
|
|
||||||
from optifik.scheludko import thickness_from_scheludko
|
from optifik.scheludko import thickness_from_scheludko
|
||||||
from optifik.io import load_spectrum
|
from optifik.io import load_spectrum
|
||||||
from optifik.analysis import Data_Smoothed
|
from optifik.analysis import smooth_intensities
|
||||||
from optifik.analysis import finds_peak
|
from optifik.analysis import finds_peak
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -21,17 +21,17 @@ def load():
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("spectrum, expected", load())
|
@pytest.mark.parametrize("spectrum_path, expected", load())
|
||||||
def test_minmax(spectrum, expected):
|
def test_minmax(spectrum_path, expected):
|
||||||
raw_intensities = load_spectrum(spectrum)
|
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||||
|
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||||
smoothed_intensities, intensities, lambdas = Data_Smoothed(spectrum)
|
|
||||||
|
|
||||||
refractive_index = 1.324188 + 3102.060378 / (lambdas**2)
|
refractive_index = 1.324188 + 3102.060378 / (lambdas**2)
|
||||||
prominence = 0.02
|
prominence = 0.02
|
||||||
|
|
||||||
total_extrema, smoothed_intensities, raw_intensities, lambdas, peaks_min, peaks_max = finds_peak(spectrum,
|
total_extrema, peaks_min, peaks_max = finds_peak(lambdas, smoothed_intensities,
|
||||||
min_peak_prominence=prominence)
|
min_peak_prominence=prominence,
|
||||||
|
plot=False)
|
||||||
|
|
||||||
thickness_scheludko = thickness_from_scheludko(lambdas,
|
thickness_scheludko = thickness_from_scheludko(lambdas,
|
||||||
smoothed_intensities,
|
smoothed_intensities,
|
||||||
|
|
|
@ -7,8 +7,7 @@ from optifik.analysis import thickness_from_fft
|
||||||
from optifik.analysis import thickness_from_minmax
|
from optifik.analysis import thickness_from_minmax
|
||||||
from optifik.analysis import thickness_from_scheludko
|
from optifik.analysis import thickness_from_scheludko
|
||||||
from optifik.analysis import thickness_for_order0
|
from optifik.analysis import thickness_for_order0
|
||||||
from optifik.analysis import plot_xy
|
from optifik.analysis import smooth_intensities
|
||||||
from optifik.analysis import Data_Smoothed
|
|
||||||
from optifik.analysis import Prominence_from_fft
|
from optifik.analysis import Prominence_from_fft
|
||||||
from optifik.analysis import finds_peak
|
from optifik.analysis import finds_peak
|
||||||
from optifik.io import load_spectrum
|
from optifik.io import load_spectrum
|
||||||
|
@ -20,8 +19,8 @@ def test_FFT():
|
||||||
expected = 3524.51
|
expected = 3524.51
|
||||||
|
|
||||||
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
||||||
raw_intensities = load_spectrum(spectrum_path)
|
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||||
smoothed_intensities, intensities, lambdas = Data_Smoothed(spectrum_path)
|
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||||
indice = 1.324188 + 3102.060378 / (lambdas**2)
|
indice = 1.324188 + 3102.060378 / (lambdas**2)
|
||||||
|
|
||||||
thickness_FFT = thickness_from_fft(lambdas,
|
thickness_FFT = thickness_from_fft(lambdas,
|
||||||
|
@ -37,8 +36,8 @@ def test_minmax_ransac():
|
||||||
expected = 1338.35
|
expected = 1338.35
|
||||||
|
|
||||||
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
||||||
raw_intensities = load_spectrum(spectrum_path)
|
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||||
smoothed_intensities, intensities, lambdas = Data_Smoothed(spectrum_path)
|
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||||
indice = 1.324188 + 3102.060378 / (lambdas**2)
|
indice = 1.324188 + 3102.060378 / (lambdas**2)
|
||||||
|
|
||||||
prominence = Prominence_from_fft(lambdas=lambdas,
|
prominence = Prominence_from_fft(lambdas=lambdas,
|
||||||
|
@ -64,14 +63,15 @@ def test_scheludko_4peaks():
|
||||||
expected = 777.07
|
expected = 777.07
|
||||||
|
|
||||||
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
||||||
raw_intensities = load_spectrum(spectrum_path)
|
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||||
smoothed_intensities, intensities, lambdas = Data_Smoothed(spectrum_path)
|
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||||
indice = 1.324188 + 3102.060378 / (lambdas**2)
|
indice = 1.324188 + 3102.060378 / (lambdas**2)
|
||||||
|
|
||||||
prominence = Prominence_from_fft(lambdas=lambdas, intensities=smoothed_intensities, refractive_index=indice, plot=False)
|
prominence = Prominence_from_fft(lambdas=lambdas, intensities=smoothed_intensities, refractive_index=indice, plot=False)
|
||||||
|
|
||||||
total_extrema, smoothed_intensities, raw_intensities, lambdas, peaks_min, peaks_max = finds_peak(spectrum_path,
|
total_extrema, peaks_min, peaks_max = finds_peak(lambdas, smoothed_intensities,
|
||||||
min_peak_prominence=prominence)
|
min_peak_prominence=prominence,
|
||||||
|
plot=False)
|
||||||
|
|
||||||
|
|
||||||
result = thickness_from_scheludko(lambdas, smoothed_intensities,
|
result = thickness_from_scheludko(lambdas, smoothed_intensities,
|
||||||
|
@ -89,15 +89,15 @@ def test_scheludko_2peaks():
|
||||||
expected = 495.69
|
expected = 495.69
|
||||||
|
|
||||||
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
||||||
raw_intensities = load_spectrum(spectrum_path)
|
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||||
smoothed_intensities, intensities, lambdas = Data_Smoothed(spectrum_path)
|
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||||
indice = 1.324188 + 3102.060378 / (lambdas**2)
|
indice = 1.324188 + 3102.060378 / (lambdas**2)
|
||||||
|
|
||||||
prominence = 0.03
|
prominence = 0.03
|
||||||
|
|
||||||
total_extrema, smoothed_intensities, raw_intensities, lambdas, peaks_min, peaks_max = finds_peak(spectrum_path,
|
total_extrema, peaks_min, peaks_max = finds_peak(lambdas, smoothed_intensities,
|
||||||
min_peak_prominence=prominence)
|
min_peak_prominence=prominence,
|
||||||
|
plot=False)
|
||||||
|
|
||||||
result = thickness_from_scheludko(lambdas, smoothed_intensities,
|
result = thickness_from_scheludko(lambdas, smoothed_intensities,
|
||||||
peaks_min, peaks_max,
|
peaks_min, peaks_max,
|
||||||
|
@ -116,15 +116,15 @@ def test_order0():
|
||||||
expected = 115.33
|
expected = 115.33
|
||||||
|
|
||||||
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
||||||
raw_intensities = load_spectrum(spectrum_path)
|
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||||
smoothed_intensities, intensities, lambdas = Data_Smoothed(spectrum_path)
|
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||||
indice = 1.324188 + 3102.060378 / (lambdas**2)
|
indice = 1.324188 + 3102.060378 / (lambdas**2)
|
||||||
|
|
||||||
prominence = 0.03
|
prominence = 0.03
|
||||||
|
|
||||||
total_extrema, smoothed_intensities, raw_intensities, lambdas, peaks_min, peaks_max = finds_peak(spectrum_path,
|
total_extrema, peaks_min, peaks_max = finds_peak(lambdas, smoothed_intensities,
|
||||||
min_peak_prominence=prominence)
|
min_peak_prominence=prominence,
|
||||||
|
plot=False)
|
||||||
|
|
||||||
result = thickness_for_order0(lambdas, smoothed_intensities,
|
result = thickness_for_order0(lambdas, smoothed_intensities,
|
||||||
peaks_min, peaks_max,
|
peaks_min, peaks_max,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue