本文整理汇总了Python中hyperspy._signals.spectrum.Spectrum.unfold方法的典型用法代码示例。如果您正苦于以下问题:Python Spectrum.unfold方法的具体用法?Python Spectrum.unfold怎么用?Python Spectrum.unfold使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hyperspy._signals.spectrum.Spectrum
的用法示例。
在下文中一共展示了Spectrum.unfold方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: blind_source_separation
# 需要导入模块: from hyperspy._signals.spectrum import Spectrum [as 别名]
# 或者: from hyperspy._signals.spectrum.Spectrum import unfold [as 别名]
#.........这里部分代码省略.........
# the correct diff_axes for the factors.
# Get diff_axes index in axes manager
if diff_axes is not None:
diff_axes = [1 + axis.index_in_axes_manager for axis in
[self.axes_manager[axis] for axis in diff_axes]]
if not on_loadings:
diff_axes = [index - self.axes_manager.navigation_dimension
for index in diff_axes]
# Select components to separate
if number_of_components is not None:
comp_list = range(number_of_components)
elif comp_list is not None:
number_of_components = len(comp_list)
else:
if lr.output_dimension is not None:
number_of_components = lr.output_dimension
comp_list = range(number_of_components)
else:
raise ValueError(
"No `number_of_components` or `comp_list` provided.")
factors = stack([factors.inav[i] for i in comp_list])
# Apply differences pre-processing if requested.
if diff_order > 0:
factors = get_derivative(factors,
diff_axes=diff_axes,
diff_order=diff_order)
if mask is not None:
# The following is a little trick to dilate the mask as
# required when operation on the differences. It exploits the
# fact that np.diff autimatically "dilates" nans. The trick has
# a memory penalty which should be low compare to the total
# memory required for the core application in most cases.
mask_diff_axes = (
[iaxis - 1 for iaxis in diff_axes]
if diff_axes is not None
else None)
mask.change_dtype("float")
mask.data[mask.data == 1] = np.nan
mask = get_derivative(mask,
diff_axes=mask_diff_axes,
diff_order=diff_order)
mask.data[np.isnan(mask.data)] = 1
mask.change_dtype("bool")
# Unfold in case the signal_dimension > 1
factors.unfold()
if mask is not None:
mask.unfold()
factors = factors.data.T[~mask.data]
else:
factors = factors.data.T
# Center and scale the data
factors, invsqcovmat = centering_and_whitening(factors)
# Perform actual BSS
if algorithm == 'orthomax':
_, unmixing_matrix = orthomax(factors, **kwargs)
unmixing_matrix = unmixing_matrix.T
elif algorithm == 'sklearn_fastica':
if not import_sklearn.sklearn_installed:
raise ImportError(
"The optional package scikit learn is not installed "
"and it is required for this feature.")
if 'tol' not in kwargs:
kwargs['tol'] = 1e-10
lr.bss_node = import_sklearn.FastICA(
**kwargs)
lr.bss_node.whiten = False
lr.bss_node.fit(factors)
try:
unmixing_matrix = lr.bss_node.unmixing_matrix_
except AttributeError:
# unmixing_matrix was renamed to components
unmixing_matrix = lr.bss_node.components_
else:
if mdp_installed is False:
raise ImportError(
'MDP is not installed. Nothing done')
temp_function = getattr(mdp.nodes, algorithm + "Node")
lr.bss_node = temp_function(**kwargs)
lr.bss_node.train(factors)
unmixing_matrix = lr.bss_node.get_recmatrix()
w = np.dot(unmixing_matrix, invsqcovmat)
if lr.explained_variance is not None:
# The output of ICA is not sorted in any way what makes it
# difficult to compare results from different unmixings. The
# following code is an experimental attempt to sort them in a
# more predictable way
sorting_indices = np.argsort(np.dot(
lr.explained_variance[:number_of_components],
np.abs(w.T)))[::-1]
w[:] = w[sorting_indices, :]
lr.unmixing_matrix = w
lr.on_loadings = on_loadings
self._unmix_components()
self._auto_reverse_bss_component(lr)
lr.bss_algorithm = algorithm