def set_background_estimator(self): if self.background_type == 'Power Law': self.background_estimator = components1d.PowerLaw() self.bg_line_range = 'from_left_range' elif self.background_type == 'Gaussian': self.background_estimator = components1d.Gaussian() self.bg_line_range = 'full' elif self.background_type == 'Offset': self.background_estimator = components1d.Offset() self.bg_line_range = 'full' elif self.background_type == 'Polynomial': self.background_estimator = components1d.Polynomial( self.polynomial_order) self.bg_line_range = 'full'
def add_polynomial_background(self, order=6): """ Add a polynomial background. the background is added to self.background_components Parameters ---------- order: int The order of the polynomial """ background = create_component.Polynomial(order=order) background.name = 'background_order_' + str(order) background.isbackground = True self.append(background) self.background_components.append(background)
def add_polynomial_background(self, order=6): """ Add a polynomial background. the background is added to self.background_components Parameters ---------- order: int The order of the polynomial """ with ignore_warning(message="The API of the `Polynomial` component"): background = create_component.Polynomial(order=order, legacy=False) background.name = 'background_order_' + str(order) background.isbackground = True self.append(background) self.background_components.append(background)
def test_plot_BackgroundRemoval_change_background(): pl = components1d.PowerLaw() pl.A.value = 1e10 pl.r.value = 3 s = signals.Signal1D(pl.function(np.arange(100, 200))) s.axes_manager[0].offset = 100 s.add_gaussian_noise(100) br = BackgroundRemoval(s, background_type='Power Law', polynomial_order=2, fast=False, plot_remainder=True) br.span_selector.extents = (105, 150) # will draw the line br.span_selector_changed() # will update the right axis br.span_selector_changed() assert isinstance(br.background_estimator, components1d.PowerLaw) br.background_type = 'Polynomial' assert isinstance(br.background_estimator, type(components1d.Polynomial(legacy=False)))
def remove_background(self, signal_range='interactive', background_type='PowerLaw', polynomial_order=2, fast=True, show_progressbar=None): """Remove the background, either in place using a gui or returned as a new spectrum using the command line. Parameters ---------- signal_range : tuple, optional If this argument is not specified, the signal range has to be selected using a GUI. And the original spectrum will be replaced. If tuple is given, the a spectrum will be returned. background_type : string The type of component which should be used to fit the background. Possible components: PowerLaw, Gaussian, Offset, Polynomial If Polynomial is used, the polynomial order can be specified polynomial_order : int, default 2 Specify the polynomial order if a Polynomial background is used. fast : bool If True, perform an approximative estimation of the parameters. If False, the signal is fitted using non-linear least squares afterwards.This is slower compared to the estimation but possibly more accurate. show_progressbar : None or bool If True, display a progress bar. If None the default is set in `preferences`. Examples -------- Using gui, replaces spectrum s >>>> s.remove_background() Using command line, returns a spectrum >>>> s = s.remove_background(signal_range=(400,450), background_type='PowerLaw') Using a full model to fit the background >>>> s = s.remove_background(signal_range=(400,450), fast=False) Raises ------ SignalDimensionError if the signal dimension is not 1. """ self._check_signal_dimension_equals_one() if signal_range == 'interactive': br = BackgroundRemoval(self) br.edit_traits() else: if background_type == 'PowerLaw': background_estimator = components1d.PowerLaw() elif background_type == 'Gaussian': background_estimator = components1d.Gaussian() elif background_type == 'Offset': background_estimator = components1d.Offset() elif background_type == 'Polynomial': background_estimator = components1d.Polynomial( polynomial_order) else: raise ValueError("Background type: " + background_type + " not recognized") spectra = self._remove_background_cli( signal_range=signal_range, background_estimator=background_estimator, fast=fast, show_progressbar=show_progressbar) return spectra