simplify finds_peak
This commit is contained in:
parent
022966608a
commit
56aac01151
6 changed files with 66 additions and 88 deletions
13
check.py
13
check.py
|
@ -61,13 +61,16 @@ def check_SV1():
|
|||
|
||||
spectre_file = os.path.join(DATA_FOLDER, fn)
|
||||
|
||||
##### Affichage du spectre brut et récupération des Intesités brutes#####
|
||||
|
||||
raw_intensities = plot_xy(spectre_file)
|
||||
lambdas, raw_intensities = load_spectrum(spectre_file, lambda_min=450)
|
||||
|
||||
##### 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)
|
||||
|
||||
|
||||
# smoothed_intensities, intensities, lambdas = Data_Smoothed(spectre_file)
|
||||
|
||||
##### Indice Optique en fonction de Lambda #####
|
||||
|
||||
|
@ -97,4 +100,4 @@ def check_SV1():
|
|||
if __name__ == '__main__':
|
||||
|
||||
check_basic()
|
||||
#check_SV1()
|
||||
check_SV1()
|
||||
|
|
|
@ -48,14 +48,7 @@ def plot_xy(file_path, plot=True):
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def finds_peak(filename, min_peak_prominence, min_peak_distance=10, plot=None):
|
||||
def finds_peak(lambdas, intensities, 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).
|
||||
|
||||
|
@ -68,10 +61,11 @@ def finds_peak(filename, min_peak_prominence, min_peak_distance=10, plot=None):
|
|||
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
|
||||
smoothed_intensities = savgol_filter(intensities, WIN_SIZE, 3)
|
||||
|
||||
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)
|
||||
|
@ -89,45 +83,24 @@ def finds_peak(filename, min_peak_prominence, min_peak_distance=10, plot=None):
|
|||
|
||||
# Nombre total d’extremums
|
||||
total_extrema = len(peaks_max) + len(peaks_min)
|
||||
if total_extrema >=15:
|
||||
if total_extrema >= 15:
|
||||
print('Number of extrema', total_extrema,'.')
|
||||
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('OOSpectro method')
|
||||
|
||||
if total_extrema <=4:
|
||||
if total_extrema <= 4:
|
||||
print('Number of extrema', total_extrema,'.')
|
||||
print('Scheludko method')
|
||||
|
||||
return total_extrema, smoothed_intensities, intensities, lambdas, peaks_min, peaks_max
|
||||
return total_extrema, peaks_min, peaks_max
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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)
|
||||
def smooth_intensities(intensities):
|
||||
WIN_SIZE = 11
|
||||
smoothed_intensities = savgol_filter(intensities, WIN_SIZE, 3)
|
||||
|
||||
return smoothed_intensities, intensities, lambdas
|
||||
|
||||
|
||||
|
||||
|
||||
return smoothed_intensities
|
||||
|
||||
|
|
|
@ -10,11 +10,13 @@ def auto(DATA_FOLDER, FILE_NAME, plot=None):
|
|||
|
||||
##### 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é #####
|
||||
|
||||
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 #####
|
||||
|
||||
|
@ -30,7 +32,7 @@ def auto(DATA_FOLDER, FILE_NAME, plot=None):
|
|||
prominence = 0.03
|
||||
##### 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,
|
||||
plot=plot)
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@ from numpy.testing import assert_allclose
|
|||
import pytest
|
||||
|
||||
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.analysis import smooth_intensities
|
||||
from optifik.analysis import finds_peak
|
||||
|
||||
import yaml
|
||||
|
||||
|
@ -21,17 +21,17 @@ def load():
|
|||
return data
|
||||
|
||||
|
||||
@pytest.mark.parametrize("spectrum, expected", load())
|
||||
def test_minmax(spectrum, expected):
|
||||
raw_intensities = load_spectrum(spectrum)
|
||||
|
||||
smoothed_intensities, intensities, lambdas = Data_Smoothed(spectrum)
|
||||
@pytest.mark.parametrize("spectrum_path, expected", load())
|
||||
def test_minmax(spectrum_path, expected):
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
|
||||
indice = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
prominence = 0.02
|
||||
|
||||
total_extrema, smoothed_intensities, raw_intensities, lambdas, peaks_min, peaks_max = finds_peak(spectrum,
|
||||
min_peak_prominence=prominence)
|
||||
total_extrema, peaks_min, peaks_max = finds_peak(lambdas, smoothed_intensities,
|
||||
min_peak_prominence=prominence,
|
||||
plot=False)
|
||||
|
||||
thickness_minmax = thickness_from_minmax(lambdas,
|
||||
smoothed_intensities,
|
||||
|
|
|
@ -5,7 +5,7 @@ import pytest
|
|||
|
||||
from optifik.scheludko import thickness_from_scheludko
|
||||
from optifik.io import load_spectrum
|
||||
from optifik.analysis import Data_Smoothed
|
||||
from optifik.analysis import smooth_intensities
|
||||
from optifik.analysis import finds_peak
|
||||
|
||||
import yaml
|
||||
|
@ -21,17 +21,17 @@ def load():
|
|||
return data
|
||||
|
||||
|
||||
@pytest.mark.parametrize("spectrum, expected", load())
|
||||
def test_minmax(spectrum, expected):
|
||||
raw_intensities = load_spectrum(spectrum)
|
||||
|
||||
smoothed_intensities, intensities, lambdas = Data_Smoothed(spectrum)
|
||||
@pytest.mark.parametrize("spectrum_path, expected", load())
|
||||
def test_minmax(spectrum_path, expected):
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
|
||||
refractive_index = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
prominence = 0.02
|
||||
|
||||
total_extrema, smoothed_intensities, raw_intensities, lambdas, peaks_min, peaks_max = finds_peak(spectrum,
|
||||
min_peak_prominence=prominence)
|
||||
total_extrema, peaks_min, peaks_max = finds_peak(lambdas, smoothed_intensities,
|
||||
min_peak_prominence=prominence,
|
||||
plot=False)
|
||||
|
||||
thickness_scheludko = thickness_from_scheludko(lambdas,
|
||||
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_scheludko
|
||||
from optifik.analysis import thickness_for_order0
|
||||
from optifik.analysis import plot_xy
|
||||
from optifik.analysis import Data_Smoothed
|
||||
from optifik.analysis import smooth_intensities
|
||||
from optifik.analysis import Prominence_from_fft
|
||||
from optifik.analysis import finds_peak
|
||||
from optifik.io import load_spectrum
|
||||
|
@ -20,8 +19,8 @@ def test_FFT():
|
|||
expected = 3524.51
|
||||
|
||||
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
||||
raw_intensities = load_spectrum(spectrum_path)
|
||||
smoothed_intensities, intensities, lambdas = Data_Smoothed(spectrum_path)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
indice = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
|
||||
thickness_FFT = thickness_from_fft(lambdas,
|
||||
|
@ -37,8 +36,8 @@ def test_minmax_ransac():
|
|||
expected = 1338.35
|
||||
|
||||
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
||||
raw_intensities = load_spectrum(spectrum_path)
|
||||
smoothed_intensities, intensities, lambdas = Data_Smoothed(spectrum_path)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
indice = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
|
||||
prominence = Prominence_from_fft(lambdas=lambdas,
|
||||
|
@ -64,14 +63,15 @@ def test_scheludko_4peaks():
|
|||
expected = 777.07
|
||||
|
||||
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
||||
raw_intensities = load_spectrum(spectrum_path)
|
||||
smoothed_intensities, intensities, lambdas = Data_Smoothed(spectrum_path)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
indice = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
|
||||
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,
|
||||
min_peak_prominence=prominence)
|
||||
total_extrema, peaks_min, peaks_max = finds_peak(lambdas, smoothed_intensities,
|
||||
min_peak_prominence=prominence,
|
||||
plot=False)
|
||||
|
||||
|
||||
result = thickness_from_scheludko(lambdas, smoothed_intensities,
|
||||
|
@ -89,15 +89,15 @@ def test_scheludko_2peaks():
|
|||
expected = 495.69
|
||||
|
||||
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
||||
raw_intensities = load_spectrum(spectrum_path)
|
||||
smoothed_intensities, intensities, lambdas = Data_Smoothed(spectrum_path)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
indice = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
|
||||
prominence = 0.03
|
||||
|
||||
total_extrema, smoothed_intensities, raw_intensities, lambdas, peaks_min, peaks_max = finds_peak(spectrum_path,
|
||||
min_peak_prominence=prominence)
|
||||
|
||||
total_extrema, peaks_min, peaks_max = finds_peak(lambdas, smoothed_intensities,
|
||||
min_peak_prominence=prominence,
|
||||
plot=False)
|
||||
|
||||
result = thickness_from_scheludko(lambdas, smoothed_intensities,
|
||||
peaks_min, peaks_max,
|
||||
|
@ -116,15 +116,15 @@ def test_order0():
|
|||
expected = 115.33
|
||||
|
||||
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
||||
raw_intensities = load_spectrum(spectrum_path)
|
||||
smoothed_intensities, intensities, lambdas = Data_Smoothed(spectrum_path)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
indice = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
|
||||
prominence = 0.03
|
||||
|
||||
total_extrema, smoothed_intensities, raw_intensities, lambdas, peaks_min, peaks_max = finds_peak(spectrum_path,
|
||||
min_peak_prominence=prominence)
|
||||
|
||||
total_extrema, peaks_min, peaks_max = finds_peak(lambdas, smoothed_intensities,
|
||||
min_peak_prominence=prominence,
|
||||
plot=False)
|
||||
|
||||
result = thickness_for_order0(lambdas, smoothed_intensities,
|
||||
peaks_min, peaks_max,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue