def estimate_parameters(self, signal, x1, x2, only_current=False): """Estimate the Voigt function by calculating the momenta of the Gaussian. Parameters ---------- signal : Signal1D instance x1 : float Defines the left limit of the spectral range to use for the estimation. x2 : float Defines the right limit of the spectral range to use for the estimation. only_current : bool If False estimates the parameters for the full dataset. Returns ------- : bool Exit status required for the :meth:`remove_background` function. Notes ----- Adapted from http://www.scipy.org/Cookbook/FittingData Examples -------- >>> g = hs.model.components1D.Voigt(legacy=False) >>> x = np.arange(-10, 10, 0.01) >>> data = np.zeros((32, 32, 2000)) >>> data[:] = g.function(x).reshape((1, 1, 2000)) >>> s = hs.signals.Signal1D(data) >>> s.axes_manager[-1].offset = -10 >>> s.axes_manager[-1].scale = 0.01 >>> g.estimate_parameters(s, -10, 10, False) """ super(Voigt, self)._estimate_parameters(signal) axis = signal.axes_manager.signal_axes[0] centre, height, sigma = _estimate_gaussian_parameters( signal, x1, x2, only_current) if only_current is True: self.centre.value = centre self.sigma.value = sigma self.area.value = height * sigma * sqrt2pi if self.binned: self.area.value /= axis.scale return True else: if self.area.map is None: self._create_arrays() self.area.map['values'][:] = height * sigma * sqrt2pi if self.binned: self.area.map['values'][:] /= axis.scale self.area.map['is_set'][:] = True self.sigma.map['values'][:] = sigma self.sigma.map['is_set'][:] = True self.centre.map['values'][:] = centre self.centre.map['is_set'][:] = True self.fetch_stored_values() return True
def estimate_parameters(self, signal, x1, x2, only_current=False): """Estimate the gaussian by calculating the momenta. Parameters ---------- signal : Signal1D instance x1 : float Defines the left limit of the spectral range to use for the estimation. x2 : float Defines the right limit of the spectral range to use for the estimation. only_current : bool If False estimates the parameters for the full dataset. Returns ------- bool Notes ----- Adapted from http://www.scipy.org/Cookbook/FittingData Examples -------- >>> g = hs.model.components1D.GaussianHF() >>> x = np.arange(-10, 10, 0.01) >>> data = np.zeros((32, 32, 2000)) >>> data[:] = g.function(x).reshape((1, 1, 2000)) >>> s = hs.signals.Signal1D(data) >>> s.axes_manager[-1].offset = -10 >>> s.axes_manager[-1].scale = 0.01 >>> g.estimate_parameters(s, -10, 10, False) """ super()._estimate_parameters(signal) axis = signal.axes_manager.signal_axes[0] centre, height, sigma = _estimate_gaussian_parameters( signal, x1, x2, only_current) scaling_factor = _get_scaling_factor(signal, axis, centre) if only_current is True: self.centre.value = centre self.fwhm.value = sigma * sigma2fwhm self.height.value = float(height) if is_binned(signal): # in v2 replace by #if axis.is_binned: self.height.value /= scaling_factor return True else: if self.height.map is None: self._create_arrays() self.height.map['values'][:] = height if is_binned(signal): # in v2 replace by #if axis.is_binned: self.height.map['values'][:] /= scaling_factor self.height.map['is_set'][:] = True self.fwhm.map['values'][:] = sigma * sigma2fwhm self.fwhm.map['is_set'][:] = True self.centre.map['values'][:] = centre self.centre.map['is_set'][:] = True self.fetch_stored_values() return True
def estimate_parameters(self, signal, x1, x2, only_current=False): """Estimate the Donach by calculating the median (centre) and the variance parameter (sigma). Note that an insufficient range will affect the accuracy of this method and that this method doesn't estimate the asymmetry parameter (alpha). Parameters ---------- signal : Signal1D instance x1 : float Defines the left limit of the spectral range to use for the estimation. x2 : float Defines the right limit of the spectral range to use for the estimation. only_current : bool If False estimates the parameters for the full dataset. Returns ------- bool Returns True when the parameters estimation is successful Examples -------- >>> g = hs.model.components1D.Lorentzian() >>> x = np.arange(-10, 10, 0.01) >>> data = np.zeros((32, 32, 2000)) >>> data[:] = g.function(x).reshape((1, 1, 2000)) >>> s = hs.signals.Signal1D(data) >>> s.axes_manager[-1].offset = -10 >>> s.axes_manager[-1].scale = 0.01 >>> g.estimate_parameters(s, -10, 10, False) """ super()._estimate_parameters(signal) axis = signal.axes_manager.signal_axes[0] centre, height, sigma = _estimate_gaussian_parameters( signal, x1, x2, only_current) scaling_factor = _get_scaling_factor(signal, axis, centre) if only_current is True: self.centre.value = centre self.sigma.value = sigma self.A.value = height * 1.3 if is_binned(signal): # in v2 replace by #if axis.is_binned: self.A.value /= scaling_factor return True else: if self.A.map is None: self._create_arrays() self.A.map['values'][:] = height * 1.3 if is_binned(signal): # in v2 replace by #if axis.is_binned: self.A.map['values'][:] /= scaling_factor self.A.map['is_set'][:] = True self.sigma.map['values'][:] = sigma self.sigma.map['is_set'][:] = True self.centre.map['values'][:] = centre self.centre.map['is_set'][:] = True self.fetch_stored_values() return True
def estimate_parameters(self, signal, x1, x2, only_current=False): """Estimate the gaussian by calculating the momenta. Parameters ---------- signal : Signal instance x1 : float Defines the left limit of the spectral range to use for the estimation. x2 : float Defines the right limit of the spectral range to use for the estimation. only_current : bool If False estimates the parameters for the full dataset. Returns ------- bool Notes ----- Adapted from http://www.scipy.org/Cookbook/FittingData Examples -------- >>> g = hs.model.components.GaussianHF() >>> x = np.arange(-10, 10, 0.01) >>> data = np.zeros((32, 32, 2000)) >>> data[:] = g.function(x).reshape((1, 1, 2000)) >>> s = hs.signals.Spectrum(data) >>> s.axes_manager._axes[-1].offset = -10 >>> s.axes_manager._axes[-1].scale = 0.01 >>> g.estimate_parameters(s, -10, 10, False) """ binned = signal.metadata.Signal.binned axis = signal.axes_manager.signal_axes[0] centre, height, sigma = _estimate_gaussian_parameters(signal, x1, x2, only_current) if only_current is True: self.centre.value = centre self.fwhm.value = sigma * sigma2fwhm self.height.value = float(height) if binned is True: self.height.value /= axis.scale return True else: if self.height.map is None: self._create_arrays() self.height.map['values'][:] = height if binned is True: self.height.map['values'][:] /= axis.scale self.height.map['is_set'][:] = True self.fwhm.map['values'][:] = sigma * sigma2fwhm self.fwhm.map['is_set'][:] = True self.centre.map['values'][:] = centre self.centre.map['is_set'][:] = True self.fetch_stored_values() return True