mpl
This commit is contained in:
parent
31eeb53dea
commit
9e77fc8f03
8 changed files with 57 additions and 40 deletions
3
check.py
3
check.py
|
@ -211,6 +211,9 @@ def check_SV1():
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
from optifik.utils import is_latex_installed
|
||||||
|
print(is_latex_installed())
|
||||||
|
|
||||||
#check_basic()
|
#check_basic()
|
||||||
#check_SV1()
|
#check_SV1()
|
||||||
#play()
|
#play()
|
||||||
|
|
|
@ -10,11 +10,11 @@ plt.rcParams.update({
|
||||||
'legend.fontsize': 23,
|
'legend.fontsize': 23,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
from .utils import setup_matplotlib
|
||||||
|
|
||||||
def plot_spectrum(wavelengths, intensities, title=''):
|
def plot_spectrum(wavelengths, intensities, title=''):
|
||||||
|
setup_matplotlib()
|
||||||
plt.figure(figsize=(10, 6), dpi=300)
|
plt.figure()
|
||||||
plt.plot(wavelengths, intensities, 'o-', markersize=2)
|
plt.plot(wavelengths, intensities, 'o-', markersize=2)
|
||||||
plt.xlabel(r'$\lambda$ (nm)')
|
plt.xlabel(r'$\lambda$ (nm)')
|
||||||
plt.ylabel(r'$I^*$')
|
plt.ylabel(r'$I^*$')
|
||||||
|
@ -46,11 +46,14 @@ def finds_peak(wavelengths, intensities, min_peak_prominence, min_peak_distance=
|
||||||
(peaks_min, peaks_max)
|
(peaks_min, peaks_max)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if plot:
|
||||||
|
setup_matplotlib()
|
||||||
|
|
||||||
peaks_max, _ = find_peaks(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)
|
peaks_min, _ = find_peaks(-intensities, prominence=min_peak_prominence, distance=min_peak_distance)
|
||||||
|
|
||||||
if plot:
|
if plot:
|
||||||
plt.figure(figsize=(10, 6), dpi=300)
|
plt.figure()
|
||||||
plt.plot(wavelengths, intensities, 'o-', markersize=2, label="Smoothed data")
|
plt.plot(wavelengths, intensities, 'o-', markersize=2, label="Smoothed data")
|
||||||
plt.plot(wavelengths[peaks_max], intensities[peaks_max], 'ro')
|
plt.plot(wavelengths[peaks_max], intensities[peaks_max], 'ro')
|
||||||
plt.plot(wavelengths[peaks_min], intensities[peaks_min], 'ro')
|
plt.plot(wavelengths[peaks_min], intensities[peaks_min], 'ro')
|
||||||
|
|
|
@ -4,16 +4,8 @@ from scipy.fftpack import fft, ifft, fftfreq
|
||||||
|
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
plt.rc('text', usetex=True)
|
|
||||||
plt.rcParams.update({
|
|
||||||
'axes.labelsize': 26,
|
|
||||||
'xtick.labelsize': 32,
|
|
||||||
'ytick.labelsize': 32,
|
|
||||||
'legend.fontsize': 23,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
from .utils import OptimizeResult, setup_matplotlib
|
||||||
from .utils import OptimizeResult
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,6 +35,9 @@ def thickness_from_fft(wavelengths, intensities,
|
||||||
results : Instance of `OptimizeResult` class.
|
results : Instance of `OptimizeResult` class.
|
||||||
The attribute `thickness` gives the thickness value in nm.
|
The attribute `thickness` gives the thickness value in nm.
|
||||||
"""
|
"""
|
||||||
|
if plot:
|
||||||
|
setup_matplotlib()
|
||||||
|
|
||||||
if num_half_space is None:
|
if num_half_space is None:
|
||||||
num_half_space = 10 * len(wavelengths)
|
num_half_space = 10 * len(wavelengths)
|
||||||
|
|
||||||
|
@ -74,7 +69,7 @@ def thickness_from_fft(wavelengths, intensities,
|
||||||
thickness_fft = freq_max / 2.
|
thickness_fft = freq_max / 2.
|
||||||
|
|
||||||
if plot:
|
if plot:
|
||||||
plt.figure(figsize=(10, 6), dpi=300)
|
plt.figure()
|
||||||
plt.loglog(inverse_wavelengths_fft, np.abs(intensities_fft))
|
plt.loglog(inverse_wavelengths_fft, np.abs(intensities_fft))
|
||||||
plt.loglog(freq_max, np.abs(intensities_fft[idx_max_fft]), 'o')
|
plt.loglog(freq_max, np.abs(intensities_fft[idx_max_fft]), 'o')
|
||||||
plt.xlabel('Frequency')
|
plt.xlabel('Frequency')
|
||||||
|
@ -91,7 +86,7 @@ def thickness_from_fft(wavelengths, intensities,
|
||||||
#
|
#
|
||||||
# # # # 1. Spectre original
|
# # # # 1. Spectre original
|
||||||
# # if plot:
|
# # if plot:
|
||||||
# # plt.figure(figsize=(10, 6), dpi=150)
|
# # plt.figure()
|
||||||
# # plt.plot(1/wavelengths, intensities, label='Spectre original')
|
# # plt.plot(1/wavelengths, intensities, label='Spectre original')
|
||||||
# # plt.xlabel('1/Longueur d\'onde (nm-1)')
|
# # plt.xlabel('1/Longueur d\'onde (nm-1)')
|
||||||
# # plt.ylabel('Intensité')
|
# # plt.ylabel('Intensité')
|
||||||
|
@ -119,7 +114,7 @@ def thickness_from_fft(wavelengths, intensities,
|
||||||
# F_max = freqs_pos[idx_max]
|
# F_max = freqs_pos[idx_max]
|
||||||
#
|
#
|
||||||
# if plot:
|
# if plot:
|
||||||
# plt.figure(figsize=(10, 6), dpi=150)
|
# plt.figure()
|
||||||
# plt.plot(freqs_pos, abs_fft_pos, label='|FFT|')
|
# plt.plot(freqs_pos, abs_fft_pos, label='|FFT|')
|
||||||
# plt.axvline(F_max, color='r', linestyle='--', label='Pic principal')
|
# plt.axvline(F_max, color='r', linestyle='--', label='Pic principal')
|
||||||
# plt.xlabel('Distance optique [nm]')
|
# plt.xlabel('Distance optique [nm]')
|
||||||
|
@ -153,7 +148,7 @@ def thickness_from_fft(wavelengths, intensities,
|
||||||
#
|
#
|
||||||
# # 9. Affichage reconstruction
|
# # 9. Affichage reconstruction
|
||||||
# if plot:
|
# if plot:
|
||||||
# plt.figure(figsize=(10, 6), dpi=150)
|
# plt.figure()
|
||||||
# plt.plot(lambda_reconstructed, intensities_k, '--', label='Original interpolé')
|
# plt.plot(lambda_reconstructed, intensities_k, '--', label='Original interpolé')
|
||||||
# plt.plot(lambda_reconstructed, signal_filtered_HF,'--', color='gray')
|
# plt.plot(lambda_reconstructed, signal_filtered_HF,'--', color='gray')
|
||||||
#
|
#
|
||||||
|
|
|
@ -5,15 +5,8 @@ from skimage.measure import ransac, LineModelND
|
||||||
from scipy.signal import find_peaks
|
from scipy.signal import find_peaks
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
plt.rc('text', usetex=True)
|
|
||||||
plt.rcParams.update({
|
|
||||||
'axes.labelsize': 26,
|
|
||||||
'xtick.labelsize': 32,
|
|
||||||
'ytick.labelsize': 32,
|
|
||||||
'legend.fontsize': 23,
|
|
||||||
})
|
|
||||||
|
|
||||||
from .utils import OptimizeResult
|
from .utils import OptimizeResult, setup_matplotlib
|
||||||
|
|
||||||
|
|
||||||
def thickness_from_minmax(wavelengths,
|
def thickness_from_minmax(wavelengths,
|
||||||
|
@ -56,6 +49,8 @@ def thickness_from_minmax(wavelengths,
|
||||||
see the documentation of `scipy.signal.find_peaks`. This function
|
see the documentation of `scipy.signal.find_peaks`. This function
|
||||||
is used to find extrema.
|
is used to find extrema.
|
||||||
"""
|
"""
|
||||||
|
if plot:
|
||||||
|
setup_matplotlib()
|
||||||
|
|
||||||
peaks_max, _ = find_peaks(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)
|
peaks_min, _ = find_peaks(-intensities, prominence=min_peak_prominence, distance=min_peak_distance)
|
||||||
|
@ -106,7 +101,7 @@ def thickness_from_minmax(wavelengths,
|
||||||
#slope = slransac.estimator_.coef_[0]
|
#slope = slransac.estimator_.coef_[0]
|
||||||
|
|
||||||
if plot:
|
if plot:
|
||||||
fig, ax = plt.subplots(figsize=(10, 6), dpi=600)
|
fig, ax = plt.subplots()
|
||||||
|
|
||||||
ax.set_xlabel('extremum n°')
|
ax.set_xlabel('extremum n°')
|
||||||
ax.set_ylabel('$n$($\lambda$) / $\lambda$')
|
ax.set_ylabel('$n$($\lambda$) / $\lambda$')
|
||||||
|
@ -133,7 +128,7 @@ def thickness_from_minmax(wavelengths,
|
||||||
thickness_minmax = 1 / slope / 4
|
thickness_minmax = 1 / slope / 4
|
||||||
|
|
||||||
if plot:
|
if plot:
|
||||||
fig, ax = plt.subplots(figsize=(8, 6))
|
fig, ax = plt.subplots()
|
||||||
|
|
||||||
ax.set_xlabel('extremum n°')
|
ax.set_xlabel('extremum n°')
|
||||||
ax.set_ylabel('1 / $\lambda$')
|
ax.set_ylabel('1 / $\lambda$')
|
||||||
|
|
|
@ -2,16 +2,9 @@ import numpy as np
|
||||||
from scipy.optimize import curve_fit
|
from scipy.optimize import curve_fit
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
plt.rc('text', usetex=True)
|
|
||||||
plt.rcParams.update({
|
|
||||||
'axes.labelsize': 26,
|
|
||||||
'xtick.labelsize': 32,
|
|
||||||
'ytick.labelsize': 32,
|
|
||||||
'legend.fontsize': 23,
|
|
||||||
})
|
|
||||||
|
|
||||||
from .io import load_spectrum
|
from .io import load_spectrum
|
||||||
from .utils import OptimizeResult
|
from .utils import OptimizeResult, setup_matplotlib
|
||||||
from .analysis import finds_peak
|
from .analysis import finds_peak
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,6 +153,9 @@ def thickness_from_scheludko(wavelengths,
|
||||||
DESCRIPTION.
|
DESCRIPTION.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if plot:
|
||||||
|
setup_matplotlib()
|
||||||
|
|
||||||
max_tested_order = 12
|
max_tested_order = 12
|
||||||
r_index = refractive_index
|
r_index = refractive_index
|
||||||
|
|
||||||
|
@ -196,7 +192,7 @@ def thickness_from_scheludko(wavelengths,
|
||||||
best_h_values = None
|
best_h_values = None
|
||||||
|
|
||||||
if plot:
|
if plot:
|
||||||
plt.figure(figsize=(10, 6), dpi=300)
|
plt.figure()
|
||||||
plt.ylabel(r'$h$ ($\mathrm{{nm}}$)')
|
plt.ylabel(r'$h$ ($\mathrm{{nm}}$)')
|
||||||
plt.xlabel(r'$\lambda$ ($ \mathrm{nm} $)')
|
plt.xlabel(r'$\lambda$ ($ \mathrm{nm} $)')
|
||||||
|
|
||||||
|
@ -242,7 +238,7 @@ def thickness_from_scheludko(wavelengths,
|
||||||
if plot:
|
if plot:
|
||||||
Delta_values = Delta(wavelengths_masked, fitted_h, best_m, r_index_masked)
|
Delta_values = Delta(wavelengths_masked, fitted_h, best_m, r_index_masked)
|
||||||
|
|
||||||
plt.figure(figsize=(10, 6), dpi=300)
|
plt.figure()
|
||||||
plt.plot(wavelengths_masked, DeltaVrai,
|
plt.plot(wavelengths_masked, DeltaVrai,
|
||||||
'bo-', markersize=2, label=r'$\mathrm{{Smoothed}}\ \mathrm{{Data}}$')
|
'bo-', markersize=2, label=r'$\mathrm{{Smoothed}}\ \mathrm{{Data}}$')
|
||||||
|
|
||||||
|
@ -268,6 +264,8 @@ def thickness_for_order0(wavelengths,
|
||||||
refractive_index,
|
refractive_index,
|
||||||
min_peak_prominence,
|
min_peak_prominence,
|
||||||
plot=None):
|
plot=None):
|
||||||
|
if plot:
|
||||||
|
setup_matplotlib()
|
||||||
|
|
||||||
# TODO :
|
# TODO :
|
||||||
# Load "trou"
|
# Load "trou"
|
||||||
|
@ -303,7 +301,7 @@ 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=300)
|
plt.figure()
|
||||||
plt.plot(wavelengths_masked, best_h_values, label=r"Épaisseur du film (Scheludko, m=0)")
|
plt.plot(wavelengths_masked, best_h_values, label=r"Épaisseur du film (Scheludko, m=0)")
|
||||||
plt.ylabel(r'$h$ ($\mathrm{{nm}}$)')
|
plt.ylabel(r'$h$ ($\mathrm{{nm}}$)')
|
||||||
plt.xlabel(r'$\lambda$ (nm)')
|
plt.xlabel(r'$\lambda$ (nm)')
|
||||||
|
@ -326,7 +324,7 @@ def thickness_for_order0(wavelengths,
|
||||||
if plot:
|
if plot:
|
||||||
Delta_values = Delta(wavelengths_masked, fitted_h, best_m, r_index_masked)
|
Delta_values = Delta(wavelengths_masked, fitted_h, best_m, r_index_masked)
|
||||||
|
|
||||||
plt.figure(figsize=(10, 6), dpi=300)
|
plt.figure()
|
||||||
plt.plot(wavelengths_masked, DeltaVrai,
|
plt.plot(wavelengths_masked, DeltaVrai,
|
||||||
'bo-', markersize=2, label=r'$\mathrm{{Smoothed}}\ \mathrm{{Data}}$')
|
'bo-', markersize=2, label=r'$\mathrm{{Smoothed}}\ \mathrm{{Data}}$')
|
||||||
|
|
||||||
|
|
|
@ -25,3 +25,26 @@ class OptimizeResult(dict):
|
||||||
|
|
||||||
def __dir__(self):
|
def __dir__(self):
|
||||||
return list(self.keys())
|
return list(self.keys())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def is_latex_installed():
|
||||||
|
import shutil
|
||||||
|
return shutil.which("latex") is not None or shutil.which("pdflatex") is not None
|
||||||
|
|
||||||
|
def setup_matplotlib():
|
||||||
|
"""
|
||||||
|
Configure matplotlib with LaTeX text rendering and custom font sizes.
|
||||||
|
|
||||||
|
"""
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
plt.rc('text', usetex=is_latex_installed())
|
||||||
|
plt.rcParams.update({
|
||||||
|
'figure.dpi': 300,
|
||||||
|
'figure.figsize': (10, 6),
|
||||||
|
'axes.labelsize': 26,
|
||||||
|
'xtick.labelsize': 32,
|
||||||
|
'ytick.labelsize': 32,
|
||||||
|
'legend.fontsize': 23,
|
||||||
|
})
|
||||||
|
|
0
run_test.sh
Normal file → Executable file
0
run_test.sh
Normal file → Executable file
|
@ -20,7 +20,7 @@ def load():
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
#@pytest.mark.skip('...')
|
@pytest.mark.skip('...')
|
||||||
@pytest.mark.parametrize("spectrum_path, expected", load())
|
@pytest.mark.parametrize("spectrum_path, expected", load())
|
||||||
def test_SV2o0(spectrum_path, expected):
|
def test_SV2o0(spectrum_path, expected):
|
||||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue