Skip to content

Commit c769ec5

Browse files
committed
fix(reports): improve generalization across software packages
- release a ``defaultconfig.json`` to initiate ``Report``s - release a default report template (``report.tpl``) - make config and packagename optional
1 parent 39928d7 commit c769ec5

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

niworkflows/data/tests/work/config.json renamed to niworkflows/viz/defaultconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"space": ".*",
3131
"suffix": "T1w"
3232
},
33-
"caption": "Nonlinear mapping of the T1w image into {space} space. Hover on the panel with the mouse to transition between both spaces.",
33+
"description": "Results of nonlinear alignment of the T1w image to template space. Hover on the panel with the mouse to transition between both spaces.",
34+
"caption": "Spatial normalization of the T1w image to the <code>{space}</code> template.",
3435
"title": "Spatial normalization"
3536
},
3637
{

niworkflows/data/tests/work/report.tpl renamed to niworkflows/viz/report.tpl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ h2 { padding-top: 20px; }
1717
h3 { padding-top: 15px; }
1818
1919
.elem-desc {}
20+
.elem-caption {
21+
margin-top: 15px
22+
margin-bottom: 0;
23+
}
2024
.elem-filename {}
2125
2226
div.elem-image {
@@ -82,11 +86,11 @@ div#boilerplate pre {
8286
<h1 class="sub-report-title">{{ sub_report.name }}</h1>
8387
{% for run_report in sub_report.reportlets %}
8488
<div id="{{run_report.name}}">
85-
{% if run_report.title %}<h2 class="run-title">Reports for {{ run_report.title }}</h2>{% endif %}
89+
{% if run_report.title %}<h2 class="run-title">{{ run_report.title }}</h2>{% endif %}
8690
{% if run_report.description %}<p class="elem-desc">{{ run_report.description }}</p>{% endif %}
8791
{% for elem in run_report.components %}
8892
{% if elem[0] %}
89-
{% if elem[1] %}<p class="elem-desc">{{ elem[1] }}</p>{% endif %}
93+
{% if elem[1] %}<p class="elem-caption">{{ elem[1] }}</p>{% endif %}
9094
{{ elem[0] }}
9195
{% endif %}
9296
{% endfor %}
@@ -99,8 +103,8 @@ div#boilerplate pre {
99103
<div id="boilerplate">
100104
<h1 class="sub-report-title">Methods</h1>
101105
{% if boilerplate %}
102-
<p>We kindly ask to report results preprocessed with fMRIPrep using the following
103-
boilerplate</p>
106+
<p>We kindly ask to report results preprocessed with this tool using the following
107+
boilerplate.</p>
104108
<ul class="nav nav-tabs" id="myTab" role="tablist">
105109
{% for b in boilerplate %}
106110
<li class="nav-item">
@@ -116,7 +120,6 @@ div#boilerplate pre {
116120
{% else %}
117121
<p class="text-danger">Failed to generate the boilerplate</p>
118122
{% endif %}
119-
<p>Alternatively, an interactive <a href="http://fmriprep.readthedocs.io/en/latest/citing.html">boilerplate generator</a> is available in the <a href="https://fmriprep.org">documentation website</a>.</p>
120123
</div>
121124

122125
<div id="errors">

niworkflows/viz/reports.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import jinja2
2020
from nipype.utils.filemanip import copyfile
2121

22+
2223
add_config_paths(figures=pkgrf('niworkflows', 'viz/figures.json'))
2324
LAYOUT_GET = defaultdict(str('s').format, [('echo', 'es')])
2425
SVG_SNIPPET = """\
@@ -190,8 +191,7 @@ class Report(object):
190191
191192
.. doctest::
192193
193-
>>> robj = Report(testdir / 'work' / 'reportlets',
194-
... 'work/config.json', testdir / 'out',
194+
>>> robj = Report(testdir / 'work' / 'reportlets', testdir / 'out',
195195
... 'madeoutuuid', subject_id='01')
196196
>>> robj.layout.get(subject='01', desc='reconall')
197197
[<BIDSFile filename='fmriprep/sub-01/anat/sub-01_desc-reconall_T1w.svg'>]
@@ -203,7 +203,7 @@ class Report(object):
203203
204204
"""
205205

206-
def __init__(self, reportlets_dir, config, out_dir, run_uuid,
206+
def __init__(self, reportlets_dir, out_dir, run_uuid, config=None,
207207
subject_id=None, out_filename='report.html',
208208
packagename=None):
209209
self.root = reportlets_dir
@@ -226,6 +226,8 @@ def __init__(self, reportlets_dir, config, out_dir, run_uuid,
226226
if self.subject_id is not None:
227227
self.out_filename = 'sub-{}.html'.format(self.subject_id)
228228

229+
if config is None:
230+
config = pkgrf('niworkflows', 'viz/defaultconfig.json')
229231
self._load_config(Path(config))
230232

231233
def _load_config(self, config):
@@ -328,7 +330,8 @@ def generate_report(self):
328330
return len(self.errors)
329331

330332

331-
def run_reports(reportlets_dir, out_dir, subject_label, run_uuid, config):
333+
def run_reports(reportlets_dir, out_dir, subject_label, run_uuid, config=None,
334+
packagename=None):
332335
"""
333336
Runs the reports
334337
@@ -347,27 +350,28 @@ def run_reports(reportlets_dir, out_dir, subject_label, run_uuid, config):
347350
.. doctest::
348351
349352
>>> run_reports(str(testdir / 'work' / 'reportlets'),
350-
... str(testdir / 'out'), '01', 'madeoutuuid',
351-
... 'work/config.json')
353+
... str(testdir / 'out'), '01', 'madeoutuuid')
352354
0
353355
354356
.. testcleanup::
355357
356358
>>> tmpdir.cleanup()
357359
358360
"""
359-
report = Report(Path(reportlets_dir), config, out_dir, run_uuid,
360-
subject_id=subject_label)
361+
report = Report(Path(reportlets_dir), out_dir, run_uuid, config=config,
362+
subject_id=subject_label, packagename=packagename)
361363
return report.generate_report()
362364

363365

364-
def generate_reports(subject_list, output_dir, work_dir, run_uuid, config):
366+
def generate_reports(subject_list, output_dir, work_dir, run_uuid, config=None,
367+
packagename=None):
365368
"""
366369
A wrapper to run_reports on a given ``subject_list``
367370
"""
368371
reports_dir = str(Path(work_dir) / 'reportlets')
369372
report_errors = [
370-
run_reports(reports_dir, output_dir, subject_label, run_uuid, config)
373+
run_reports(reports_dir, output_dir, subject_label, run_uuid,
374+
config, packagename=packagename)
371375
for subject_label in subject_list
372376
]
373377

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def main():
3333
'niworkflows': [
3434
'data/t1-mni_registration*.json',
3535
'data/bold-mni_registration*.json',
36+
'viz/*.json',
37+
'viz/report.tpl',
3638
]}
3739

3840
root_dir = op.dirname(op.abspath(getfile(currentframe())))

0 commit comments

Comments
 (0)