Last active
November 10, 2016 14:02
-
-
Save thomasaarholt/bcb473a20cc2fd40cbf4925ee5dead19 to your computer and use it in GitHub Desktop.
Function for creating a rectangle on a hyperspy signal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 [email protected] | |
""" | |
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]] | |
else: | |
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)] | |
else: | |
[x1, y1, x2, y2] = [roi_XY.left, roi_XY.top, roi_XY.right, roi_XY.bottom] | |
s.plot() | |
roi = hs.roi.RectangularROI(x1, y1, x2, y2) | |
roi_signal = roi.interactive(s) | |
if hide: | |
s._plot.close() | |
return roi, roi_signal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Screenshot:
