Open
Description
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)