diff --git a/qudi_hira_analysis/helper_functions.py b/qudi_hira_analysis/helper_functions.py index ba94495..0b18e94 100644 --- a/qudi_hira_analysis/helper_functions.py +++ b/qudi_hira_analysis/helper_functions.py @@ -1,5 +1,3 @@ -import numpy as np -from scipy import sparse def decibelm_to_watts(dbm_value: float) -> float: @@ -44,23 +42,3 @@ def format_exponent_as_str( def log_tick_formatter(val, pos=None): """ Format ticks for log10 scale plots """ return rf"$10^{{{val:.0f}}}$" - - -def baseline_als(y: np.ndarray, lam: float = 1e6, p: float = 0.9, - niter: int = 10) -> np.ndarray: - """ - Asymmetric least squares baseline. - Source: Paul H. C. Eilers, Hans F.M. Boelens. Baseline Correction with Asymmetric - Least Squares Smoothing (2005). - """ - L = len(y) # noqa: N806 - D = sparse.csc_matrix(np.diff(np.eye(L), 2)) # noqa: N806 - w = np.ones(L) - - z = None - for _ in range(niter): - W = sparse.spdiags(w, 0, L, L) # noqa: N806 - Z = W + lam * D.dot(D.transpose()) # noqa: N806 - z = sparse.linalg.spsolve(Z, w * y) - w = p * (y > z) + (1 - p) * (y < z) - return z diff --git a/tests/test_fitting.py b/tests/test_fitting.py index 054658e..920250d 100644 --- a/tests/test_fitting.py +++ b/tests/test_fitting.py @@ -2,6 +2,8 @@ from pathlib import Path from unittest import TestCase +import lmfit + from qudi_hira_analysis import DataHandler logging.disable(logging.CRITICAL) @@ -37,13 +39,14 @@ def test_pulsedodmr_lorentziandouble_fit(self): odmr_list = self.dh.load_measurements(measurement_str="ODMR", pulsed=True) odmr = odmr_list["20220315-2050-39"] - x_fit, y_fit, _ = self.dh.fit( + x_fit, y_fit, res = self.dh.fit( x="Controlled variable(Hz)", y="Signal", data=odmr.data, fit_function=self.dh.fit_function.lorentziandouble ) - + odmr.fit_model = res + self.assertIsInstance(odmr.fit_model, lmfit.model.ModelResult) self.assertAlmostEqual(x_fit.tolist()[0], 2850000000.0) self.assertAlmostEqual(y_fit.tolist()[0], 1.1015461033795304) diff --git a/tests/test_helpers.py b/tests/test_helpers.py new file mode 100644 index 0000000..5e45009 --- /dev/null +++ b/tests/test_helpers.py @@ -0,0 +1,27 @@ +import logging +from unittest import TestCase + +from qudi_hira_analysis.helper_functions import ( + decibelm_to_watts, + format_exponent_as_str, + log_tick_formatter, +) + +logging.disable(logging.CRITICAL) + + +class TestFitting(TestCase): + def test_decibelm_to_watts(self): + self.assertEqual(0.01, decibelm_to_watts(10)) + + def test_format_exponent_as_str(self): + self.assertEqual( + "${ 1.0 } \cdot 10^{ -4 }$", + format_exponent_as_str(0.0001) + ) + + def test_log_tick_formatter(self): + self.assertEqual( + "$10^{1}$", + log_tick_formatter(1) + ) diff --git a/tests/test_loading.py b/tests/test_loading.py index f8bf14e..595bb1d 100644 --- a/tests/test_loading.py +++ b/tests/test_loading.py @@ -75,9 +75,12 @@ def test_bruker_mfm_load(self): bruker_measurements = self.dh.load_measurements(measurement_str="", extension=".001", qudi=False) - bruker_data = bruker_measurements[next(iter(bruker_measurements))].data + bruker = bruker_measurements[next(iter(bruker_measurements))] + bruker_data = bruker.data + scan_size = bruker.get_param_from_filename(unit="um") mfm = bruker_data.get_channel("Phase", mfm=True) + self.assertEqual(scan_size, 15.0) self.assertEqual(mfm.channel, "Phase") self.assertEqual(mfm.type, "Bruker MFM") bruker_data.file.close()