ROI#
|
Base class for all ROIs. |
Base class for interactive ROIs, i.e. ROIs with widget interaction. |
Region of interests (ROIs) operate on BaseSignal
instances and include widgets for interactive operation.
The following 1D ROIs are available:
Single element ROI of a 1D signal |
|
Interval ROI of a 1D signal |
The following 2D ROIs are available:
Single element ROI of a 2D signal |
|
Rectagular ROI of a 2D signal |
|
(Hollow) circular ROI of a 2D signal |
|
Line profile of a 2D signal with customisable width |
- class hyperspy.roi.BaseInteractiveROI#
Bases:
BaseROI
Base class for interactive ROIs, i.e. ROIs with widget interaction. The base class defines a lot of the common code for interacting with widgets, but inheritors need to implement the following functions:
_get_widget_type() _apply_roi2widget(widget) _set_from_widget(widget)
Sets up events.changed event, and inits HasTraits.
- add_widget(signal, axes=None, widget=None, color='green', snap=True, **kwargs)#
Add a widget to visually represent the ROI, and connect it so any changes in either are reflected in the other. Note that only one widget can be added per signal/axes combination.
- Parameters:
- signal
hyperspy.api.signals.BaseSignal
(or subclass) The signal to which the widget is added. This is used to determine which plot to add the widget to, and it supplies the axes_manager for the widget.
- axes
None
,str
,int
orhyperspy.axes.DataAxis
, defaultNone
The axes argument specifies which axes the ROI will be applied on. The axes in the collection can be either of the following:
Anything that can index the provided
axes_manager
.a tuple or list of:
anything that can index the provided
axes_manager
None
, it will check whether the widget can be added to the navigator, i.e. if dimensionality matches, and use it if possible, otherwise it will try the signal space. If none of the two attempts work, an error message will be raised.
- widgethyperspy widget or
None
, defaultNone
If specified, this is the widget that will be added. If None, the default widget will be used.
- colormatplotlib color, default
'green'
The color for the widget. Any format that matplotlib uses should be ok. This will not change the color for any widget passed with the
'widget'
argument.- snapbool, default
True
If True, the ROI will be snapped to the axes values.
- **kwargs
dict
All keyword arguments are passed to the widget constructor.
- signal
- Returns:
- hyperspy widget
The widget of the ROI.
- interactive(signal, navigation_signal='same', out=None, color='green', snap=True, **kwargs)#
Creates an interactively sliced Signal (sliced by this ROI) via
interactive()
.- Parameters:
- signal
hyperspy.api.signals.BaseSignal
(or subclass) The source signal to slice.
- navigation_signal
hyperspy.api.signals.BaseSignal
(or subclass),None
or “same” (default) The signal the ROI will be added to, for navigation purposes only. Only the source signal will be sliced. If not None, it will automatically create a widget on navigation_signal. Passing
"same"
is identical to passing the same signal to"signal"
and"navigation_signal"
, but is less ambigous, and allows “same” to be the default value.- out
hyperspy.api.signals.BaseSignal
(or subclass) If not None, it will use ‘out’ as the output instead of returning a new Signal.
- colormatplotlib color, default:
'green'
The color for the widget. Any format that matplotlib uses should be ok. This will not change the color for any widget passed with the ‘widget’ argument.
- snapbool, default
True
If True, the ROI will be snapped to the axes values.
- **kwargs
All kwargs are passed to the roi
__call__
method which is called interactively on any roi parameter change.
- signal
- Returns:
BaseSignal
(or subclass)Signal updated with the current ROI selection when the ROI is changed.
- remove_widget(signal=None, render_figure=True)#
Removing a widget from a signal consists of two tasks:
Disconnect the interactive operations associated with this ROI and the specified signal
signal
.Removing the widget from the plot.
- Parameters:
- signal
hyperspy.api.signals.BaseSignal
(or subclass) The signal from which the interactive operations will be disconnected. If None, remove from all signals.
- render_figurebool, default
True
If False, the figure will not be rendered after removing the widget in order to save redraw events.
- signal
- update()#
Function responsible for updating anything that depends on the ROI. It should be called by implementors whenever the ROI changes. This implementation updates the widgets associated with it, and triggers the changed event.
- class hyperspy.roi.BaseROI#
Bases:
HasTraits
Base class for all ROIs.
Provides some basic functionalities that are likely to be shared between all ROIs, and serve as a common type that can be checked for.
- Attributes:
- signal_map
dict
Mapping of
signal
:(widget
,axes
) to keep track to the signals (and corresponding widget/signal axes) on which the ROI has been added. This dictionary is populated inBaseInteractiveROI.add_widget()
- parameters
dict
Mapping of parameters name and values for all parameters of the ROI.
- signal_map
Sets up events.changed event, and inits HasTraits.
- is_valid()#
Determine if the ROI is in a valid state.
This is typically determined by all the coordinates being defined, and that the values makes sense relative to each other.
- update()#
Function responsible for updating anything that depends on the ROI. It should be called by implementors whenever the ROI changes. The base implementation simply triggers the changed event.