Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message initialisation SpanROI #2604

Merged
merged 6 commits into from Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Expand Up @@ -23,6 +23,7 @@ RELEASE_next_patch (Unreleased)
* Fix ``find_peaks`` GUIs call with laplacian/difference of gaussian methods (`#2622 <https://github.com/hyperspy/hyperspy/issues/2622>`_ and `#2647 <https://github.com/hyperspy/hyperspy/pull/2647>`_)
* Added lazy reading support for FFT and DPC datasets in FEI emd datasets (`#2651 <https://github.com/hyperspy/hyperspy/pull/2651>`_).
* Fix various future and deprecation warnings from numpy and scikit-learn (`#2646 <https://github.com/hyperspy/hyperspy/pull/2646>`_)
* Improve error message when initialising SpanROI with left >= right (`#2604 <https://github.com/hyperspy/hyperspy/pull/2604>`_)


Changelog
Expand Down
5 changes: 2 additions & 3 deletions hyperspy/misc/label_position.py
Expand Up @@ -219,9 +219,8 @@ def _text_parser(self, text_edge):
element, subshell = text_edge.split('_')

if subshell[-1].isdigit():
formatted = element+' '+'$\mathregular{'+subshell[0]+'_'+\
subshell[-1]+'}$'
formatted = f"{element} {subshell[0]}$_{subshell[-1]}$"
else:
formatted = element+' '+'$\mathregular{'+subshell[0]+'}$'
formatted = f"{element} {subshell[0]}"

return formatted
8 changes: 4 additions & 4 deletions hyperspy/roi.py
Expand Up @@ -702,16 +702,16 @@ class SpanROI(BaseInteractiveROI):
_ndim = 1

def __init__(self, left, right):
super(SpanROI, self).__init__()
self._bounds_check = True # Use reponsibly!
super().__init__()
self._bounds_check = True # Use responsibly!
if left >= right:
raise ValueError(f"`left` ({left}) must be smaller than `right` ({right}).")
self.left, self.right = left, right

def __getitem__(self, *args, **kwargs):
_tuple = (self.left, self.right)
return _tuple.__getitem__(*args, **kwargs)



def is_valid(self):
return (t.Undefined not in (self.left, self.right) and
self.right >= self.left)
Expand Down
6 changes: 6 additions & 0 deletions hyperspy/tests/utils/test_roi.py
Expand Up @@ -104,6 +104,12 @@ def test_point2d_getitem(self):
r = Point2DROI(1, 2)
assert tuple(r) == (1, 2)

def test_span_roi_init(self):
with pytest.raises(ValueError):
SpanROI(30, 15)
with pytest.raises(ValueError):
SpanROI(15, 15)

def test_span_spectrum_nav(self):
s = self.s_s
r = SpanROI(15, 30)
Expand Down
2 changes: 1 addition & 1 deletion hyperspy/ui_registry.py
Expand Up @@ -18,7 +18,7 @@

"""Registry of user interface widgets.

Format {"tool_key" : {"toolkit" : <function(obj, display, \*\*kwargs)>}}
Format {"tool_key" : {"toolkit" : <function(obj, display, **kwargs)>}}

The ``tool_key`` is defined by the "model function" to which the widget provides
and user interface. That function gets the widget function from this registry
Expand Down
2 changes: 1 addition & 1 deletion hyperspy/utils/__init__.py
Expand Up @@ -48,7 +48,7 @@


def print_known_signal_types():
"""Print all known `signal_type`\s
r"""Print all known `signal_type`\s

This includes `signal_type`\s from all installed packages that
extend HyperSpy.
Expand Down