diff --git a/CHANGES.rst b/CHANGES.rst index c075fced1..97ecc327c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -7,6 +7,7 @@ https://holospy.readthedocs.io/en/latest/changes.html 0.1.dev0 (UNRELEASED) ===================== +- Enable ``signal_range`` arguments when using ``subpixel=True`` in :py:meth:`~.signals.EELSSpectrum.align_zero_loss_peak` (`#7 `_) - Support for tabulated :ref:`Generalised Oscillator Strengths (GOS) ` using the `GOSH `_ open file format. By default, a freely usable dataset is downloaded from `doi:10.5281/zenodo.7645765 `_ diff --git a/exspy/signals/eels.py b/exspy/signals/eels.py index 822c70924..036cce7c9 100644 --- a/exspy/signals/eels.py +++ b/exspy/signals/eels.py @@ -335,7 +335,8 @@ def align_zero_loss_peak( """Align the zero-loss peak. This function first aligns the spectra using the result of - `estimate_zero_loss_peak_centre` and afterward, if subpixel is True, + `estimate_zero_loss_peak_centre` which finds the maximum in the + given energy range, then if subpixel is True, proceeds to align with subpixel accuracy using `align1D`. The offset is automatically correct if `calibrate` is True. @@ -450,26 +451,28 @@ def estimate_zero_loss_peak_centre(s, mask, signal_range): if subpixel is False: return - left, right = -3.0, 3.0 + + start, end = signal_range or (-3.0, 3.0) + if calibrate is False: - left += mean_ - right += mean_ + start += mean_ + end += mean_ - left = ( - left - if left > self.axes_manager[-1].axis[0] + start = ( + start + if start > self.axes_manager[-1].axis[0] else self.axes_manager[-1].axis[0] ) - right = ( - right - if right < self.axes_manager[-1].axis[-1] + end = ( + end + if end < self.axes_manager[-1].axis[-1] else self.axes_manager[-1].axis[-1] ) if self.axes_manager.navigation_size > 1: self.align1D( - left, - right, + start, + end, also_align=also_align, show_progressbar=show_progressbar, mask=mask, diff --git a/exspy/tests/signals/test_eels.py b/exspy/tests/signals/test_eels.py index e0c80add0..98f54c709 100644 --- a/exspy/tests/signals/test_eels.py +++ b/exspy/tests/signals/test_eels.py @@ -193,6 +193,18 @@ def test_align_zero_loss_peak_crop_false(self): s.align_zero_loss_peak(crop=False, print_stats=False) assert original_size == s.axes_manager.signal_axes[0].size + @pytest.mark.parametrize("signal_range", ((-2.0, 2.0), (0, 40), "roi")) + def test_align_zero_loss_peak_start_end_float(self, signal_range): + s = self.signal + if signal_range == "roi": + signal_range = hs.roi.SpanROI(-3, 3) + s.axes_manager[-1].offset = -2 + s.align_zero_loss_peak(subpixel=True, signal_range=signal_range) + zlpc = s.estimate_zero_loss_peak_centre() + # Check if start and end arguments work + assert zlpc.data.mean() == 0 + assert zlpc.data.std() == 0 + @lazifyTestClass class TestSpikesRemovalToolZLP: diff --git a/pyproject.toml b/pyproject.toml index 21fb67d88..f92a4d8b2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -93,6 +93,14 @@ force-exclude = ''' | exspy/misc/elements.py ''' +[tool.coverage.run] +branch = true +source = ["hyperspy"] +omit = ["hyperspy/tests/*"] + +[tool.coverage.report] +precision = 2 + [tool.pytest.ini_options] addopts = "-ra -n auto --dist loadfile" testpaths = ["exspy/tests", ]