8000 `pyxem.signals.BeamShift` incompatible with ROIs · Issue #1094 · pyxem/pyxem · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

pyxem.signals.BeamShift incompatible with ROIs #1094

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

Open
sivborg opened this issue Jun 19, 2024 · 0 comments
Open

pyxem.signals.BeamShift incompatible with ROIs #1094

sivborg opened this issue Jun 19, 2024 · 0 comments

Comments

@sivborg
Copy link
Contributor
sivborg commented Jun 19, 2024

Describe the bug
Trying to use ROIs on BeamShift signals will fail due to the new implementation of plotting.

To Reproduce

import hyperspy.api as hs
import pyxem as pxm
import numpy as np
r = hs.roi.RectangularROI()
s = pxm.signals.BeamShift(np.indices((256,256)).T)
s.plot()
r.add_widget(s)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[4], line 8
      6 # s = hs.signals.Signal2D(s.T)
      7 s.plot()
----> 8 r.add_widget(s)

File ~\hyperspy\hyperspy\roi.py:535, in BaseInteractiveROI.add_widget(self, signal, axes, widget, color, snap, **kwargs)
    532     self._set_default_values(signal, axes=axes)
    534 if signal._plot is None or signal._plot.signal_plot is None:
--> 535     raise RuntimeError(
    536         f"{repr(signal)} does not have an active plot. Plot the "
    537         "signal before calling this method."
    538     )
    540 if widget is None:
    541     widget = self._get_widget_type(axes, signal)(signal.axes_manager, **kwargs)

RuntimeError: <BeamShift, title: , dimensions: (256, 256|2)> does not have an active plot. Plot the signal before calling this method.

This is due to the large refactoring of pyxem.signals.BeamShift, where the plotting is done instead by hyperspy.api.plot.plot_images. The ROIs rely on some private variables that are then not set. Looking through the code quickly, this can get a bit complex.

So a current workaround is to cast the signal to another one before plotting:

import hyperspy.api as hs
import pyxem as pxm
import numpy as np
r = hs.roi.RectangularROI()
s = pxm.signals.BeamShift(np.indices((256,256)).T)
s = hs.signals.Signal2D(s.T)
s.plot()
r.add_widget(s)
@sivborg sivborg changed the title :class:pyxem.signals.BeamShift incompatible with ROIs pyxem.signals.BeamShift incompatible with ROIs Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0