-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add sourcespace to Report #12848
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
Changes from all commits
7c80b70
e464260
1710b11
690945a
00c60fa
b2da283
924c029
26b6a42
f7fa3b8
712ba43
45a4fa1
031fa66
dd59dfe
175a622
9226b32
b7529b5
3f80b8f
d8a7a41
0136108
5f38c72
6103859
8664b45
ea20780
d24ebde
64c1e13
aac99fb
5d9ef52
665610b
0f556f7
0d547dd
0468218
7f70ad5
42eb09f
5f9e0e3
b483bf4
c2abd6a
35be9a7
b18ca44
137c25b
439ced5
45f5eb4
eb94cef
f9d97a6
1890199
8398347
88a21f8
d294ffe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add source space(s) visualization(s) in :func:`mne.Report.add_forward`, by `Victor Ferat`_. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -475,7 +475,17 @@ def _fig_to_img( | |
|
|
||
|
|
||
| def _get_bem_contour_figs_as_arrays( | ||
| *, sl, n_jobs, mri_fname, surfaces, orientation, src, show, show_orientation, width | ||
| *, | ||
| sl, | ||
| n_jobs, | ||
| mri_fname, | ||
| surfaces, | ||
| orientation, | ||
| src, | ||
| trans, | ||
| show, | ||
| show_orientation, | ||
| width, | ||
| ): | ||
| """Render BEM surface contours on MRI slices. | ||
|
|
||
|
|
@@ -494,6 +504,7 @@ def _get_bem_contour_figs_as_arrays( | |
| surfaces=surfaces, | ||
| orientation=orientation, | ||
| src=src, | ||
| trans=trans, | ||
| show=show, | ||
| show_orientation=show_orientation, | ||
| width=width, | ||
|
|
@@ -507,6 +518,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 | ||
|
|
@@ -531,7 +557,18 @@ def _itv(function, fig, *, max_width=MAX_IMG_WIDTH, max_res=MAX_IMG_RES, **kwarg | |
|
|
||
| function(fig=fig, **kwargs) | ||
|
|
||
| views = ("frontal", "lateral", "medial", "axial", "rostral", "coronal") | ||
| views = ( | ||
| "right_lateral", | ||
| "right_anterolateral", | ||
| "anterior", | ||
| "left_anterolateral", | ||
| "left_lateral", | ||
| "superior", | ||
| "right_posterolateral", | ||
| "posterior", | ||
| "left_posterolateral", | ||
| "inferior", | ||
| ) | ||
|
|
||
| images = [] | ||
| for view in views: | ||
|
|
@@ -544,7 +581,7 @@ def _itv(function, fig, *, max_width=MAX_IMG_WIDTH, max_res=MAX_IMG_RES, **kwarg | |
| images.append(im) | ||
|
|
||
| images = np.concatenate( | ||
| [np.concatenate(images[:3], axis=1), np.concatenate(images[3:], axis=1)], axis=0 | ||
| [np.concatenate(images[:5], axis=1), np.concatenate(images[5:], axis=1)], axis=0 | ||
| ) | ||
|
|
||
| try: | ||
|
|
@@ -2655,6 +2692,8 @@ def add_bem( | |
| self._add_bem( | ||
| subject=subject, | ||
| subjects_dir=subjects_dir, | ||
| src=None, | ||
| trans=None, | ||
| decim=decim, | ||
| n_jobs=n_jobs, | ||
| width=width, | ||
|
|
@@ -3245,6 +3284,8 @@ def _render_one_bem_axis( | |
| surfaces, | ||
| image_format, | ||
| orientation, | ||
| src=None, | ||
| trans=None, | ||
| decim=2, | ||
| n_jobs=None, | ||
| width=512, | ||
|
|
@@ -3265,7 +3306,8 @@ def _render_one_bem_axis( | |
| mri_fname=mri_fname, | ||
| surfaces=surfaces, | ||
| orientation=orientation, | ||
| src=None, | ||
| src=src, | ||
| trans=trans, | ||
| show=False, | ||
| show_orientation="always", | ||
| width=width, | ||
|
|
@@ -3574,6 +3616,89 @@ def _add_forward( | |
| replace=replace, | ||
| ) | ||
|
|
||
| if 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, _ = _iterate_trans_views( | ||
| function=plot_alignment, | ||
| alpha=0.5, | ||
| max_width=self.img_max_width, | ||
| max_res=self.img_max_res, | ||
| **kwargs, | ||
| ) | ||
| self._add_image( | ||
| img=img, | ||
| title="Alignment", | ||
| section=section, | ||
| caption=None, | ||
| image_format="png", | ||
| tags=tags, | ||
| replace=replace, | ||
| ) | ||
| # Source space | ||
| kwargs = dict( | ||
| trans=trans, | ||
| subjects_dir=subjects_dir, | ||
| ) | ||
|
|
||
| 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, | ||
| ) | ||
|
Comment on lines
+3656
to
+3669
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Rather than make this depend on subject, too, I'm going to make it not depend on |
||
|
|
||
| if src.kind == "surface" or src.kind == "mixed": | ||
| surfaces = dict(head=0.1, white=0.5) | ||
| else: | ||
| surfaces = dict(head=0.1) | ||
|
|
||
| kwargs = dict( | ||
| trans=trans, | ||
| src=src, | ||
| subject=subject, | ||
| subjects_dir=subjects_dir, | ||
| show_axes=False, | ||
| coord_frame="mri", | ||
| surfaces=surfaces, | ||
| ) | ||
| img, _ = _iterate_alignment_views( | ||
| function=plot_alignment, | ||
| alpha=0.5, | ||
| max_width=self.img_max_width, | ||
| max_res=self.img_max_res, | ||
| **kwargs, | ||
| ) | ||
| self._add_image( | ||
| img=img, | ||
| title="Source space(s) (3D view)", | ||
| section=section, | ||
| caption=None, | ||
| image_format="png", | ||
| tags=tags, | ||
| replace=replace, | ||
| ) | ||
|
|
||
| def _add_inverse_operator( | ||
| self, | ||
| *, | ||
|
|
@@ -4440,13 +4565,15 @@ def _add_bem( | |
| *, | ||
| subject, | ||
| subjects_dir, | ||
| src, | ||
| trans, | ||
| decim, | ||
| n_jobs, | ||
| width=512, | ||
| image_format, | ||
| title, | ||
| tags, | ||
| section, | ||
| tags, | ||
| replace, | ||
| ): | ||
| """Render mri+bem (only PNG).""" | ||
|
|
@@ -4472,6 +4599,8 @@ def _add_bem( | |
| mri_fname=mri_fname, | ||
| surfaces=surfaces, | ||
| orientation=orientation, | ||
| src=src, | ||
| trans=trans, | ||
| decim=decim, | ||
| n_jobs=n_jobs, | ||
| width=width, | ||
|
|
||
There was a problem hiding this comment.
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_forwardbehavior dependent on whether or notsubjectis passed. Technically it could be pulled fromfwd["src"][0]["subject_his_id"]in most cases. I'll think on it a bit and maybe make this part opt-in withplot=False (default) | Trueforreport.add_forward, especially sincereport.add_bemalready exists which gives some overlapping behavior.