Warning: This document is for the development version of niworkflows. The main version is master.

niworkflows.reports.core module

Reports builder for BIDS-Apps.

Generalizes report generation across BIDS-Apps

class niworkflows.reports.core.Element(name, title=None)[source]

Bases: object

Just a basic component of a report

class niworkflows.reports.core.Report(out_dir, run_uuid, config=None, out_filename='report.html', packagename=None, reportlets_dir=None, subject_id=None)[source]

Bases: object

The full report object. This object maintains a BIDSLayout to index all reportlets.

>>> cwd = os.getcwd()
>>> os.chdir(tmpdir)
>>> from pkg_resources import resource_filename
>>> from shutil import copytree
>>> from bids.layout import BIDSLayout
>>> test_data_path = resource_filename('niworkflows', 'data/tests/work')
>>> testdir = Path(tmpdir)
>>> data_dir = copytree(test_data_path, str(testdir / 'work'))
>>> out_figs = testdir / 'out' / 'fmriprep'

>>> robj = Report(testdir / 'out', 'madeoutuuid', subject_id='01', packagename='fmriprep',
...               reportlets_dir=testdir / 'work' / 'reportlets')
>>> robj.layout.get(subject='01', desc='reconall')  
[<BIDSFile filename='.../figures/sub-01_desc-reconall_T1w.svg'>]
>>> robj.generate_report()
0
>>> len((testdir / 'out' / 'fmriprep' / 'sub-01.html').read_text())
36693
>>> os.chdir(cwd)
generate_report()[source]

Once the Report has been indexed, the final HTML can be generated

index(config)[source]

Traverse the reports config definition and instantiate reportlets.

This method also places figures in their final location.

init_layout()[source]
class niworkflows.reports.core.Reportlet(layout, out_dir, config=None)[source]

Bases: niworkflows.reports.core.Element

A reportlet has title, description and a list of components with either an HTML fragment or a path to an SVG file, and possibly a caption. This is a factory class to generate Reportlets reusing the layout from a Report object.

>>> cwd = os.getcwd()
>>> os.chdir(tmpdir)
>>> from pkg_resources import resource_filename
>>> from shutil import copytree
>>> from bids.layout import BIDSLayout
>>> test_data_path = resource_filename('niworkflows', 'data/tests/work')
>>> testdir = Path(tmpdir)
>>> data_dir = copytree(test_data_path, str(testdir / 'work'))
>>> out_figs = testdir / 'out' / 'fmriprep'
>>> bl = BIDSLayout(str(testdir / 'work' / 'reportlets'),
...                 config='figures', validate=False)

>>> bl.get(subject='01', desc='reconall') 
[<BIDSFile filename='.../fmriprep/sub-01/figures/sub-01_desc-reconall_T1w.svg'>]
>>> len(bl.get(subject='01', space='.*', regex_search=True))
2
>>> r = Reportlet(bl, out_figs, config={
...     'title': 'Some Title', 'bids': {'datatype': 'figures', 'desc': 'reconall'},
...     'description': 'Some description'})
>>> r.name
'datatype-figures_desc-reconall'
>>> r.components[0][0].startswith('<img')
True
>>> r = Reportlet(bl, out_figs, config={
...     'title': 'Some Title', 'bids': {'datatype': 'figures', 'desc': 'reconall'},
...     'description': 'Some description', 'static': False})
>>> r.name
'datatype-figures_desc-reconall'
>>> r.components[0][0].startswith('<object')
True
>>> r = Reportlet(bl, out_figs, config={
...     'title': 'Some Title', 'bids': {'datatype': 'figures', 'desc': 'summary'},
...     'description': 'Some description'})
>>> r.components[0][0].startswith('<h3')
True
>>> r.components[0][1] is None
True
>>> r = Reportlet(bl, out_figs, config={
...     'title': 'Some Title',
...     'bids': {'datatype': 'figures', 'space': '.*', 'regex_search': True},
...     'caption': 'Some description {space}'})
>>> sorted(r.components)[0][1]
'Some description MNI152NLin2009cAsym'
>>> sorted(r.components)[1][1]
'Some description MNI152NLin6Asym'
>>> r = Reportlet(bl, out_figs, config={
...     'title': 'Some Title',
...     'bids': {'datatype': 'fmap', 'space': '.*', 'regex_search': True},
...     'caption': 'Some description {space}'})
>>> r.is_empty()
True
>>> os.chdir(cwd)
is_empty()[source]
class niworkflows.reports.core.SubReport(name, isnested=False, reportlets=None, title='')[source]

Bases: niworkflows.reports.core.Element

SubReports are sections within a Report.

niworkflows.reports.core.generate_reports(subject_list, output_dir, run_uuid, config=None, work_dir=None, packagename=None)[source]

Execute run_reports on a list of subjects.

niworkflows.reports.core.run_reports(out_dir, subject_label, run_uuid, config=None, reportlets_dir=None, packagename=None)[source]

Run the reports.

>>> cwd = os.getcwd()
>>> os.chdir(tmpdir)
>>> from pkg_resources import resource_filename
>>> from shutil import copytree
>>> test_data_path = resource_filename('niworkflows', 'data/tests/work')
>>> testdir = Path(tmpdir)
>>> data_dir = copytree(test_data_path, str(testdir / 'work'))
>>> (testdir / 'fmriprep').mkdir(parents=True, exist_ok=True)

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