Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sourcespace to Report #12848

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 69 additions & 3 deletions mne/report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,21 @@ def _get_bem_contour_figs_as_arrays(
return out


def _iterate_alignment_views(function, alpha, **kwargs):
"""Auxiliary function to iterate over views in trans fig."""
from ..viz.backends.renderer import MNE_3D_BACKEND_TESTING

# TODO: Eventually maybe we should expose the size option?
size = (80, 80) if MNE_3D_BACKEND_TESTING else (800, 800)
fig = create_3d_figure(size, bgcolor=(0.5, 0.5, 0.5))
from ..viz.backends.renderer import backend

try:
return _itv(function, fig, **kwargs)
finally:
backend._close_3d_figure(fig)


def _iterate_trans_views(function, alpha, **kwargs):
"""Auxiliary function to iterate over views in trans fig."""
from ..viz.backends.renderer import MNE_3D_BACKEND_TESTING
Expand Down Expand Up @@ -1409,7 +1424,7 @@ def add_forward(
subjects_dir=subjects_dir,
title=title,
image_format=self.image_format,
section=None,
section=title,
tags=tags,
replace=replace,
)
Expand Down Expand Up @@ -2454,12 +2469,14 @@ def add_bem(
self._add_bem(
subject=subject,
subjects_dir=subjects_dir,
src=None,
decim=decim,
n_jobs=n_jobs,
width=width,
image_format=self.image_format,
title=title,
tags=tags,
section=None, # No nesting
replace=replace,
)

Expand Down Expand Up @@ -3042,6 +3059,7 @@ def _render_one_bem_axis(
surfaces,
image_format,
orientation,
src=None,
decim=2,
n_jobs=None,
width=512,
Expand All @@ -3062,7 +3080,7 @@ def _render_one_bem_axis(
mri_fname=mri_fname,
surfaces=surfaces,
orientation=orientation,
src=None,
src=src,
show=False,
show_orientation="always",
width=width,
Expand Down Expand Up @@ -3362,6 +3380,51 @@ def _add_forward(
replace=replace,
)

if self.subject:
src = forward["src"]
trans = forward["mri_head_t"]
# Alignment
kwargs = dict(
info=forward["info"],
trans=trans,
src=src,
subject=subject,
subjects_dir=subjects_dir,
meg=["helmet", "sensors"],
show_axes=True,
eeg=dict(original=0.2, projected=0.8),
coord_frame="mri",
)
img, caption = _iterate_trans_views(
function=plot_alignment, alpha=0.5, **kwargs
)
self._add_image(
img=img,
title="Alignment",
section=section,
caption=caption,
image_format="png",
tags=tags,
replace=replace,
)
# Source space
kwargs = dict(
trans=trans,
subjects_dir=subjects_dir,
)
img, caption = _iterate_alignment_views(
function=src.plot, alpha=0.5, **kwargs
)
self._add_image(
img=img,
title="Source space",
section=section,
caption=caption,
image_format="png",
tags=tags,
replace=replace,
)

def _add_inverse_operator(
self,
*,
Expand Down Expand Up @@ -4210,11 +4273,13 @@ def _add_bem(
*,
subject,
subjects_dir,
src,
decim,
n_jobs,
width=512,
image_format,
title,
section,
tags,
replace,
):
Expand All @@ -4241,6 +4306,7 @@ def _add_bem(
mri_fname=mri_fname,
surfaces=surfaces,
orientation=orientation,
src=src,
decim=decim,
n_jobs=n_jobs,
width=width,
Expand All @@ -4265,7 +4331,7 @@ def _add_bem(
)
self._add_or_replace(
title=title,
section=None, # no nesting
section=section,
tags=tags,
html_partial=html_partial,
replace=replace,
Expand Down
7 changes: 7 additions & 0 deletions mne/source_space/_source_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ def plot(
skull=None,
subjects_dir=None,
trans=None,
fig=None,
verbose=None,
):
"""Plot the source space.
Expand Down Expand Up @@ -358,6 +359,11 @@ def plot(
produced during coregistration. If trans is None, an identity
matrix is assumed. This is only needed when the source space is in
head coordinates.
fig : Figure3D | None
PyVista scene in which to plot the alignment.
If ``None``, creates a new 600x600 pixel figure with black background.

.. versionadded:: 1.9
%(verbose)s

Returns
Expand Down Expand Up @@ -427,6 +433,7 @@ def plot(
ecog=False,
bem=bem,
src=self,
fig=fig,
)

def __getitem__(self, *args, **kwargs):
Expand Down
Loading