From cd06da8c8b5f2877ee779fac2d73704b820fd8ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Wed, 25 Jun 2025 11:48:48 +0200 Subject: [PATCH 1/4] add test --- tests/test_thickness.py | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/test_thickness.py diff --git a/tests/test_thickness.py b/tests/test_thickness.py new file mode 100644 index 0000000..068b7ed --- /dev/null +++ b/tests/test_thickness.py @@ -0,0 +1,67 @@ +import pytest +import yaml +from pathlib import Path +import os.path + +import numpy as np +from numpy.testing import assert_allclose +from numpy.testing import assert_almost_equal + +from optifik.minmax import thickness_from_minmax +from optifik.analysis import smooth_intensities +from optifik.io import load_spectrum + + +def load(): + test_data_dir = Path(__file__).parent.parent / 'data' + FOLDER = test_data_dir / 'spectraLorene' / 'sample1' + + yaml_file = os.path.join(FOLDER, 'sample1.yaml') + with open(yaml_file, "r") as yaml_file: + thickness_dict = yaml.safe_load(yaml_file) + #print(thickness_dict) + data = [(os.path.join(FOLDER, fn), val) for fn, val in thickness_dict['known_thicknesses'].items()] + return data + + +def test_minmax_sample1(): + min_peak_prominence = 0.02 + min_peak_distance = 10 + skipped = ('011137.xy', + '012426.xy', + '012795.xy', + '012979.xy', + '011321.xy', #Insufficient number of data points + ) + + for path, expected in load(): + file = os.path.split(path)[-1] + if file not in skipped: + lambdas, raw_intensities = load_spectrum(path, wavelength_min=450) + smoothed_intensities = smooth_intensities(raw_intensities) + r_index = 1.33 #TODO + + prominence = 0.02 + distance = 10 + + result = thickness_from_minmax(lambdas, + smoothed_intensities, + refractive_index=r_index, + min_peak_prominence=prominence, + min_peak_distance=distance, + method='ransac', + plot=False) + + assert_allclose(result.thickness, expected, rtol=2.3e-1) + +#def test_fft_sample1(): +# for name, value in known_values.sample1['known_thicknesses'].items(): +# index = known_values.sample1['refractive_index'] +# # this method works only for large thicknesses +# if value < 3000: +# continue +# path = os.path.join('spectra', name) +# lambdas, intensities = io.load_spectrum(path, lambda_min=450) +# result = thickness_from_fft(lambdas, intensities, refractive_index=index,) +# error = 100 * np.abs(result.thickness - value) / value +# assert(error < 5) From 28077e2853b184e02c30b6d6a87a0ae684deafe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Wed, 25 Jun 2025 11:48:59 +0200 Subject: [PATCH 2/4] add licence --- CHANGELOG.md | 4 ++++ README.md | 6 ++++++ pyproject.toml | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..65b2eeb --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ + +# x.x.x + +First version diff --git a/README.md b/README.md index be6680a..b07face 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Optifik +TODO: write a paragraph here... + This library replaces oospectro. @@ -48,3 +50,7 @@ cd docs make html ``` +## Licence + +The source code is released under the GNU General Public License v3.0. +See LICENSE for details. diff --git a/pyproject.toml b/pyproject.toml index d05cb02..e53c231 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ authors = [ { name = "François Boulogne", email = "francois.boulogne@cnrs.fr" }, { name = "Victor Ziapkoff", email = "victor.ziapkoff@universite-paris-saclay.fr" }, ] -license = "GPL-3.0-or-later" +license = "GPL-3.0" readme = "README.md" requires-python = ">=3.13" dependencies = [ From 99bbb51fc14ce1020d4c43ceab307f99a695fb85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Wed, 25 Jun 2025 11:49:20 +0200 Subject: [PATCH 3/4] add gitignore --- .gitignore | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3547ba4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +__pycache__ +.backups +optifik.egg-info +*.bak +*.pyc +.ipynb_checkpoints +build/ +dist/ From 481f15ef7a30305febfa028b76a482a33498f619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Wed, 25 Jun 2025 11:50:10 +0200 Subject: [PATCH 4/4] populate git ignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 3547ba4..1f811a3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,7 @@ optifik.egg-info *.bak *.pyc .ipynb_checkpoints +.venv build/ +_build/ dist/