Skip to content

Commit

Permalink
BUG: Fix bug with Report.add_ica component number (mne-tools#12156)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner authored Nov 2, 2023
1 parent 89ec1d1 commit 70a915b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
1 change: 1 addition & 0 deletions doc/changes/devel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Bugs
- Fix bug with :meth:`mne.viz.Brain.get_view` where calling :meth:`~mne.viz.Brain.show_view` with returned parameters would change the view (:gh:`12000` by `Eric Larson`_)
- Fix bug with :meth:`mne.viz.Brain.show_view` where ``distance=None`` would change the view distance (:gh:`12000` by `Eric Larson`_)
- Fix bug with :meth:`~mne.viz.Brain.add_annotation` when reading an annotation from a file with both hemispheres shown (:gh:`11946` by `Marijn van Vliet`_)
- Fix bug with reported component number and errant reporting of PCA explained variance as ICA explained variance in :meth:`mne.Report.add_ica` (:gh:`12155` by `Eric Larson`_)
- Fix bug with axis clip box boundaries in :func:`mne.viz.plot_evoked_topo` and related functions (:gh:`11999` by `Eric Larson`_)
- Fix bug with ``subject_info`` when loading data from and exporting to EDF file (:gh:`11952` by `Paul Roujansky`_)
- Fix bug where :class:`mne.Info` HTML representations listed all channel counts instead of good channel counts under the heading "Good channels" (:gh:`12145` by `Eric Larson`_)
Expand Down
19 changes: 2 additions & 17 deletions mne/report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -1669,24 +1669,9 @@ def _add_ica_properties(
figs = _plot_ica_properties_as_arrays(
ica=ica, inst=inst, picks=picks, n_jobs=n_jobs
)
rel_explained_var = (
ica.pca_explained_variance_ / ica.pca_explained_variance_.sum()
)
cum_explained_var = np.cumsum(rel_explained_var)
captions = []
for idx, rel_var, cum_var in zip(
range(len(figs)),
rel_explained_var[: len(figs)],
cum_explained_var[: len(figs)],
):
caption = (
f"ICA component {idx}. " f"Variance explained: {round(100 * rel_var)}%"
)
if idx == 0:
caption += "."
else:
caption += f" ({round(100 * cum_var)}% cumulative)."

for idx in range(len(figs)):
caption = f"ICA component {picks[idx]}."
captions.append(caption)

title = "ICA component properties"
Expand Down
7 changes: 4 additions & 3 deletions mne/report/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,10 +913,10 @@ def test_manual_report_2d(tmp_path, invisible_fig):
evoked = evokeds[0].pick("eeg")

with pytest.warns(ConvergenceWarning, match="did not converge"):
ica = ICA(n_components=2, max_iter=1, random_state=42).fit(
ica = ICA(n_components=3, max_iter=1, random_state=42).fit(
inst=raw.copy().crop(tmax=1)
)
ica_ecg_scores = ica_eog_scores = np.array([3, 0])
ica_ecg_scores = ica_eog_scores = np.array([3, 0, 0])
ica_ecg_evoked = ica_eog_evoked = epochs_without_metadata.average()

r.add_raw(raw=raw, title="my raw data", tags=("raw",), psd=True, projs=False)
Expand Down Expand Up @@ -969,12 +969,13 @@ def test_manual_report_2d(tmp_path, invisible_fig):
ica=ica,
title="my ica with raw inst",
inst=raw.copy().load_data(),
picks=[0],
picks=[2],
ecg_evoked=ica_ecg_evoked,
eog_evoked=ica_eog_evoked,
ecg_scores=ica_ecg_scores,
eog_scores=ica_eog_scores,
)
assert "ICA component 2" in r._content[-1].html
epochs_baseline = epochs_without_metadata.copy().load_data()
epochs_baseline.apply_baseline((None, 0))
r.add_ica(
Expand Down
2 changes: 1 addition & 1 deletion tutorials/intro/70_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
report.add_ica(
ica=ica,
title="ICA cleaning",
picks=[0, 1], # only plot the first two components
picks=ica.exclude, # plot the excluded EOG components
inst=raw,
eog_evoked=eog_epochs.average(),
eog_scores=eog_scores,
Expand Down

0 comments on commit 70a915b

Please sign in to comment.