# Sign and order of components is non deterministic.
# setting the random state to 0 makes the solution reproducible.
# Instead of the actual number of components we pass a float value
# between 0 and 1 to select n_components by a percentage of
# explained variance.

ica = ICA(n_components=0.90,
          max_n_components=100,
          noise_cov=None,
          random_state=0)

# For maximum rejection performance we will compute the decomposition on
# the entire time range

# decompose sources for raw data, select n_components by explained variance
ica.decompose_raw(raw, start=None, stop=None, picks=picks)
print ica

# setup reasonable time window for inspection
start_plot, stop_plot = raw.time_as_index([100, 103])

# plot components
ica.plot_sources_raw(raw, start=start_plot, stop=stop_plot)

###############################################################################
# Automatically find the ECG component using correlation with ECG signal

# As we don't have an ECG channel we use one that correlates a lot with heart
# beats: 'MEG 1531'. We can directly pass the name to the find_sources method.
# We select the pearson correlation from scipy stats via string label.
# The function is internally modified to be applicable to 2D arrays and,
Пример #2
0
# setting the random state to 0 makes the solution reproducible.
# Instead of the actual number of components we pass a float value
# between 0 and 1 to select n_components by a percentage of
# explained variance.

ica = ICA(n_components=0.90, max_n_components=100, noise_cov=None,
          random_state=0)
print ica

# 1 minute exposure should be sufficient for artifact detection.
# However, rejection performance may significantly improve when using
# the entire data range
start, stop = raw.time_as_index([100, 160])

# decompose sources for raw data
ica.decompose_raw(raw, start=start, stop=stop, picks=picks)
print ica

sources = ica.get_sources_raw(raw, start=start, stop=stop)

# setup reasonable time window for inspection
start_plot, stop_plot = raw.time_as_index([100, 103])

# plot components
ica.plot_sources_raw(raw, start=start_plot, stop=stop_plot)

###############################################################################
# Automatically find the ECG component using correlation with ECG signal.

# First, we create a helper function that iteratively applies the pearson
# correlation function to sources and returns an array of r values
# Setup ICA seed decompose data, then access and plot sources.

# Sign and order of components is non deterministic.
# setting the random state to 0 makes the solution reproducible.
# Instead of the actual number of components we pass a float value
# between 0 and 1 to select n_components by a percentage of
# explained variance.

ica = ICA(n_components=0.90, max_n_components=100, noise_cov=None,
          random_state=0)

# For maximum rejection performance we will compute the decomposition on
# the entire time range

# decompose sources for raw data, select n_components by explained variance
ica.decompose_raw(raw, start=None, stop=None, picks=picks)
print ica

sources = ica.get_sources_raw(raw)

# setup reasonable time window for inspection
start_plot, stop_plot = raw.time_as_index([100, 103])

# plot components
ica.plot_sources_raw(raw, start=start_plot, stop=stop_plot)

###############################################################################
# Automatically find the ECG component using correlation with ECG signal

# As we don't have an ECG channel we use one that correlates a lot with heart
# beats: 'MEG 1531'. We can directly pass the name to the find_sources method.