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 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