Skip to content

Commit

Permalink
add ref in tutorial, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrockhill committed Apr 18, 2022
1 parent 7eab656 commit 6894198
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
3 changes: 1 addition & 2 deletions examples/preprocessing/muscle_ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@

# %%
# Compare to EEGBCI dataset
# Note that the ICA for the third subject got

muscle_idxs = {1: [9], 2: [5, 10, 12, 13, 14]}
for sub in (1, 2, 3):
for sub, muscle_idx in muscle_idxs.items():
raw = mne.io.read_raw_edf(
mne.datasets.eegbci.load_data(subject=sub, runs=(1,))[0], preload=True)
mne.datasets.eegbci.standardize(raw) # set channel names
Expand Down
4 changes: 2 additions & 2 deletions mne/preprocessing/ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -1648,16 +1648,16 @@ def find_bads_muscle(self, inst, threshold=0.5, start=None,
# compute metric #2: distance from the vertex of focus
components_norm = abs(components) / np.max(abs(components), axis=0)
pos = _find_topomap_coords(inst.info, picks='data', sphere=sphere)
assert pos.shape[0] == components.shape[0] # pos for each component
assert pos.shape[0] == components.shape[0] # pos for each sensor
pos -= pos.mean(axis=0) # center
dists = np.linalg.norm(pos, axis=1)
dists /= dists.max()
focus_dists = np.dot(dists, components_norm)

# compute metric #3: smoothness
smoothnesses = np.zeros((components.shape[1],))
dists = squareform(pdist(pos))
dists = 1 - (dists / dists.max()) # invert
smoothnesses = np.zeros((components.shape[1],))
for idx, comp in enumerate(components.T):
comp_dists = squareform(pdist(comp[:, np.newaxis]))
comp_dists /= comp_dists.max()
Expand Down
4 changes: 2 additions & 2 deletions mne/preprocessing/tests/test_ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -1324,8 +1324,8 @@ def test_ica_labels():

scores = ica.find_bads_muscle(raw)[1]
assert 'muscle' in ica.labels_
assert ica.labels_['muscle'] == [0, 1, 2, 3]
assert_allclose(scores, [0.2, 0.25, 0.35, 0.55], atol=0.03)
assert ica.labels_['muscle'] == [0]
assert_allclose(scores, [0.56, 0.01, 0.03, 0.00], atol=0.03)


@requires_sklearn
Expand Down
5 changes: 5 additions & 0 deletions tutorials/preprocessing/40_artifact_correction_ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,11 @@
# of automated approaches like `~mne.preprocessing.ICA.find_bads_ecg`
# before accepting them.

# %%
# For EEG, activation of muscles for postural control of the head and neck
# contaminate the signal as well. This is usually not detected by MEG. For
# an example showing how to remove these components, see :ref:`ex-muscle-ica`.

# clean up memory before moving on
del raw, ica, new_ica

Expand Down

0 comments on commit 6894198

Please sign in to comment.