upd API
This commit is contained in:
parent
12922f0f79
commit
a9df27b7c7
13 changed files with 43 additions and 40 deletions
8
check.py
8
check.py
|
@ -41,7 +41,7 @@ def minmax():
|
|||
lambdas, intensities = io.load_spectrum(spectrum_file)
|
||||
plot_spectrum(lambdas, intensities, title='Raw')
|
||||
|
||||
lambdas, intensities = io.load_spectrum(spectrum_file, lambda_min=450)
|
||||
lambdas, intensities = io.load_spectrum(spectrum_file, wavelength_min=450)
|
||||
plot_spectrum(lambdas, intensities, title='Raw, cropped')
|
||||
|
||||
smoothed_intensities = smooth_intensities(intensities)
|
||||
|
@ -79,7 +79,7 @@ def play_order1():
|
|||
lambdas, intensities = io.load_spectrum(spectrum_file)
|
||||
plot_spectrum(lambdas, intensities, title='Raw')
|
||||
|
||||
lambdas, intensities = io.load_spectrum(spectrum_file, lambda_min=450)
|
||||
lambdas, intensities = io.load_spectrum(spectrum_file, wavelength_min=450)
|
||||
plot_spectrum(lambdas, intensities, title='Raw, cropped')
|
||||
|
||||
smoothed_intensities = smooth_intensities(intensities)
|
||||
|
@ -129,7 +129,7 @@ def play_order0():
|
|||
lambdas, intensities = io.load_spectrum(spectrum_file)
|
||||
plot_spectrum(lambdas, intensities, title='Raw')
|
||||
|
||||
lambdas, intensities = io.load_spectrum(spectrum_file, lambda_min=450)
|
||||
lambdas, intensities = io.load_spectrum(spectrum_file, wavelength_min=450)
|
||||
plot_spectrum(lambdas, intensities, title='Raw, cropped')
|
||||
|
||||
|
||||
|
@ -186,7 +186,7 @@ def check_SV1():
|
|||
|
||||
spectre_file = os.path.join(DATA_FOLDER, fn)
|
||||
|
||||
lambdas, raw_intensities = load_spectrum(spectre_file, lambda_min=450)
|
||||
lambdas, raw_intensities = load_spectrum(spectre_file, wavelength_min=450)
|
||||
|
||||
##### Affichage du spectre lissé #####
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ import numpy as np
|
|||
|
||||
|
||||
def load_spectrum(spectrum_path,
|
||||
lambda_min=0,
|
||||
lambda_max=np.inf,
|
||||
wavelength_min=0,
|
||||
wavelength_max=np.inf,
|
||||
delimiter=','):
|
||||
"""
|
||||
Load a spectrum file.
|
||||
|
@ -15,10 +15,10 @@ def load_spectrum(spectrum_path,
|
|||
----------
|
||||
spectrum_path : string
|
||||
File path.
|
||||
lambda_min : scalar, optional
|
||||
Cut the data at this minimum wavelength in nm.
|
||||
lambda_max : scalar, optional
|
||||
Cut the data at this maximum wavelength in nm.
|
||||
wavelength_min : scalar, optional
|
||||
Cut the data at this minimum wavelength (included).
|
||||
wavelength_max : scalar, optional
|
||||
Cut the data at this maximum wavelength (included).
|
||||
delimiter : string, optional
|
||||
Delimiter between columns in the datafile.
|
||||
|
||||
|
@ -30,5 +30,5 @@ def load_spectrum(spectrum_path,
|
|||
data = np.loadtxt(spectrum_path, delimiter=delimiter)
|
||||
lambdas, intensities = np.column_stack(data)
|
||||
|
||||
mask = (lambdas > lambda_min) & (lambdas < lambda_max)
|
||||
mask = (lambdas >= wavelength_min) & (lambdas <= wavelength_max)
|
||||
return lambdas[mask], intensities[mask]
|
||||
|
|
|
@ -288,14 +288,14 @@ def thickness_from_scheludko(wavelengths,
|
|||
wavelengths_masked = wavelengths[mask]
|
||||
r_index_masked = r_index[mask]
|
||||
intensities_masked = intensities[mask]
|
||||
intensities_I_min_masked = intensities_void[mask]
|
||||
intensities_void_masked = intensities_void[mask]
|
||||
|
||||
interference_order = 0
|
||||
thickness_values = _thicknesses_scheludko_at_order(wavelengths_masked,
|
||||
intensities_masked,
|
||||
interference_order,
|
||||
r_index_masked,
|
||||
Imin=intensities_I_min_masked)
|
||||
intensities_void=intensities_void_masked)
|
||||
|
||||
elif interference_order > 0:
|
||||
h_values = _thicknesses_scheludko_at_order(wavelengths_masked,
|
||||
|
@ -312,8 +312,8 @@ def thickness_from_scheludko(wavelengths,
|
|||
|
||||
# Delta
|
||||
if interference_order == 0:
|
||||
num = intensities_masked - np.min(intensities_I_min_masked)
|
||||
denom = np.max(intensities_masked) - np.min(intensities_I_min_masked)
|
||||
num = intensities_masked - np.min(intensities_void_masked)
|
||||
denom = np.max(intensities_masked) - np.min(intensities_void_masked)
|
||||
else:
|
||||
num = intensities_masked - np.min(intensities_masked)
|
||||
denom = np.max(intensities_masked) - np.min(intensities_masked)
|
||||
|
@ -340,7 +340,8 @@ def thickness_from_scheludko(wavelengths,
|
|||
|
||||
plt.figure()
|
||||
plt.plot(wavelengths_masked, Delta_from_data,
|
||||
'bo-', markersize=2, label=r'$\mathrm{{Smoothed}}\ \mathrm{{Data}}$')
|
||||
'bo-', markersize=2,
|
||||
label=r'$\mathrm{{Smoothed}}\ \mathrm{{Data}}$')
|
||||
|
||||
# Scheludko
|
||||
label = rf'$\mathrm{{Scheludko}}\ (h = {np.mean(thickness_values):.1f} \pm {np.std(thickness_values):.1f}\ \mathrm{{nm}})$'
|
||||
|
@ -348,7 +349,9 @@ def thickness_from_scheludko(wavelengths,
|
|||
'go-', markersize=2, label=label)
|
||||
# Fit
|
||||
label = rf'$\mathrm{{Fit}}\ (h = {fitted_h:.1f}\pm {std_err:.1f} \ \mathrm{{nm}})$'
|
||||
plt.plot(wavelengths_masked, Delta_values, 'ro-', markersize=2, label=label)
|
||||
plt.plot(wavelengths_masked, Delta_values,
|
||||
'ro-', markersize=2,
|
||||
label=label)
|
||||
|
||||
plt.legend()
|
||||
plt.ylabel(r'$\Delta$')
|
||||
|
|
|
@ -23,7 +23,7 @@ def load():
|
|||
|
||||
@pytest.mark.parametrize("spectrum_path, expected", load())
|
||||
def test_minmax(spectrum_path, expected):
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, wavelength_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
|
||||
assert_equal(len(lambdas), len(smoothed_intensities))
|
||||
|
|
|
@ -24,11 +24,11 @@ def load(filename):
|
|||
#@pytest.mark.skip('...')
|
||||
@pytest.mark.parametrize("spectrum_path, expected", load('known_value.yaml'))
|
||||
def test_SV2o0_small_tol(spectrum_path, expected):
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, wavelength_min=450)
|
||||
|
||||
File_I_min = 'tests/spectre_trou/000043641.xy'
|
||||
_, intensities_void = load_spectrum(File_I_min, lambda_min=450)
|
||||
|
||||
_, intensities_void = load_spectrum(File_I_min, wavelength_min=450)
|
||||
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
|
||||
r_index = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
|
@ -54,11 +54,11 @@ def test_SV2o0_small_tol(spectrum_path, expected):
|
|||
|
||||
@pytest.mark.parametrize("spectrum_path, expected", load('known_value_large_tol.yaml'))
|
||||
def test_SV2o0_large_tol(spectrum_path, expected):
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, wavelength_min=450)
|
||||
|
||||
File_I_min = 'tests/spectre_trou/000043641.xy'
|
||||
_, intensities_void = load_spectrum(File_I_min, lambda_min=450)
|
||||
|
||||
_, intensities_void = load_spectrum(File_I_min, wavelength_min=450)
|
||||
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
|
||||
r_index = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
|
|
|
@ -24,7 +24,7 @@ def load():
|
|||
#@pytest.mark.skip('...')
|
||||
@pytest.mark.parametrize("spectrum_path, expected", load())
|
||||
def test_SV2o1(spectrum_path, expected):
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, wavelength_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
|
||||
r_index = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
|
|
|
@ -23,7 +23,7 @@ def load():
|
|||
|
||||
@pytest.mark.parametrize("spectrum_path, expected", load())
|
||||
def test_SV2o2(spectrum_path, expected):
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, wavelength_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
|
||||
r_index = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
|
|
|
@ -23,7 +23,7 @@ def load():
|
|||
|
||||
@pytest.mark.parametrize("spectrum_path, expected", load())
|
||||
def test_SV2o3(spectrum_path, expected):
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, wavelength_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
|
||||
r_index = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
|
|
|
@ -23,7 +23,7 @@ def load():
|
|||
|
||||
@pytest.mark.parametrize("spectrum_path, expected", load())
|
||||
def test_SV2o4(spectrum_path, expected):
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, wavelength_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
|
||||
r_index = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
|
|
|
@ -23,7 +23,7 @@ def load():
|
|||
|
||||
@pytest.mark.parametrize("spectrum_path, expected", load())
|
||||
def test_SV2o5(spectrum_path, expected):
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, wavelength_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
|
||||
r_index = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
|
|
|
@ -14,7 +14,7 @@ def test_FFT():
|
|||
expected = 3524.51
|
||||
|
||||
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, wavelength_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
r_index = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ def test_minmax_ransac():
|
|||
expected = 1338.35
|
||||
|
||||
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, wavelength_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
r_index = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
|
||||
|
@ -36,7 +36,7 @@ def test_minmax_linreg():
|
|||
expected = 1338.35
|
||||
|
||||
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, wavelength_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
r_index = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ def dataset1():
|
|||
expected = 777.07
|
||||
|
||||
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, wavelength_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
r_index = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
|
||||
|
@ -97,7 +97,7 @@ def test_scheludko_2peaks():
|
|||
expected = 495.69
|
||||
|
||||
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, wavelength_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
r_index = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
|
||||
|
@ -127,14 +127,14 @@ def test_order0():
|
|||
expected = 115.33
|
||||
|
||||
spectrum_path = os.path.join(FOLDER, FILE_NAME)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, lambda_min=450)
|
||||
lambdas, raw_intensities = load_spectrum(spectrum_path, wavelength_min=450)
|
||||
smoothed_intensities = smooth_intensities(raw_intensities)
|
||||
r_index = 1.324188 + 3102.060378 / (lambdas**2)
|
||||
prominence = 0.03
|
||||
|
||||
|
||||
|
||||
|
||||
File_I_min = 'tests/spectre_trou/000043641.xy'
|
||||
_, intensities_void = load_spectrum(File_I_min, lambda_min=450)
|
||||
_, intensities_void = load_spectrum(File_I_min, wavelength_min=450)
|
||||
|
||||
|
||||
w_start, w_stop = None, None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue