Skip to content

Commit

Permalink
Merge pull request #7 from HanHsuanWu/main
Browse files Browse the repository at this point in the history
align_zero_loss_peak should take left and right arguments for low loss spectra
  • Loading branch information
ericpre authored Nov 18, 2023
2 parents 987e6a8 + 1ab68ea commit add7440
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/hyperspy/exspy/pull/7>`_)
- Support for tabulated :ref:`Generalised Oscillator Strengths (GOS) <eels.GOS>` using the
`GOSH <https://gitlab.com/gguzzina/gosh>`_ open file format. By default, a freely
usable dataset is downloaded from `doi:10.5281/zenodo.7645765 <https://zenodo.org/record/6599071>`_
Expand Down
27 changes: 15 additions & 12 deletions exspy/signals/eels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions exspy/tests/signals/test_eels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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", ]
Expand Down

0 comments on commit add7440

Please sign in to comment.