def __init__(self, spectrum, auto_background=True, auto_add_edges=True, ll=None, GOS=None, dictionary=None): Model.__init__(self, spectrum) self._suspend_auto_fine_structure_width = False self.convolved = False self.low_loss = ll self.GOS = GOS self.edges = list() if dictionary is not None: auto_background = False auto_add_edges = False self._load_dictionary(dictionary) if auto_background is True: interactive_ns = get_interactive_ns() background = PowerLaw() background.name = "background" warnings.warn( 'Adding "background" to the user namespace. ' "This feature will be removed in HyperSpy 0.9.", VisibleDeprecationWarning, ) interactive_ns["background"] = background self.append(background) if self.spectrum.subshells and auto_add_edges is True: self._add_edges_from_subshells_names()
def power_law_extrapolation(self, window_size=20, extrapolation_size=1024, add_noise=False, fix_neg_r=False): """Extrapolate the spectrum to the right using a powerlaw Parameters ---------- window_size : int The number of channels from the right side of the spectrum that are used to estimate the power law parameters. extrapolation_size : int Size of the extrapolation in number of channels add_noise : bool If True, add poissonian noise to the extrapolated spectrum. fix_neg_r : bool If True, the negative values for the "components.PowerLaw" parameter r will be flagged and the extrapolation will be done with a constant zero-value. Returns ------- A new spectrum, with the extrapolation. """ self._check_signal_dimension_equals_one() axis = self.axes_manager.signal_axes[0] s = self.deepcopy() s.mapped_parameters.title += (' %i channels extrapolated' % extrapolation_size) if s.tmp_parameters.has_item('filename'): s.tmp_parameters.filename += ('_%i_channels_extrapolated' % extrapolation_size) new_shape = list(self.data.shape) new_shape[axis.index_in_array] += extrapolation_size s.data = np.zeros((new_shape)) s.get_dimensions_from_data() s.data[..., :axis.size] = self.data pl = PowerLaw() pl._axes_manager = self.axes_manager pl.estimate_parameters(s, axis.index2value(axis.size - window_size), axis.index2value(axis.size - 1)) if fix_neg_r is True: _r = pl.r.map['values'] _A = pl.A.map['values'] _A[_r <= 0] = 0 pl.A.map['values'] = _A s.data[..., axis.size:] = ( pl.A.map['values'][..., np.newaxis] * s.axes_manager.signal_axes[0].axis[np.newaxis, axis.size:] **(-pl.r.map['values'][..., np.newaxis])) return s
def __init__(self, spectrum, auto_background=True, auto_add_edges=True, ll=None, GOS=None, *args, **kwargs): Model.__init__(self, spectrum, *args, **kwargs) self.convolved = False self.low_loss = ll self.GOS = GOS if auto_background is True: background = PowerLaw() background.name = 'background' interactive_ns['background'] = background self.append(background) if self.spectrum.subshells and auto_add_edges is True: self._add_edges_from_subshells_names()
def __init__(self, spectrum, auto_background=True, auto_add_edges=True, ll=None, GOS=None, *args, **kwargs): Model.__init__(self, spectrum, *args, **kwargs) self.convolved = False self.low_loss = ll self.GOS = GOS if auto_background is True: background = PowerLaw() background.name = 'background' interactive_ns['background'] = background self.append(background) if self.spectrum.subshells and auto_add_edges is True: self._add_edges_from_subshells_names()
def __init__(self, spectrum, auto_background=True, auto_add_edges=True, ll=None, GOS=None, *args, **kwargs): Model.__init__(self, spectrum, *args, **kwargs) self._suspend_auto_fine_structure_width = False self.convolved = False self.low_loss = ll self.GOS = GOS self.edges = list() if auto_background is True: interactive_ns = get_interactive_ns() background = PowerLaw() background.name = "background" interactive_ns["background"] = background self.append(background) if self.spectrum.subshells and auto_add_edges is True: self._add_edges_from_subshells_names()
def __init__(self, spectrum, auto_background=True, auto_add_edges=True, ll=None, GOS=None, dictionary=None): Model1D.__init__(self, spectrum) self._suspend_auto_fine_structure_width = False self.convolved = False self.low_loss = ll self.GOS = GOS self.edges = [] self._background_components = [] if dictionary is not None: auto_background = False auto_add_edges = False self._load_dictionary(dictionary) if auto_background is True: background = PowerLaw() self.append(background) if self.spectrum.subshells and auto_add_edges is True: self._add_edges_from_subshells_names()
def __init__(self, spectrum, auto_background=True, auto_add_edges=True, ll=None, *args, **kwargs): Model.__init__(self, spectrum, *args, **kwargs) self.ll = ll if auto_background is True: background = PowerLaw() background.name = "background" interactive_ns["background"] = background self.append(background) if self.ll is not None: self.convolved = True if self.experiments.convolution_axis is None: self.experiments.set_convolution_axis() else: self.convolved = False if self.spectrum.subshells and auto_add_edges is True: self._add_edges_from_subshells_names()
def __init__(self, spectrum, auto_background=True, auto_add_edges=True, ll=None, *args, **kwargs): Model.__init__(self, spectrum, *args, **kwargs) self.ll = ll if auto_background is True: bg = PowerLaw() interactive_ns['bg'] = bg self.append(bg) if self.ll is not None: self.convolved = True if self.experiments.convolution_axis is None: self.experiments.set_convolution_axis() else: self.convolved = False if self.spectrum.subshells and auto_add_edges is True: self._add_edges_from_subshells_names()
def power_law_extrapolation(self, window_size=20, extrapolation_size=1024, add_noise=False, fix_neg_r=False): """Extrapolate the spectrum to the right using a powerlaw Parameters ---------- window_size : int The number of channels from the right side of the spectrum that are used to estimate the power law parameters. extrapolation_size : int Size of the extrapolation in number of channels add_noise : bool If True, add poissonian noise to the extrapolated spectrum. fix_neg_r : bool If True, the negative values for the "components.PowerLaw" parameter r will be flagged and the extrapolation will be done with a constant zero-value. Returns ------- A new spectrum, with the extrapolation. """ self._check_signal_dimension_equals_one() axis = self.axes_manager.signal_axes[0] s = self.deepcopy() s.mapped_parameters.title += ( ' %i channels extrapolated' % extrapolation_size) if s.tmp_parameters.has_item('filename'): s.tmp_parameters.filename += ( '_%i_channels_extrapolated' % extrapolation_size) new_shape = list(self.data.shape) new_shape[axis.index_in_array] += extrapolation_size s.data = np.zeros((new_shape)) s.get_dimensions_from_data() s.data[...,:axis.size] = self.data pl = PowerLaw() pl._axes_manager = self.axes_manager pl.estimate_parameters( s, axis.index2value(axis.size - window_size), axis.index2value(axis.size - 1)) if fix_neg_r is True: _r = pl.r.map['values'] _A = pl.A.map['values'] _A[_r<=0] = 0 pl.A.map['values'] = _A s.data[...,axis.size:] = ( pl.A.map['values'][...,np.newaxis]* s.axes_manager.signal_axes[0].axis[np.newaxis,axis.size:]**( -pl.r.map['values'][...,np.newaxis])) return s