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

ROI error if axes_manager[0].offset != 0 #2720

Closed
ks00x opened this issue Apr 26, 2021 · 3 comments · Fixed by #2721
Closed

ROI error if axes_manager[0].offset != 0 #2720

ks00x opened this issue Apr 26, 2021 · 3 comments · Fixed by #2721

Comments

@ks00x
Copy link

ks00x commented Apr 26, 2021

Hyperspy 1.62 crashes if the image has an offset > 0. This code example taken from the documentation gives the error traceback below if I dont force the offset to 0. Have the same issue with older data which used to work with code like this and where the image origin is not (0,0) .

holo = hs.datasets.example_signals.object_hologram()

# enabling this 2 lines prevents the crash
#holo.axes_manager[0].offset = 0 
#holo.axes_manager[1].offset = 0

roi = hs.roi.Line2DROI(x1=465.577, y1=445.15, x2=169.4, y2=387.731, linewidth=0)
holo.plot()
ss = roi.interactive(holo)


error trace:

ValueError                                Traceback (most recent call last)
<ipython-input-23-b859ff1fe3d5> in <module>
      5 roi = hs.roi.Line2DROI(x1=465.577, y1=445.15, x2=169.4, y2=387.731, linewidth=0)
      6 holo.plot()
----> 7 ss = roi.interactive(holo)
      8 ss.plot()

C:\develop\anaconda\envs\hyperspy\lib\site-packages\hyperspy\roi.py in interactive(self, signal, navigation_signal, out, color, snap, **kwargs)
    382         if navigation_signal is not None:
    383             if navigation_signal not in self.signal_map:
--> 384                 self.add_widget(navigation_signal, color=color, snap=snap,
    385                                 axes=kwargs.get("axes", None))
    386         if (self.update not in

C:\develop\anaconda\envs\hyperspy\lib\site-packages\hyperspy\roi.py in add_widget(self, signal, axes, widget, color, snap, **kwargs)
    460             widget.color = color
    461             if hasattr(widget, 'snap_all'):
--> 462                 widget.snap_all = snap
    463             else:
    464                 widget.snap_position = snap

C:\develop\anaconda\envs\hyperspy\lib\site-packages\hyperspy\drawing\widget.py in <lambda>(s, v)
    617 
    618     snap_all = property(lambda s: s.snap_size and s.snap_position,
--> 619                         lambda s, v: s._set_snap_all(v))
    620 
    621     def increase_size(self):

C:\develop\anaconda\envs\hyperspy\lib\site-packages\hyperspy\drawing\widget.py in _set_snap_all(self, value)
    613     def _set_snap_all(self, value):
    614         # Snap position first, as snapped size can depend on position.
--> 615         self.snap_position = value
    616         self.snap_size = value
    617 

C:\develop\anaconda\envs\hyperspy\lib\site-packages\hyperspy\drawing\widget.py in <lambda>(s, v)
    442 
    443     snap_position = property(lambda s: s._snap_position,
--> 444                              lambda s, v: s._set_snap_position(v))
    445 
    446     def connect(self, ax):

C:\develop\anaconda\envs\hyperspy\lib\site-packages\hyperspy\drawing\widget.py in _set_snap_position(self, value)
    436         self._snap_position = value
    437         if value:
--> 438             snap_value = self._do_snap_position(self._pos)
    439             if np.any(self._pos != snap_value):
    440                 self._pos = snap_value

C:\develop\anaconda\envs\hyperspy\lib\site-packages\hyperspy\drawing\_widgets\line2d.py in _do_snap_position(self, value)
    189         value = np.array(value) if value is not None else self._pos
    190 
--> 191         ret1 = super(Line2DWidget, self)._do_snap_position(value[0, :])
    192         ret2 = super(Line2DWidget, self)._do_snap_position(value[1, :])
    193 

C:\develop\anaconda\envs\hyperspy\lib\site-packages\hyperspy\drawing\widget.py in _do_snap_position(self, value)
    430         value = np.array(value) if value is not None else self._pos
    431         for i, ax in enumerate(self.axes):
--> 432             value[i] = ax.index2value(ax.value2index(value[i]))
    433         return value
    434 

C:\develop\anaconda\envs\hyperspy\lib\site-packages\hyperspy\axes.py in value2index(self, value, rounding)
    542                 return index
    543             else:
--> 544                 raise ValueError("The value is out of the axis limits")
    545 
    546     def index2value(self, index):

ValueError: The value is out of the axis limits
@ericpre
Copy link
Member

ericpre commented Apr 26, 2021

Thanks for the bug report, I can reproduce!

There are a few things which need fixing/improvement here:

  • the bug itself!
  • the error could be more useful because it doesn't tell which axis and what are the axis bounds
  • we should have the example of the user guide tested...

@ericpre ericpre mentioned this issue Apr 26, 2021
3 tasks
@ericpre
Copy link
Member

ericpre commented Apr 26, 2021

Fixed in #2721.

In the meantime, you can use disable snapping:

import hyperspy.api as hs

holo = hs.datasets.example_signals.object_hologram()
roi = hs.roi.Line2DROI(x1=465.577, y1=445.15, x2=169.4, y2=387.731, linewidth=0)
holo.plot()
ss = roi.interactive(holo, snap=False)

@ericpre ericpre added this to the v1.6.3 milestone Apr 26, 2021
@ericpre ericpre linked a pull request Apr 27, 2021 that will close this issue
3 tasks
@ks00x
Copy link
Author

ks00x commented Apr 27, 2021

thanks, the snap workaround works for me as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants