Skip to content

Add sourcespace to Report#12848

Merged
larsoner merged 47 commits intomne-tools:mainfrom
vferat:dev-report-src
Jul 7, 2025
Merged

Add sourcespace to Report#12848
larsoner merged 47 commits intomne-tools:mainfrom
vferat:dev-report-src

Conversation

@vferat
Copy link
Copy Markdown
Contributor

@vferat vferat commented Sep 13, 2024

Reference issue (if any)

Fixes #12836

What does this implement/fix?

Add a src argument to the Report.add_bem method.

Additional information

I'm not sure which strategy to adopt and changes to make to Report.parse_folder.
The Report.parse_folder method automatically adds BEM to the Report if Report.subject is specified. However, several sourcespaces -src.fif files might be present in the BEM folder and/or folder to parse.

@larsoner
Copy link
Copy Markdown
Member

For add_folder I think if a source space is found, it could be passed in during the add_bem step (assuming that happens in parse_folder, I don't remember!). Not 100% sure the right thing to do when multiple source spaces are found, could just put in whichever is first, or only add one if there is exactly one source space. I'm thinking just using the first one would make sense so that you get some sense whether or not the alignment is correct.

Another place it would be nice to add if you're motivated is in report.add_trans since that's used for making sure everything is nicely aligned, too.

Then it would be good to pass some src in the tests for report.add_bem and report.add_trans

@vferat
Copy link
Copy Markdown
Contributor Author

vferat commented Sep 16, 2024

Having looked at the many possibilities, I think the best solution would be to add a figure in the forward section:
the forward object contains all the information needed to display the source space

This solution has the advantage of being able to also display the EEG sensors projected onto the scalp, as well as displaying only the sources used in for forward computation (as some sources from the original source space may be dropped if too close to the inner skull surface). This will give a global idea of the sensors <-> sources model.

mne.viz.plot_alignment(trans=fwd["mri_head_t"], info=fwd["info"], src=fwd["src"], eeg=dict(original=0.2, projected=0.8))

image

We could also have a clearer view of the source space with an additional plot:

image

@larsoner
Copy link
Copy Markdown
Member

I like both of those plots! Adding to the forward section sounds reasonable to me

@vferat
Copy link
Copy Markdown
Contributor Author

vferat commented Feb 24, 2025

  • If subject is defined, the forward report section now includes new figures:
    • Alignement with projected EEG sensors, MEG sensors, source spaces, head model
    • BEM with sources
    • sources (3D view)
report = mne.Report(verbose=True, subject='sample', subjects_dir=subjects_dir)
report.add_forward(fwd, title="Forward")
image
  • If subject is not defined, keeps the default forward report section:
report = mne.Report(verbose=True)
report.add_forward(fwd, title="Forward")
image

@vferat vferat marked this pull request as ready for review February 24, 2025 10:17
@larsoner
Copy link
Copy Markdown
Member

larsoner commented Jun 2, 2025

@vferat looks like some tests broke, can you check?

@larsoner
Copy link
Copy Markdown
Member

@vferat it would be good to get this into 1.10 which we plan to release soon, do you have time to look at the failed tests? If not, can I take a look and see if I can fix them and push some commits?

@vferat
Copy link
Copy Markdown
Contributor Author

vferat commented Jun 27, 2025

I will try to have a look during the weekend and let you now on Monday if I can't find time to finish this

@vferat
Copy link
Copy Markdown
Contributor Author

vferat commented Jun 29, 2025

Might need some help for the failed ubuntu jobs since I don't have a Linux distro with desktop environment available

Comment thread mne/viz/misc.py Outdated
@larsoner larsoner requested a review from alexrockhill as a code owner July 7, 2025 19:07
@larsoner
Copy link
Copy Markdown
Member

larsoner commented Jul 7, 2025

Okay in dev vs this PR we get:

dev PR
image image

So I'll mark for merge-when-green, thanks in advance @vferat !

@larsoner larsoner enabled auto-merge (squash) July 7, 2025 19:33
@larsoner larsoner merged commit 715784f into mne-tools:main Jul 7, 2025
32 checks passed
Comment thread mne/report/report.py
replace=replace,
)

if subject:
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.

Hmm on second thought I think this is causing failures in CircleCI

https://app.circleci.com/pipelines/github/mne-tools/mne-bids-pipeline/5101/workflows/aa9790e5-cea0-4db5-aaf8-a2df99cdefba/jobs/81886

Not sure we should make add_forward behavior dependent on whether or not subject is passed. Technically it could be pulled from fwd["src"][0]["subject_his_id"] in most cases. I'll think on it a bit and maybe make this part opt-in with plot=False (default) | True for report.add_forward, especially since report.add_bem already exists which gives some overlapping behavior.

Comment thread mne/report/report.py
Comment on lines +3656 to +3669
self._add_bem(
subject=subject,
subjects_dir=subjects_dir,
src=src,
trans=trans,
decim=1,
n_jobs=1,
width=512,
image_format=image_format,
title="Source space(s) (BEM view)",
section=section,
tags=tags,
replace=replace,
)
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.

Okay it's this step that takes over 10 minutes (!) to compute on CIs. Since we already have report.add_bem, I don't think we actually want this here.

Rather than make this depend on subject, too, I'm going to make it not depend on subject, but add a separate plot=True by default. That way if people want the old behavior, they can get it with plot=False. And if subject is not defined, it can be pulled from the source space.

@vferat
Copy link
Copy Markdown
Contributor Author

vferat commented Jul 15, 2025

Hey @larsoner, sorry to have left you on your own on that one, it was hard to find some time to finish this.
The new behavior looks alright to me !

Thanks for the help

WouterKroot pushed a commit to WouterKroot/mne-python that referenced this pull request Aug 13, 2025
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
zEdS15B3GCwq pushed a commit to zEdS15B3GCwq/mne-python that referenced this pull request Aug 25, 2025
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
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.

MNE Report: plot source space(s)

3 participants