Created
April 27, 2017 13:15
-
-
Save thomasaarholt/a55c941e5dd3101c985bd2e4da7a1bc8 to your computer and use it in GitHub Desktop.
Hyperspy automatic Line2DROI
This file contains 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 create_Line_on_DF(s, lineROI=[], 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, linewidth] 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 thomasaarholt@gmail.com | |
""" | |
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 lineROI: | |
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)] | |
linewidth = (x_axis.axis[-1] - x_axis.axis[0]) / 20 + (y_axis.axis[-1] - y_axis.axis[0]) / 20 | |
else: | |
[x1, y1, x2, y2, linewidth] = [lineROI.x1, lineROI.y1, lineROI.x2, lineROI.y2, lineROI.linewidth] | |
s.plot() | |
roi = hs.roi.Line2DROI(x1, y1, x2, y2, linewidth) | |
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