Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/mne-tools/mne-python into c…
Browse files Browse the repository at this point in the history
…oreg-ui-fiducial-io-widgets
  • Loading branch information
hoechenberger committed Jan 26, 2022
2 parents 3d39ae4 + 9396ca7 commit d36a609
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
2 changes: 2 additions & 0 deletions doc/changes/latest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ Enhancements

- All methods of :class:`mne.Report` with a ``tags`` parameter now also accept a single tag passed as a string (previously, you needed to pass a tuple of strings, even for a single tag) (:gh:`10183`, by `Richard Höchenberger`_)

- :meth:`mne.Report.add_trans` has gained a new parameter, ``alpha``, to control the level of opacity of the rendered head (:gh:`10247`, by `Richard Höchenberger`_)

- The new convenience function :func:`mne.event.match_event_names` allows for straightforward checking if a specific event name or a group of events is present in a collection of event names (:gh:`10233` by `Richard Höchenberger`_)

Bugs
Expand Down
2 changes: 1 addition & 1 deletion mne/html_templates/report/epochs.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
aria-labelledby="accordion-header-{{ id }}">
<div class="accordion-body">
{{ repr | safe }}
{{ drop_log | safe }}
{{ metadata | safe }}
{{ erp_imgs | safe }}
{{ drop_log | safe }}
{{ psd | safe }}
{{ ssp_projs | safe }}
</div>
Expand Down
21 changes: 14 additions & 7 deletions mne/report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def _get_bem_contour_figs_as_arrays(
return out


def _iterate_trans_views(function, **kwargs):
def _iterate_trans_views(function, alpha, **kwargs):
"""Auxiliary function to iterate over views in trans fig."""
from ..viz import create_3d_figure
from ..viz.backends.renderer import MNE_3D_BACKEND_TESTING
Expand All @@ -447,9 +447,11 @@ def _iterate_trans_views(function, **kwargs):
from ..viz.backends.renderer import backend
try:
try:
return _itv(function, fig, surfaces=['head-dense'], **kwargs)
return _itv(
function, fig, surfaces={'head-dense': alpha}, **kwargs
)
except IOError:
return _itv(function, fig, surfaces=['head'], **kwargs)
return _itv(function, fig, surfaces={'head': alpha}, **kwargs)
finally:
backend._close_3d_figure(fig)

Expand Down Expand Up @@ -1241,7 +1243,7 @@ def add_inverse_operator(self, inverse_operator, title, *, subject=None,

@fill_doc
def add_trans(self, trans, *, info, title, subject=None, subjects_dir=None,
tags=('coregistration',), replace=False):
alpha=None, tags=('coregistration',), replace=False):
"""Add a coregistration visualization to the report.
Parameters
Expand All @@ -1259,6 +1261,10 @@ def add_trans(self, trans, *, info, title, subject=None, subjects_dir=None,
report creation.
subjects_dir : path-like | None
The FreeSurfer ``SUBJECTS_DIR``.
alpha : float | None
The level of opacity to apply to the head surface. If a float, must
be between 0 and 1 (inclusive), where 1 means fully opaque. If
``None``, will use the MNE-Python default value.
%(report_tags)s
%(report_replace)s
Expand All @@ -1273,6 +1279,7 @@ def add_trans(self, trans, *, info, title, subject=None, subjects_dir=None,
info=info,
subject=subject,
subjects_dir=subjects_dir,
alpha=alpha,
title=title,
tags=tags
)
Expand Down Expand Up @@ -3484,8 +3491,8 @@ def _render_cov(self, cov, *, info, image_format, tags):

return htmls

def _render_trans(self, *, trans, info, subject, subjects_dir, title,
tags):
def _render_trans(self, *, trans, info, subject, subjects_dir, alpha,
title, tags):
"""Render trans (only PNG)."""
if not isinstance(trans, Transform):
trans = read_trans(trans)
Expand All @@ -3497,7 +3504,7 @@ def _render_trans(self, *, trans, info, subject, subjects_dir, title,
meg=['helmet', 'sensors'], show_axes=True,
coord_frame='mri')
img, caption = _iterate_trans_views(
function=plot_alignment, **kwargs)
function=plot_alignment, alpha=alpha, **kwargs)

dom_id = self._get_dom_id()
html = _html_image_element(
Expand Down
5 changes: 3 additions & 2 deletions tutorials/intro/70_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,15 @@
# "coregistration") can be visualized via :meth:`mne.Report.add_trans`. The
# method expects the transformation either as a `~mne.transforms.Transform`
# object or as a path to a ``trans.fif`` file, the FreeSurfer subject name and
# subjects directory, and a title.
# subjects directory, and a title. The ``alpha`` parameter can be used to
# control the transparency of the head, where a value of 1 means fully opaque.

trans_path = sample_dir / 'sample_audvis_raw-trans.fif'

report = mne.Report(title='Coregistration example')
report.add_trans(
trans=trans_path, info=raw_path, subject='sample',
subjects_dir=subjects_dir, title='Coregistration'
subjects_dir=subjects_dir, alpha=1.0, title='Coregistration'
)
report.save('report_coregistration.html', overwrite=True)

Expand Down

0 comments on commit d36a609

Please sign in to comment.