fixes
This commit is contained in:
parent
d5fae56eb4
commit
1800675fd3
5 changed files with 107 additions and 109 deletions
|
@ -26,7 +26,7 @@ def plot_spectrum(wavelengths, intensities, title=''):
|
||||||
|
|
||||||
def finds_peak(wavelengths, intensities, min_peak_prominence, min_peak_distance=10, plot=None):
|
def finds_peak(wavelengths, intensities, min_peak_prominence, min_peak_distance=10, plot=None):
|
||||||
"""
|
"""
|
||||||
Detect minima and maxima
|
Detect minima and maxima.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
|
178
optifik/fft.py
178
optifik/fft.py
|
@ -71,12 +71,10 @@ def thickness_from_fft(wavelengths, intensities,
|
||||||
idx_max_fft = np.argmax(abs(intensities_fft))
|
idx_max_fft = np.argmax(abs(intensities_fft))
|
||||||
freq_max = inverse_wavelengths_fft[idx_max_fft]
|
freq_max = inverse_wavelengths_fft[idx_max_fft]
|
||||||
|
|
||||||
|
|
||||||
thickness_fft = freq_max / 2.
|
thickness_fft = freq_max / 2.
|
||||||
|
|
||||||
|
|
||||||
plt.figure(figsize=(10, 6),dpi =600)
|
|
||||||
if plot:
|
if plot:
|
||||||
|
plt.figure(figsize=(10, 6),dpi =600)
|
||||||
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')
|
||||||
|
@ -86,90 +84,90 @@ def thickness_from_fft(wavelengths, intensities,
|
||||||
return OptimizeResult(thickness=thickness_fft,)
|
return OptimizeResult(thickness=thickness_fft,)
|
||||||
|
|
||||||
|
|
||||||
def Prominence_from_fft(wavelengths, intensities, refractive_index,
|
#def Prominence_from_fft(wavelengths, intensities, refractive_index,
|
||||||
num_half_space=None, plot=None):
|
# num_half_space=None, plot=None):
|
||||||
if num_half_space is None:
|
# if num_half_space is None:
|
||||||
num_half_space = len(wavelengths)
|
# num_half_space = len(wavelengths)
|
||||||
|
#
|
||||||
# # # 1. Spectre original
|
# # # # 1. Spectre original
|
||||||
# if plot:
|
# # if plot:
|
||||||
# plt.figure(figsize=(10, 6), dpi=150)
|
# # plt.figure(figsize=(10, 6), dpi=150)
|
||||||
# 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é')
|
||||||
# plt.legend()
|
# # plt.legend()
|
||||||
# plt.show()
|
# # plt.show()
|
||||||
|
#
|
||||||
|
#
|
||||||
# 2. Conversion lambda → k = n(λ) / λ
|
# # 2. Conversion lambda → k = n(λ) / λ
|
||||||
k_vals = refractive_index / wavelengths
|
# k_vals = refractive_index / wavelengths
|
||||||
f_interp = interp1d(k_vals, intensities, kind='linear', fill_value="extrapolate")
|
# f_interp = interp1d(k_vals, intensities, kind='linear', fill_value="extrapolate")
|
||||||
|
#
|
||||||
# 3. Axe k uniforme + interpolation
|
# # 3. Axe k uniforme + interpolation
|
||||||
k_linspace = np.linspace(k_vals[0], k_vals[-1], 2 * num_half_space)
|
# k_linspace = np.linspace(k_vals[0], k_vals[-1], 2 * num_half_space)
|
||||||
intensities_k = f_interp(k_linspace)
|
# intensities_k = f_interp(k_linspace)
|
||||||
|
#
|
||||||
# 4. FFT
|
# # 4. FFT
|
||||||
delta_k = (k_vals[-1] - k_vals[0]) / (2 * num_half_space)
|
# delta_k = (k_vals[-1] - k_vals[0]) / (2 * num_half_space)
|
||||||
fft_vals = fft(intensities_k)
|
# fft_vals = fft(intensities_k)
|
||||||
freqs = fftfreq(2 * num_half_space, delta_k)
|
# freqs = fftfreq(2 * num_half_space, delta_k)
|
||||||
|
#
|
||||||
# 5. Pic FFT
|
# # 5. Pic FFT
|
||||||
freqs_pos = freqs[freqs > 0]
|
# freqs_pos = freqs[freqs > 0]
|
||||||
abs_fft_pos = np.abs(fft_vals[freqs > 0])
|
# abs_fft_pos = np.abs(fft_vals[freqs > 0])
|
||||||
idx_max = np.argmax(abs_fft_pos)
|
# idx_max = np.argmax(abs_fft_pos)
|
||||||
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(figsize=(10, 6), dpi=150)
|
||||||
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]')
|
||||||
plt.ylabel(r'FFT($I^*$)')
|
# plt.ylabel(r'FFT($I^*$)')
|
||||||
plt.xscale('log')
|
# plt.xscale('log')
|
||||||
plt.yscale('log')
|
# plt.yscale('log')
|
||||||
plt.legend()
|
# plt.legend()
|
||||||
plt.show()
|
# plt.show()
|
||||||
|
#
|
||||||
# 6. Filtrage (garde hautes fréquences)
|
# # 6. Filtrage (garde hautes fréquences)
|
||||||
cutoff_HF = 2 * F_max
|
# cutoff_HF = 2 * F_max
|
||||||
|
#
|
||||||
mask_HF = np.abs(freqs) >= cutoff_HF
|
# mask_HF = np.abs(freqs) >= cutoff_HF
|
||||||
fft_filtered_HF = np.zeros_like(fft_vals, dtype=complex)
|
# fft_filtered_HF = np.zeros_like(fft_vals, dtype=complex)
|
||||||
fft_filtered_HF[mask_HF] = fft_vals[mask_HF]
|
# fft_filtered_HF[mask_HF] = fft_vals[mask_HF]
|
||||||
|
#
|
||||||
# 7. Filtrage (garde basses fréquences)
|
# # 7. Filtrage (garde basses fréquences)
|
||||||
cutoff_BF = 10 * F_max
|
# cutoff_BF = 10 * F_max
|
||||||
mask_BF = np.abs(freqs) <= cutoff_BF
|
# mask_BF = np.abs(freqs) <= cutoff_BF
|
||||||
fft_filtered_BF = np.zeros_like(fft_vals, dtype=complex)
|
# fft_filtered_BF = np.zeros_like(fft_vals, dtype=complex)
|
||||||
fft_filtered_BF[mask_BF] = fft_vals[mask_BF]
|
# fft_filtered_BF[mask_BF] = fft_vals[mask_BF]
|
||||||
|
#
|
||||||
|
#
|
||||||
# 8. Reconstruction
|
# # 8. Reconstruction
|
||||||
signal_filtered_HF = np.real(ifft(fft_filtered_HF))
|
# signal_filtered_HF = np.real(ifft(fft_filtered_HF))
|
||||||
signal_filtered_BF = np.real(ifft(fft_filtered_BF))
|
# signal_filtered_BF = np.real(ifft(fft_filtered_BF))
|
||||||
lambda_reconstructed = np.interp(k_linspace, k_vals[::-1], wavelengths[::-1])
|
# lambda_reconstructed = np.interp(k_linspace, k_vals[::-1], wavelengths[::-1])
|
||||||
|
#
|
||||||
# Masque dans la plage [550, 700] nm
|
# # Masque dans la plage [550, 700] nm
|
||||||
mask_Cam_Sensitivity = (lambda_reconstructed >= 550) & (lambda_reconstructed <= 700)
|
# mask_Cam_Sensitivity = (lambda_reconstructed >= 550) & (lambda_reconstructed <= 700)
|
||||||
|
#
|
||||||
# 9. Affichage reconstruction
|
# # 9. Affichage reconstruction
|
||||||
if plot:
|
# if plot:
|
||||||
plt.figure(figsize=(10, 6), dpi=150)
|
# plt.figure(figsize=(10, 6), dpi=150)
|
||||||
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')
|
||||||
|
#
|
||||||
plt.plot(lambda_reconstructed[mask_Cam_Sensitivity], signal_filtered_HF[mask_Cam_Sensitivity],
|
# plt.plot(lambda_reconstructed[mask_Cam_Sensitivity], signal_filtered_HF[mask_Cam_Sensitivity],
|
||||||
color='orange', label='Spectre filtré HF')
|
# color='orange', label='Spectre filtré HF')
|
||||||
plt.plot(lambda_reconstructed, signal_filtered_BF,
|
# plt.plot(lambda_reconstructed, signal_filtered_BF,
|
||||||
color='red', label='Spectre filtré BF')
|
# color='red', label='Spectre filtré BF')
|
||||||
|
#
|
||||||
plt.xlabel('Wavelength (nm)')
|
# plt.xlabel('Wavelength (nm)')
|
||||||
plt.ylabel('Intensity')
|
# plt.ylabel('Intensity')
|
||||||
plt.legend()
|
# plt.legend()
|
||||||
plt.show()
|
# plt.show()
|
||||||
|
#
|
||||||
max_amplitude = np.max(np.abs(signal_filtered_HF[mask_Cam_Sensitivity]))
|
# max_amplitude = np.max(np.abs(signal_filtered_HF[mask_Cam_Sensitivity]))
|
||||||
|
#
|
||||||
return max_amplitude, signal_filtered_BF, lambda_reconstructed
|
# return max_amplitude, signal_filtered_BF, lambda_reconstructed
|
||||||
|
#
|
||||||
|
|
|
@ -29,10 +29,10 @@ def thickness_scheludko_at_order(wavelengths,
|
||||||
Wavelength values in nm.
|
Wavelength values in nm.
|
||||||
intensities : array
|
intensities : array
|
||||||
Intensity values.
|
Intensity values.
|
||||||
interference_order: TYPE
|
interference_order : int
|
||||||
DESCRIPTION.
|
Interference order.
|
||||||
refractive_index : TYPE
|
refractive_index : array_like (or float)
|
||||||
DESCRIPTION.
|
Refractive index.
|
||||||
Imin : TYPE, optional
|
Imin : TYPE, optional
|
||||||
DESCRIPTION. The default is None.
|
DESCRIPTION. The default is None.
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ def thickness_from_scheludko(wavelengths,
|
||||||
plt.xlabel(r'$\lambda$ ($ \mathrm{nm} $)')
|
plt.xlabel(r'$\lambda$ ($ \mathrm{nm} $)')
|
||||||
|
|
||||||
|
|
||||||
return OptimizeResult(thickness=fitted_h ,)
|
return OptimizeResult(thickness=fitted_h,)
|
||||||
|
|
||||||
|
|
||||||
def thickness_for_order0(wavelengths,
|
def thickness_for_order0(wavelengths,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue