diff --git a/mne/report/report.py b/mne/report/report.py index 0f72a85b905..56959c2e816 100644 --- a/mne/report/report.py +++ b/mne/report/report.py @@ -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 @@ -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, ) @@ -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, ) @@ -3042,6 +3059,7 @@ def _render_one_bem_axis( surfaces, image_format, orientation, + src=None, decim=2, n_jobs=None, width=512, @@ -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, @@ -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, *, @@ -4210,11 +4273,13 @@ def _add_bem( *, subject, subjects_dir, + src, decim, n_jobs, width=512, image_format, title, + section, tags, replace, ): @@ -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, @@ -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, diff --git a/mne/source_space/_source_space.py b/mne/source_space/_source_space.py index 4265de0cd11..f4c932390ba 100644 --- a/mne/source_space/_source_space.py +++ b/mne/source_space/_source_space.py @@ -329,6 +329,7 @@ def plot( skull=None, subjects_dir=None, trans=None, + fig=None, verbose=None, ): """Plot the source space. @@ -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 @@ -427,6 +433,7 @@ def plot( ecog=False, bem=bem, src=self, + fig=fig, ) def __getitem__(self, *args, **kwargs):