Esempio n. 1
0
 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'
Esempio n. 2
0
    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