Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Function for creating a rectangle on a hyperspy signal
def ROI_Rect(s, roi_XY=[], hide=False):
Plots a hyperspy signal and draws an interactive ROI on it on the top left tenth of the image.
Can take a list of [x1, y1, x2, y2] to set a known intial ROI.
Returns a tuple of (roi, roi_signal). Use hide=True to not show the plot.
Please report bugs/improvements to
import hyperspy.api as hs
if s.axes_manager.navigation_dimension < 2:
x_axis = s.axes_manager[s.axes_manager.signal_indices_in_array[1]]
y_axis = s.axes_manager[s.axes_manager.signal_indices_in_array[0]]
x_axis = s.axes_manager[s.axes_manager.navigation_indices_in_array[1]]
y_axis = s.axes_manager[s.axes_manager.navigation_indices_in_array[0]]
if not roi_XY:
x1 = x_axis.axis[1]
x2 = x_axis.axis[round(x_axis.size/10)]
y1 = y_axis.axis[1]
y2 = y_axis.axis[round(y_axis.size/10)]
[x1, y1, x2, y2] = [roi_XY.left,, roi_XY.right, roi_XY.bottom]
roi = hs.roi.RectangularROI(x1, y1, x2, y2)
roi_signal = roi.interactive(s)
if hide:
return roi, roi_signal

This comment has been minimized.

Copy link
Owner Author

commented Nov 10, 2016

screenshot 2016-11-10 14 02 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.