ROI#

BaseROI()

Base class for all ROIs.

BaseInteractiveROI()

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:

1D ROIs#

Point1DROI

Single element ROI of a 1D signal

SpanROI

Interval ROI of a 1D signal

The following 2D ROIs are available:

2D ROIs#

Point2DROI

Single element ROI of a 2D signal

RectangularROI

Rectagular ROI of a 2D signal

CircleROI

(Hollow) circular ROI of a 2D signal

Line2DROI

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:
signalhyperspy.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.

axesNone, str, int or hyperspy.axes.DataAxis, default None

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:

  • 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, default None

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.

**kwargsdict

All keyword arguments are passed to the widget constructor.

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:
signalhyperspy.api.signals.BaseSignal (or subclass)

The source signal to slice.

navigation_signalhyperspy.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.

outhyperspy.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.

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:

  1. Disconnect the interactive operations associated with this ROI and the specified signal signal.

  2. Removing the widget from the plot.

Parameters:
signalhyperspy.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.

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_mapdict

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 in BaseInteractiveROI.add_widget()

parametersdict

Mapping of parameters name and values for all parameters of the ROI.

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.