Skip to content

MRG: Add ICA to Report - #9828

Merged
agramfort merged 23 commits into
mne-tools:mainfrom
hoechenberger:report-ica
Oct 14, 2021
Merged

agramfort merged 23 commits into
mne-tools:mainfrom
hoechenberger:report-ica

Conversation

@hoechenberger

@hoechenberger hoechenberger commented Oct 10, 2021 •

Copy link
Copy Markdown
Member

This PR adds Report.add_ica(), updates ICA.__repr__(), and adds ICA._repr_html_()

WIP:

  • Add ICA._repr_html_()
  • Add tests
  • Add tutorial
  • Add changelog entry
  • Add to parse_folder() (low prio)

Comment thread mne/report/report.py
)
fig.savefig(output, format=image_format, dpi=fig.get_dpi(),
bbox_inches='tight', pad_inches=0)
bbox_inches='tight')

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a small layout problem that we see in main

Comment thread mne/report/report.py Resolved
@hoechenberger
hoechenberger marked this pull request as ready for review October 12, 2021 20:18
@hoechenberger

Copy link
Copy Markdown
Member Author

@agramfort I'd been struggling with the Circle build for about 2h now, but I hope it will finally pass … In any case, the rest is ready for review. Let's keep our fingers crossed Circle will render something nice to look at 🤞

cov = pick_channels_cov(cov, raw.ch_names)
events = read_events(events_fname)
epochs = Epochs(raw=raw, events=events)
epochs = Epochs(raw=raw, events=events, baseline=None)

@hoechenberger hoechenberger Oct 12, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoids an ICA warning

r = Report(title='My Report')
raw = read_raw_fif(raw_fname)
raw.pick_channels(raw.ch_names[:6]).crop(0, 10)
raw.pick_channels(raw.ch_names[:6]).crop(10, None)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better suited for epoching; total data duration is approx 20 sec, so we're working with the ~same amount of data as before

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to ask, so thanks for preempting :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be more specific: I believe there were more events in that particular data segment than in the first 10 seconds

Comment on lines +693 to +694
ica_ecg_scores = ica_eog_scores = np.array([3, 0])
ica_ecg_evoked = ica_eog_evoked = epochs.average()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just faking something to speed up the tests

Comment thread tutorials/intro/70_report.py Resolved
Comment thread mne/report/report.py Resolved
@larsoner

larsoner commented Oct 12, 2021 •

Copy link
Copy Markdown
Member

I'd been struggling with the Circle build for about 2h now

Were you able to replicate the issue locally with either make clean && make html_dev-noplot (for warnings) or make clean && PATTERN=_ica make html_dev-pattern EDIT: (for examples)? It's generally much faster (and much lower CI burden) than waiting for CircleCI to round-trip

Comment thread mne/report/report.py Resolved
Comment thread mne/report/report.py Resolved
Comment thread mne/report/report.py Resolved
@hoechenberger

hoechenberger commented Oct 12, 2021 •

Copy link
Copy Markdown
Member Author

I'd been struggling with the Circle build for about 2h now

Were you able to replicate the issue locally with either make clean && make html_dev-noplot (for warnings) or make clean && PATTERN=_ica make html_dev-pattern EDIT: (for examples)? It's generally much faster (and much lower CI burden) than waiting for CircleCI to round-trip

Sorry, I was being imprecise here. I saw Circle fail and then managed to reproduce the doc build failure locally (was Matplotlib backend-dependent), and it took me a considerable amount of time to fix it there before pushing to Circle again :)

@hoechenberger hoechenberger changed the title WIP: Add ICA to Report MRG: Add ICA to Report Oct 12, 2021
@hoechenberger

Copy link
Copy Markdown
Member Author

Failing CI job is just the usual Azure timeout after passing all tests…

Comment thread tutorials/intro/70_report.py Resolved
Comment thread tutorials/intro/70_report.py Resolved
<td>{{n_pca_components}}</td>
</tr>
<tr>
<th>Explained variance</th>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the Explained variance here a bit ambiguous. You have lots of PCA comps and only 60% explained variance. TO me it means it's the explained variance on the PCA limited to 15 ICA components.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TO me it means it's the explained variance on the PCA limited to 15 ICA components.

Yes that's what it's supposed to mean. Any suggestions on how to make it less ambiguous?

@hoechenberger hoechenberger Oct 13, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could simply move the row up? so that it's directly below the "ICA", but above the "PCA" row?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this has not been addressed

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I addressed this by moving the "PCA" row on step down, so the table row order is now "ICA components, Variance explained, Available PCA components", this should reduce the ambiguity

Comment thread mne/data/html_templates.py Outdated
<td>{{n_components}}</td>
</tr>
<tr>
<th>PCA components used</th>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<th>PCA components used</th>
<th>Available PCA components</th>

and then we move it below the Explained variance row?

@hoechenberger

Copy link
Copy Markdown
Member Author

@agramfort I believe I have addressed all of your comments here.

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a commit with a spelling fix. Other than some minor stuff and potentially unresolved comments, LGTM!

Comment thread mne/viz/ica.py
from ..preprocessing.ica import _check_start_stop

if ica.current_fit == 'unfitted':
raise RuntimeError('You need to fit the ICA first')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally would have corresponding with pytest.raises in some test

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the proposed test

Comment thread tutorials/intro/70_report.py Resolved
r = Report(title='My Report')
raw = read_raw_fif(raw_fname)
raw.pick_channels(raw.ch_names[:6]).crop(0, 10)
raw.pick_channels(raw.ch_names[:6]).crop(10, None)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to ask, so thanks for preempting :)

Comment thread mne/report/report.py
Comment on lines +2445 to +2447
# XXX TODO We could render ICA components here someday
# elif _endswith(fname, 'ica') and ica:
# pass

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to add as part of this PR

@hoechenberger hoechenberger Oct 13, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally yes, but I ran into a non-trivial issue (meaning one that I couldn't resolve to my satisfaction within 15 min) and decided with @agramfort to move on for now. If you don't mind, I'd add this in a future iteration. I'm actually also a bit hesitant to put too much effort into parse_folder as I think it's quite inflexible. And for ICA, you could only provide a subset of the renderings we do with add_ica(), because you don't know which inst to demonstrate the ICA cleaning on etc.. or you'd have to expand the API of parse_folder or Report to allow users to specify one or multiple insts, and this requires discussion … I wanted to avoid all of that, at least for now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened an issue so we don't forget about this: #9844

<td>{{n_pca_components}}</td>
</tr>
<tr>
<th>Explained variance</th>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this has not been addressed

@hoechenberger

Copy link
Copy Markdown
Member Author

@larsoner Please merge if you're happy :)

@hoechenberger

Copy link
Copy Markdown
Member Author

HTML repr looks like this now:

Screen Shot 2021-10-13 at 22 50 50

@agramfort
agramfort merged commit 1b0f828 into mne-tools:main Oct 14, 2021
@agramfort

Copy link
Copy Markdown
Member

thx @hoechenberger

@hoechenberger

Copy link
Copy Markdown
Member Author

😍

@hoechenberger
hoechenberger deleted the report-ica branch December 7, 2021 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants