mne.preprocessing.
ICA
(n_components=None, max_pca_components=None, n_pca_components=None, noise_cov=None, random_state=None, method='fastica', fit_params=None, max_iter=200, verbose=None)¶M/EEG signal decomposition using Independent Component Analysis (ICA)
This object can be used to estimate ICA components and then remove some from Raw or Epochs for data exploration or artifact correction.
Caveat! If supplying a noise covariance keep track of the projections available in the cov or in the raw object. For example, if you are interested in EOG or ECG artifacts, EOG and ECG projections should be temporally removed before fitting the ICA. You can say:
>> projs, raw.info['projs'] = raw.info['projs'], []
>> ica.fit(raw)
>> raw.info['projs'] = projs
Parameters: | n_components : int | float | None
max_pca_components : int | None
n_pca_components : int | float
noise_cov : None | instance of mne.cov.Covariance
random_state : None | int | instance of np.random.RandomState
method : {‘fastica’, ‘infomax’, ‘extended-infomax’}
fit_params : dict | None.
max_iter : int, optional
verbose : bool, str, int, or None
|
---|---|
Attributes: | current_fit : str
ch_names : list-like
``n_components_`` : int
n_pca_components : int
max_pca_components : int
verbose : bool, str, int, or None
``pca_components_` : ndarray
``pca_mean_`` : ndarray
``pca_explained_variance_`` : ndarray
``mixing_matrix_`` : ndarray
``unmixing_matrix_`` : ndarray
exclude : list
info : None | instance of mne.io.meas_info.Info
`n_samples_` : int
`labels_` : dict
|
Methods
apply (inst[, include, exclude, ...]) |
Remove selected components from the signal. |
copy () |
Copy the ICA object |
detect_artifacts (raw[, start_find, ...]) |
Run ICA artifacts detection workflow. |
find_bads_ecg (inst[, ch_name, threshold, ...]) |
Detect ECG related components using correlation |
find_bads_eog (inst[, ch_name, threshold, ...]) |
Detect EOG related components using correlation |
fit (inst[, picks, start, stop, decim, ...]) |
Run the ICA decomposition on raw data |
get_sources (inst[, add_channels, start, stop]) |
Estimate sources given the unmixing matrix |
plot_components ([picks, ch_type, res, ...]) |
Project unmixing matrix on interpolated sensor topography. |
plot_overlay (inst[, exclude, picks, start, ...]) |
Overlay of raw and cleaned signals given the unmixing matrix. |
plot_scores (scores[, exclude, labels, ...]) |
Plot scores related to detected components. |
plot_sources (inst[, picks, exclude, start, ...]) |
Plot estimated latent sources given the unmixing matrix. |
save (fname) |
Store ICA solution into a fiff file. |
score_sources (inst[, target, score_func, ...]) |
Assign score to components based on statistic or metric |
__init__
(n_components=None, max_pca_components=None, n_pca_components=None, noise_cov=None, random_state=None, method='fastica', fit_params=None, max_iter=200, verbose=None)¶apply
(inst, include=None, exclude=None, n_pca_components=None, start=None, stop=None, copy=False)¶Remove selected components from the signal.
Given the unmixing matrix, transform data, zero out components, and inverse transform the data. This procedure will reconstruct M/EEG signals from which the dynamics described by the excluded components is subtracted.
Parameters: | inst : instance of Raw, Epochs or Evoked
include : array_like of int.
exclude : array_like of int.
n_pca_components : int | float | None
start : int | float | None
stop : int | float | None
copy : bool
|
---|
copy
()¶Copy the ICA object
Returns: | ica : instance of ICA
|
---|
detect_artifacts
(raw, start_find=None, stop_find=None, ecg_ch=None, ecg_score_func='pearsonr', ecg_criterion=0.1, eog_ch=None, eog_score_func='pearsonr', eog_criterion=0.1, skew_criterion=-1, kurt_criterion=-1, var_criterion=0, add_nodes=None)¶Run ICA artifacts detection workflow.
Note. This is still experimental and will most likely change. Over the next releases. For maximum control use the workflow exposed in the examples.
Hints and caveats: - It is highly recommended to bandpass filter ECG and EOG data and pass them instead of the channel names as ecg_ch and eog_ch arguments. - please check your results. Detection by kurtosis and variance may be powerful but misclassification of brain signals as noise cannot be precluded. - Consider using shorter times for start_find and stop_find than for start and stop. It can save you much time.
Example invocation (taking advantage of the defaults):
ica.detect_artifacts(ecg_channel='MEG 1531', eog_channel='EOG 061')
Parameters: | raw : instance of Raw
start_find : int | float | None
stop_find : int | float | None
ecg_ch : str | ndarray | None
ecg_score_func : str | callable
ecg_criterion : float | int | list-like | slice
eog_ch : list | str | ndarray | None
eog_score_func : str | callable
eog_criterion : float | int | list-like | slice
skew_criterion : float | int | list-like | slice
kurt_criterion : float | int | list-like | slice
var_criterion : float | int | list-like | slice
add_nodes : list of ica_nodes
|
---|---|
Returns: | self : instance of ICA
|
find_bads_ecg
(inst, ch_name=None, threshold=None, start=None, stop=None, l_freq=8, h_freq=16, method='ctps', verbose=None)¶Detect ECG related components using correlation
Note. If no ECG channel is available, routine attempts to create an artificial ECG based on cross-channel averaging.
Parameters: | inst : instance of Raw, Epochs or Evoked
ch_name : str
threshold : float
start : int | float | None
stop : int | float | None
l_freq : float
h_freq : float
method : {‘ctps’, ‘correlation’}
verbose : bool, str, int, or None
|
---|---|
Returns: | ecg_idx : list of int
scores : np.ndarray of float, shape (
|
See also
References
find_bads_eog
(inst, ch_name=None, threshold=3.0, start=None, stop=None, l_freq=1, h_freq=10, verbose=None)¶Detect EOG related components using correlation
Detection is based on Pearson correlation between the filtered data and the filtered EOG channel. Thresholding is based on adaptive z-scoring. The above threshold components will be masked and the z-score will be recomputed until no supra-threshold component remains.
Parameters: | inst : instance of Raw, Epochs or Evoked
ch_name : str
threshold : int | float
start : int | float | None
stop : int | float | None
l_freq : float
h_freq : float
verbose : bool, str, int, or None
|
---|---|
Returns: | eog_idx : list of int
scores : np.ndarray of float, shape (
|
See also
fit
(inst, picks=None, start=None, stop=None, decim=None, reject=None, flat=None, tstep=2.0, verbose=None)¶Run the ICA decomposition on raw data
Caveat! If supplying a noise covariance keep track of the projections available in the cov, the raw or the epochs object. For example, if you are interested in EOG or ECG artifacts, EOG and ECG projections should be temporally removed before fitting the ICA.
Parameters: | inst : instance of Raw, Epochs or Evoked
picks : array-like of int
start : int | float | None
stop : int | float | None
decim : int | None
reject : dict | None
flat : dict | None
tstep : float
verbose : bool, str, int, or None
|
---|---|
Returns: | self : instance of ICA
|
get_sources
(inst, add_channels=None, start=None, stop=None)¶Estimate sources given the unmixing matrix
This method will return the sources in the container format passed. Typical usecases:
Parameters: | inst : instance of Raw, Epochs or Evoked
add_channels : None | list of str
start : int | float | None
stop : int | float | None
|
---|---|
Returns: | sources : instance of Raw, Epochs or Evoked
|
plot_components
(picks=None, ch_type=None, res=64, layout=None, vmin=None, vmax=None, cmap='RdBu_r', sensors=True, colorbar=False, title=None, show=True, outlines='head', contours=6, image_interp='bilinear', head_pos=None)¶Project unmixing matrix on interpolated sensor topography.
Parameters: | picks : int | array-like | None
ch_type : ‘mag’ | ‘grad’ | ‘planar1’ | ‘planar2’ | ‘eeg’ | None
res : int
layout : None | Layout
vmin : float | callable
vmax : float | callable
cmap : matplotlib colormap
sensors : bool | str
colorbar : bool
title : str | None
show : bool
outlines : ‘head’ | ‘skirt’ | dict | None
contours : int | False | None
image_interp : str
head_pos : dict | None
|
---|---|
Returns: | fig : instance of matplotlib.pyplot.Figure
|
plot_overlay
(inst, exclude=None, picks=None, start=None, stop=None, title=None, show=True)¶Overlay of raw and cleaned signals given the unmixing matrix.
This method helps visualizing signal quality and artifact rejection.
Parameters: | inst : instance of mne.io.Raw or mne.Evoked
exclude : array_like of int
picks : array-like of int | None (default)
start : int
stop : int
title : str
show : bool
|
---|---|
Returns: | fig : instance of pyplot.Figure
|
plot_scores
(scores, exclude=None, labels=None, axhline=None, title='ICA component scores', figsize=(12, 6), show=True)¶Plot scores related to detected components.
Use this function to assess how well your score describes outlier sources and how well you were detecting them.
Parameters: | scores : array_like of float, shape (n ica components,) | list of array
exclude : array_like of int
labels : str | list | ‘ecg’ | ‘eog’ | None
axhline : float
title : str
figsize : tuple of int
show : bool
|
---|---|
Returns: | fig : instance of matplotlib.pyplot.Figure
|
plot_sources
(inst, picks=None, exclude=None, start=None, stop=None, title=None, show=True, block=False)¶Plot estimated latent sources given the unmixing matrix.
Typical usecases:
Parameters: | inst : instance of mne.io.Raw, mne.Epochs, mne.Evoked
picks : ndarray | None.
exclude : array_like of int
start : int
stop : int
title : str | None
show : bool
block : bool
|
---|---|
Returns: | fig : instance of pyplot.Figure
|
Notes
For raw and epoch instances, it is possible to select components for
exclusion by clicking on the line. The selected components are added to
ica.exclude
on close. The independent components can be viewed as
topographies by clicking on the component name on the left of of the
main axes. The topography view tries to infer the correct electrode
layout from the data. This should work at least for Neuromag data.
New in version 0.10.0.
save
(fname)¶Store ICA solution into a fiff file.
Parameters: | fname : str
|
---|
score_sources
(inst, target=None, score_func='pearsonr', start=None, stop=None, l_freq=None, h_freq=None, verbose=None)¶Assign score to components based on statistic or metric
Parameters: | inst : instance of Raw, Epochs or Evoked
target : array-like | ch_name | None
score_func : callable | str label
start : int | float | None
stop : int | float | None
l_freq : float
h_freq : float
verbose : bool, str, int, or None
|
---|---|
Returns: | scores : ndarray
|