本文整理汇总了Python中hyperspy._signals.spectrum.Spectrum.smooth_tv方法的典型用法代码示例。如果您正苦于以下问题:Python Spectrum.smooth_tv方法的具体用法?Python Spectrum.smooth_tv怎么用?Python Spectrum.smooth_tv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hyperspy._signals.spectrum.Spectrum
的用法示例。
在下文中一共展示了Spectrum.smooth_tv方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: blind_source_separation
# 需要导入模块: from hyperspy._signals.spectrum import Spectrum [as 别名]
# 或者: from hyperspy._signals.spectrum.Spectrum import smooth_tv [as 别名]
def blind_source_separation(self,
number_of_components=None,
algorithm='sklearn_fastica',
diff_order=1,
factors=None,
comp_list=None,
mask=None,
on_loadings=False,
pretreatment=None,
**kwargs):
"""Blind source separation (BSS) on the result on the
decomposition.
Available algorithms: FastICA, JADE, CuBICA, and TDSEP
Parameters
----------
number_of_components : int
number of principal components to pass to the BSS algorithm
algorithm : {FastICA, JADE, CuBICA, TDSEP}
diff_order : int
Sometimes it is convenient to perform the BSS on the derivative
of the signal. If diff_order is 0, the signal is not differentiated.
factors : numpy.array
Factors to decompose. If None, the BSS is performed on the result
of a previous decomposition.
comp_list : boolen numpy array
choose the components to use by the boolean list. It permits
to choose non contiguous components.
mask : numpy boolean array with the same dimension as the signal
If not None, the signal locations marked as True (masked) will
not be passed to the BSS algorithm.
on_loadings : bool
If True, perform the BSS on the loadings of a previous
decomposition. If False, performs it on the factors.
pretreatment: dict
**kwargs : extra key word arguments
Any keyword arguments are passed to the BSS algorithm.
"""
target=self.learning_results
if not hasattr(target, 'factors') or target.factors==None:
raise AttributeError(
'A decomposition must be performed before blind '
'source seperation or factors must be provided.')
else:
if factors is None:
if on_loadings:
factors = target.loadings
else:
factors = target.factors
bool_index = np.zeros((factors.shape[0]), dtype = 'bool')
if number_of_components is not None:
bool_index[:number_of_components] = True
else:
if target.output_dimension is not None:
number_of_components = target.output_dimension
bool_index[:number_of_components] = True
if comp_list is not None:
for ifactors in comp_list:
bool_index[ifactors] = True
number_of_components = len(comp_list)
factors = factors[:,bool_index]
if pretreatment is not None:
from hyperspy._signals.spectrum import Spectrum
sfactors = Spectrum(factors.T)
if pretreatment['algorithm'] == 'savitzky_golay':
sfactors.smooth_savitzky_golay(
number_of_points=pretreatment[
'number_of_points'],
polynomial_order=pretreatment[
'polynomial_order'],
differential_order = diff_order)
if pretreatment['algorithm'] == 'tv':
sfactors.smooth_tv(
smoothing_parameter= pretreatment[
'smoothing_parameter'],
differential_order = diff_order)
factors = sfactors.data.T
if pretreatment['algorithm'] == 'butter':
b, a = sp.signal.butter(pretreatment['order'],
pretreatment['cutoff'], pretreatment['type'])
for i in range(factors.shape[1]):
factors[:,i] = sp.signal.filtfilt(b,a,
factors[:,i])
elif diff_order > 0:
factors = np.diff(factors, diff_order, axis=0)
if mask is not None:
factors = factors[~mask]
# first center and scale the data
factors,invsqcovmat = centering_and_whitening(factors)
if algorithm == 'orthomax':
_, unmixing_matrix = orthomax(factors, **kwargs)
unmixing_matrix = unmixing_matrix.T
#.........这里部分代码省略.........