def _spikes_diagnosis(self, signal_mask=None, navigation_mask=None): """Plots a histogram to help in choosing the threshold for spikes removal. Parameters ---------- signal_mask: boolean array Restricts the operation to the signal locations not marked as True (masked) navigation_mask: boolean array Restricts the operation to the navigation locations not marked as True (masked). See also -------- spikes_removal_tool """ self._check_signal_dimension_equals_one() dc = self.data if signal_mask is not None: dc = dc[..., ~signal_mask] if navigation_mask is not None: dc = dc[~navigation_mask, :] der = np.abs(np.diff(dc, 1, -1)) n = ((~navigation_mask).sum() if navigation_mask else self.axes_manager.navigation_size) # arbitrary cutoff for number of spectra necessary before histogram # data is compressed by finding maxima of each spectrum tmp = BaseSignal(der) if n < 2000 else BaseSignal( np.ravel(der.max(-1))) # get histogram signal using smart binning and plot tmph = tmp.get_histogram() tmph.plot() # Customize plot appearance plt.gca().set_title('') plt.gca().fill_between(tmph.axes_manager[0].axis, tmph.data, facecolor='#fddbc7', interpolate=True, color='none') ax = tmph._plot.signal_plot.ax axl = tmph._plot.signal_plot.ax_lines[0] axl.set_line_properties(color='#b2182b') plt.xlabel('Derivative magnitude') plt.ylabel('Log(Counts)') ax.set_yscale('log') ax.set_ylim(10 ** -1, plt.ylim()[1]) ax.set_xlim(plt.xlim()[0], 1.1 * plt.xlim()[1]) plt.draw()
def _spikes_diagnosis(self, signal_mask=None, navigation_mask=None): """Plots a histogram to help in choosing the threshold for spikes removal. Parameters ---------- signal_mask: boolean array Restricts the operation to the signal locations not marked as True (masked) navigation_mask: boolean array Restricts the operation to the navigation locations not marked as True (masked). See also -------- spikes_removal_tool """ self._check_signal_dimension_equals_one() dc = self.data if signal_mask is not None: dc = dc[..., ~signal_mask] if navigation_mask is not None: dc = dc[~navigation_mask, :] der = np.abs(np.diff(dc, 1, -1)) n = ((~navigation_mask).sum() if navigation_mask else self.axes_manager.navigation_size) # arbitrary cutoff for number of spectra necessary before histogram # data is compressed by finding maxima of each spectrum tmp = BaseSignal(der) if n < 2000 else BaseSignal(np.ravel( der.max(-1))) # get histogram signal using smart binning and plot tmph = tmp.get_histogram() tmph.plot() # Customize plot appearance plt.gca().set_title('') plt.gca().fill_between(tmph.axes_manager[0].axis, tmph.data, facecolor='#fddbc7', interpolate=True, color='none') ax = tmph._plot.signal_plot.ax axl = tmph._plot.signal_plot.ax_lines[0] axl.set_line_properties(color='#b2182b') plt.xlabel('Derivative magnitude') plt.ylabel('Log(Counts)') ax.set_yscale('log') ax.set_ylim(10**-1, plt.ylim()[1]) ax.set_xlim(plt.xlim()[0], 1.1 * plt.xlim()[1]) plt.draw()