def __call__(self, signal, axes=None, order=0): """Slice the signal according to the ROI, and return it. Arguments --------- signal : Signal The signal to slice with the ROI. axes : specification of axes to use, default = None The axes argument specifies which axes the ROI will be applied on. The items in the collection can be either of the following: * a tuple of: - DataAxis. These will not be checked with signal.axes_manager. - anything that will index signal.axes_manager * For any other value, it will check whether the navigation space can fit the right number of axis, and use that if it fits. If not, it will try the signal space. """ if axes is None and signal in self.signal_map: axes = self.signal_map[signal][1] else: axes = self._parse_axes(axes, signal.axes_manager) linewidth = self.linewidth / np.min([ax.scale for ax in axes]) profile = Line2DROI.profile_line(signal.data, (self.x1, self.y1), (self.x2, self.y2), axes=axes, linewidth=linewidth, order=order) length = np.linalg.norm(np.diff(np.array( ((self.x1, self.y1), (self.x2, self.y2))), axis=0), axis=1)[0] axm = signal.axes_manager.deepcopy() idx = [] for ax in axes: idx.append(ax.index_in_axes_manager) for i in reversed(sorted(idx)): # Remove in reversed order axm.remove(i) axis = DataAxis(len(profile), scale=length / len(profile), units=axes[0].units, navigate=axes[0].navigate) axis.axes_manager = axm i0 = min(axes[0].index_in_array, axes[1].index_in_array) axm._axes.insert(i0, axis) from hyperspy.signals import Signal roi = Signal(profile, axes=axm._get_axes_dicts(), metadata=signal.metadata.deepcopy().as_dictionary(), original_metadata=signal.original_metadata.deepcopy(). as_dictionary()) return roi
def __call__(self, signal, axes=None, order=0): """Slice the signal according to the ROI, and return it. Arguments --------- signal : Signal The signal to slice with the ROI. axes : specification of axes to use, default = None The axes argument specifies which axes the ROI will be applied on. The items in the collection can be either of the following: * a tuple of: - DataAxis. These will not be checked with signal.axes_manager. - anything that will index signal.axes_manager * For any other value, it will check whether the navigation space can fit the right number of axis, and use that if it fits. If not, it will try the signal space. """ if axes is None and signal in self.signal_map: axes = self.signal_map[signal][1] else: axes = self._parse_axes(axes, signal.axes_manager) linewidth = self.linewidth / np.min([ax.scale for ax in axes]) profile = Line2DROI.profile_line(signal.data, (self.x1, self.y1), (self.x2, self.y2), axes=axes, linewidth=linewidth, order=order) length = np.linalg.norm(np.diff( np.array(((self.x1, self.y1), (self.x2, self.y2))), axis=0), axis=1)[0] axm = signal.axes_manager.deepcopy() idx = [] for ax in axes: idx.append(ax.index_in_axes_manager) for i in reversed(sorted(idx)): # Remove in reversed order axm.remove(i) axis = DataAxis(len(profile), scale=length / len(profile), units=axes[0].units, navigate=axes[0].navigate) axis.axes_manager = axm i0 = min(axes[0].index_in_array, axes[1].index_in_array) axm._axes.insert(i0, axis) from hyperspy.signals import Signal roi = Signal(profile, axes=axm._get_axes_dicts(), metadata=signal.metadata.deepcopy().as_dictionary(), original_metadata=signal.original_metadata. deepcopy().as_dictionary()) return roi
def __call__(self, signal, out=None, axes=None, order=0): """Slice the signal according to the ROI, and return it. Arguments --------- signal : Signal The signal to slice with the ROI. out : Signal, default = None If the 'out' argument is supplied, the sliced output will be put into this instead of returning a Signal. See Signal.__getitem__() for more details on 'out'. axes : specification of axes to use, default = None The axes argument specifies which axes the ROI will be applied on. The items in the collection can be either of the following: * a tuple of: - DataAxis. These will not be checked with signal.axes_manager. - anything that will index signal.axes_manager * For any other value, it will check whether the navigation space can fit the right number of axis, and use that if it fits. If not, it will try the signal space. order : The spline interpolation order to use when extracting the line profile. 0 means nearest-neighbor interpolation, and is both the default and the fastest. """ if axes is None and signal in self.signal_map: axes = self.signal_map[signal][1] else: axes = self._parse_axes(axes, signal.axes_manager) profile = Line2DROI.profile_line(signal.data, (self.x1, self.y1), (self.x2, self.y2), axes=axes, linewidth=self.linewidth, order=order) length = np.linalg.norm(np.diff(np.array( ((self.x1, self.y1), (self.x2, self.y2))), axis=0), axis=1)[0] if out is None: axm = signal.axes_manager.deepcopy() i0 = min(axes[0].index_in_array, axes[1].index_in_array) axm.remove([ax.index_in_array + 3j for ax in axes]) axis = DataAxis(profile.shape[i0], scale=length / profile.shape[i0], units=axes[0].units, navigate=axes[0].navigate) axis.axes_manager = axm axm._axes.insert(i0, axis) from hyperspy.signals import BaseSignal roi = BaseSignal( profile, axes=axm._get_axes_dicts(), metadata=signal.metadata.deepcopy().as_dictionary(), original_metadata=signal.original_metadata.deepcopy( ).as_dictionary()) return roi else: out.data = profile i0 = min(axes[0].index_in_array, axes[1].index_in_array) ax = out.axes_manager._axes[i0] size = len(profile) scale = length / len(profile) axchange = size != ax.size or scale != ax.scale if axchange: ax.size = len(profile) ax.scale = length / len(profile) out.events.data_changed.trigger(out)
def __call__(self, signal, out=None, axes=None, order=0): """Slice the signal according to the ROI, and return it. Arguments --------- signal : Signal The signal to slice with the ROI. out : Signal, default = None If the 'out' argument is supplied, the sliced output will be put into this instead of returning a Signal. See Signal.__getitem__() for more details on 'out'. axes : specification of axes to use, default = None The axes argument specifies which axes the ROI will be applied on. The items in the collection can be either of the following: * a tuple of: - DataAxis. These will not be checked with signal.axes_manager. - anything that will index signal.axes_manager * For any other value, it will check whether the navigation space can fit the right number of axis, and use that if it fits. If not, it will try the signal space. order : The spline interpolation order to use when extracting the line profile. 0 means nearest-neighbor interpolation, and is both the default and the fastest. """ if axes is None and signal in self.signal_map: axes = self.signal_map[signal][1] else: axes = self._parse_axes(axes, signal.axes_manager) linewidth = self.linewidth / np.min([ax.scale for ax in axes]) profile = Line2DROI.profile_line(signal.data, (self.x1, self.y1), (self.x2, self.y2), axes=axes, linewidth=linewidth, order=order) length = np.linalg.norm(np.diff( np.array(((self.x1, self.y1), (self.x2, self.y2))), axis=0), axis=1)[0] if out is None: axm = signal.axes_manager.deepcopy() i0 = min(axes[0].index_in_array, axes[1].index_in_array) axm.remove([ax.index_in_array + 3j for ax in axes]) axis = DataAxis(profile.shape[i0], scale=length / profile.shape[i0], units=axes[0].units, navigate=axes[0].navigate) axis.axes_manager = axm axm._axes.insert(i0, axis) from hyperspy.signals import BaseSignal roi = BaseSignal(profile, axes=axm._get_axes_dicts(), metadata=signal.metadata.deepcopy( ).as_dictionary(), original_metadata=signal.original_metadata. deepcopy().as_dictionary()) return roi else: out.data = profile i0 = min(axes[0].index_in_array, axes[1].index_in_array) ax = out.axes_manager._axes[i0] size = len(profile) scale = length / len(profile) axchange = size != ax.size or scale != ax.scale if axchange: ax.size = len(profile) ax.scale = length / len(profile) out.events.data_changed.trigger(out)