Skip to content

ENH: Add param to report.add_epochs to report reject/flat #12396 #13186

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
100 changes: 23 additions & 77 deletions mne/report/report.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Generate self-contained HTML reports from MNE objects."""
"Generate self-contained HTML reports from MNE objects."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do want the triple-quotes here

# Authors: The MNE-Python contributors.
# License: BSD-3-Clause
Expand Down Expand Up @@ -831,6 +831,7 @@ def __init__(
collapse=(),
verbose=None,
):
self.projs = projs # Initialize self.projs
self.info_fname = str(info_fname) if info_fname is not None else None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did this line need to move up? Please avoid purely cosmetic changes, it makes the important changes harder to focus on when viewing the diff.

self.cov_fname = str(cov_fname) if cov_fname is not None else None
self.baseline = baseline
Expand All @@ -842,7 +843,7 @@ def __init__(
self.subject = subject
self.title = title
self.image_format = _check_image_format(None, image_format)
self.projs = projs

# dom_id is mostly for backward compat and testing nowadays
self._dom_id = 0
self._dup_limit = 10000 # should be enough duplicates
Expand Down Expand Up @@ -1249,19 +1250,26 @@ def add_epochs(
.. versionadded:: 0.24
"""
tags = _check_tags(tags)
add_projs = self.projs if projs is None else projs
self._add_epochs(
epochs=epochs,
psd=psd,
add_projs=add_projs,
image_kwargs=image_kwargs,
topomap_kwargs=topomap_kwargs,
drop_log_ignore=drop_log_ignore,
section=title,
tags=tags,
image_format=self.image_format,
replace=replace,
)

add_projs = self.projs if projs is None else projs

if epochs._bad_dropped:
reject_info = f"<p><strong>Rejection Thresholds:</strong> {epochs.reject}</p>"
flat_info = f"<p><strong>Flat Thresholds:</strong> {epochs.flat}</p>"
self.add_html(reject_info + flat_info)

self._add_epochs(
epochs=epochs,
psd=psd,
add_projs=add_projs,
image_kwargs=image_kwargs,
topomap_kwargs=topomap_kwargs,
drop_log_ignore=drop_log_ignore,
section=title,
tags=tags,
image_format=self.image_format,
replace=replace,
)

Comment on lines +1253 to +1271
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks wrong, why is it unindented to be outside the method?

@fill_doc
def add_evokeds(
Expand Down Expand Up @@ -2212,68 +2220,6 @@ def remove(self, *, title=None, tags=None, remove_all=False):

return remove_idx

@fill_doc
def _add_or_replace(self, *, title, section, tags, html_partial, replace=False):
"""Append HTML content report, or replace it if it already exists.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this method being removed? it's used a bunch of times later in the file. Revert.

Parameters
----------
title : str
The title entry.
%(section_report)s
tags : tuple of str
The tags associated with the added element.
html_partial : callable
Callable that renders a HTML string, called as::

html_partial(id_=...)
replace : bool
Whether to replace existing content if the title and section match.
If an object is replaced, its dom_id is preserved.
"""
assert callable(html_partial), type(html_partial)

# Temporarily set HTML and dom_id to dummy values
new_content = _ContentElement(
name=title, section=section, dom_id="", tags=tags, html=""
)

append = True
if replace:
matches = [
ii
for ii, element in enumerate(self._content)
if (element.name, element.section) == (title, section)
]
if matches:
dom_id = self._content[matches[-1]].dom_id
self._content[matches[-1]] = new_content
append = False
if append:
dom_id = self._get_dom_id(section=section, title=title)
self._content.append(new_content)
new_content.dom_id = dom_id
new_content.html = html_partial(id_=dom_id)
assert isinstance(new_content.html, str), type(new_content.html)

def _add_code(self, *, code, title, language, section, tags, replace):
if isinstance(code, Path):
code = Path(code).read_text()
html_partial = partial(
_html_code_element,
tags=tags,
title=title,
code=code,
language=language,
)
self._add_or_replace(
title=title,
section=section,
tags=tags,
html_partial=html_partial,
replace=replace,
)

@fill_doc
def add_code(
self,
Expand Down
Loading
Loading