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.

>>> 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())
36713
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: 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.

>>> 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
is_empty()[source]
class niworkflows.reports.core.Smallest[source]

Bases: object

An object that always evaluates smaller than anything else, for sorting

>>> Smallest() < 1
True
>>> Smallest() < "epsilon"
True
>>> sorted([1, None, 2], key=lambda x: x if x is not None else Smallest())
[None, 1, 2]
class niworkflows.reports.core.SubReport(name, isnested=False, reportlets=None, title='')[source]

Bases: 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.

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