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

RF: Load report assembler from nireports #3177

Merged
Merged
Show file tree
Hide file tree
Changes from 12 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
1 change: 0 additions & 1 deletion fmriprep/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ def main():
config.execution.fmriprep_dir,
config.execution.run_uuid,
config=data.load("reports-spec.yml"),
packagename="fmriprep",
)
celprov marked this conversation as resolved.
Show resolved Hide resolved
write_derivative_description(config.execution.bids_dir, config.execution.fmriprep_dir)
write_bidsignore(config.execution.fmriprep_dir)
Expand Down
1 change: 0 additions & 1 deletion fmriprep/cli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def build_workflow(config_file, retval):
config.execution.fmriprep_dir,
config.execution.run_uuid,
config=data.load("reports-spec.yml"),
packagename="fmriprep",
)
return retval

Expand Down
119 changes: 34 additions & 85 deletions fmriprep/reports/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,100 +22,49 @@
#
from pathlib import Path

from niworkflows.reports.core import Report as _Report
from nireports.assembler.report import Report
celprov marked this conversation as resolved.
Show resolved Hide resolved

# This patch is intended to permit fMRIPrep 20.2.0 LTS to use the YODA-style
# derivatives directory. Ideally, we will remove this in 20.3.x and use an
# updated niworkflows.
from .. import config


class Report(_Report):
def _load_config(self, config):
from yaml import safe_load as load

settings = load(config.read_text())
self.packagename = self.packagename or settings.get("package", None)

# Removed from here: Appending self.packagename to self.root and self.out_dir
# In this version, pass reportlets_dir and out_dir with fmriprep in the path.

if self.subject_id is not None:
self.root = self.root / f"sub-{self.subject_id}"

if "template_path" in settings:
self.template_path = config.parent / settings["template_path"]

self.index(settings["sections"])


#
# The following are the interface used directly by fMRIPrep
#


def run_reports(
out_dir,
subject_label,
run_uuid,
config=None,
reportlets_dir=None,
packagename=None,
):
"""
Run the reports.

.. testsetup::

>>> copytree_or_skip("data/tests/work", testdir)
>>> (testdir / 'fmriprep').mkdir(parents=True, exist_ok=True)

.. doctest::

>>> run_reports(testdir / 'out', '01', 'madeoutuuid', packagename='fmriprep',
... reportlets_dir=testdir / 'work' / 'reportlets' / 'fmriprep')
0

"""
return Report(
out_dir,
run_uuid,
config=config,
subject_id=subject_label,
packagename=packagename,
reportlets_dir=reportlets_dir,
).generate_report()


def generate_reports(
subject_list, output_dir, run_uuid, config=None, work_dir=None, packagename=None
):
"""Execute run_reports on a list of subjects."""
def generate_reports(subject_list, output_dir, run_uuid, config=None, work_dir=None):
"""Generate reports for a list of subjects."""
reportlets_dir = None
if work_dir is not None:
reportlets_dir = Path(work_dir) / "reportlets"
report_errors = [
run_reports(

errors = []
for subject_label in subject_list:
entities = {}
entities["subject"] = subject_label

Check warning on line 39 in fmriprep/reports/core.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/reports/core.py#L36-L39

Added lines #L36 - L39 were not covered by tests

robj = Report(

Check warning on line 41 in fmriprep/reports/core.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/reports/core.py#L41

Added line #L41 was not covered by tests
output_dir,
subject_label,
run_uuid,
config=config,
packagename=packagename,
bootstrap_file=config,
reportlets_dir=reportlets_dir,
plugins=None,
plugin_meta=None,
metadata=None,
**entities,
)
for subject_label in subject_list
]

errno = sum(report_errors)
if errno:
import logging

logger = logging.getLogger("cli")
error_list = ", ".join(
f"{subid} ({err})" for subid, err in zip(subject_list, report_errors) if err
)
logger.error(
"Preprocessing did not finish successfully. Errors occurred while processing "
"data from participants: %s. Check the HTML reports for details.",
error_list,
# Count nbr of subject for which report generation failed
try:
robj.generate_report()
except:
import sys
import traceback

Check warning on line 57 in fmriprep/reports/core.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/reports/core.py#L53-L57

Added lines #L53 - L57 were not covered by tests

celprov marked this conversation as resolved.
Show resolved Hide resolved
errors.append(subject_label)
traceback.print_exception(

Check warning on line 60 in fmriprep/reports/core.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/reports/core.py#L59-L60

Added lines #L59 - L60 were not covered by tests
*sys.exc_info(),
file=str(Path(output_dir) / "logs" / f"report-{run_uuid}-{subject_label}.err"),
)

oesteban marked this conversation as resolved.
Show resolved Hide resolved
if errors:
logger.debug(

Check warning on line 66 in fmriprep/reports/core.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/reports/core.py#L65-L66

Added lines #L65 - L66 were not covered by tests
celprov marked this conversation as resolved.
Show resolved Hide resolved
"Report generation was not successful for the following participants : %s.",
", ".join(errors),
)
return errno
return len(errors)

Check warning on line 70 in fmriprep/reports/core.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/reports/core.py#L70

Added line #L70 was not covered by tests