def get_BIDSLayout_with_conf(dir_, **kwargs): """Get BIDSLayout with bids, derivatives, and pndni_bids configuration files loaded""" if "pndni_bids" not in bids_config.get_option("config_paths"): layout.add_config_paths(pndni_bids=resource_filename( 'pndniworkflows', 'config/pndni_bids.json')) l = layout.BIDSLayout(dir_, config=['bids', 'derivatives', 'pndni_bids'], **kwargs) return l
def __init__(self, reportlets_dir, out_dir, run_uuid, config=None, subject_id=None, out_filename='report.html', packagename=None): self.root = reportlets_dir # Add a new figures spec try: add_config_paths( figures=pkgrf('niworkflows', 'reports/figures.json')) except ValueError as e: if "Configuration 'figures' already exists" != str(e): raise # Initialize structuring elements self.sections = [] self.errors = [] self.out_dir = Path(out_dir) self.out_filename = out_filename self.run_uuid = run_uuid self.template_path = None self.packagename = packagename self.subject_id = subject_id if subject_id is not None and subject_id.startswith('sub-'): self.subject_id = self.subject_id[4:] if self.subject_id is not None: self.out_filename = 'sub-{}.html'.format(self.subject_id) if config is None: config = pkgrf('niworkflows', 'reports/fmriprep.yml') self._load_config(Path(config))
def test_add_config_paths(): bids_dir = dirname(bids.__file__) bids_json = os.path.join(bids_dir, 'layout', 'config', 'bids.json') with pytest.raises(ValueError) as exc: add_config_paths(test_config1='nonexistentpath.json') assert str(exc.value).startswith('Configuration file') with pytest.raises(ValueError) as exc: add_config_paths(bids=bids_json) assert str(exc.value).startswith("Configuration 'bids' already") add_config_paths(dummy=bids_json) config = Config.load('dummy') assert 'subject' in config.entities
from os import path as op from pathlib import Path import jinja2 import pkg_resources as pkgr from bids.layout import add_config_paths, BIDSLayout from ..utils import snake_to_camel PATH_PATTERNS = [ '[sub-{subject}/][ses-{session}/][sub-{subject}_][ses-{session}_]' 'model-{model}[_run-{run}].html' ] add_config_paths(fitlins=pkgr.resource_filename('fitlins', 'data/fitlins.json')) def deroot(val, root): if isinstance(val, str): if val.startswith(root): idx = len(root) if val[idx] == '/': idx += 1 val = val[idx:] elif isinstance(val, list): val = [deroot(elem, root) for elem in val] elif isinstance(val, dict): val = {key: deroot(value, root) for key, value in val.items()} return val
Generalizes report generation across BIDS-Apps """ from pathlib import Path import re from itertools import compress from collections import defaultdict from pkg_resources import resource_filename as pkgrf from bids.layout import BIDSLayout, add_config_paths import jinja2 from nipype.utils.filemanip import copyfile # Add a new figures spec try: add_config_paths(figures=pkgrf("niworkflows", "data/nipreps.json")) except ValueError as e: if "Configuration 'figures' already exists" != str(e): raise PLURAL_SUFFIX = defaultdict(str("s").format, [("echo", "es")]) SVG_SNIPPET = [ """\ <object class="svg-reportlet" type="image/svg+xml" data="./{0}"> Problem loading figure {0}. If the link below works, please try \ reloading the report in your browser.</object> </div> <div class="elem-filename"> Get figure file: <a href="./{0}" target="_blank">{0}</a> </div> """,
Generalizes report generation across BIDS-Apps """ from pathlib import Path import re from itertools import product from collections import defaultdict from pkg_resources import resource_filename as pkgrf from bids.layout import BIDSLayout, add_config_paths import jinja2 from nipype.utils.filemanip import copyfile # Add a new figures spec try: add_config_paths(figures=pkgrf('niworkflows', 'reports/figures.json')) except ValueError as e: if "Configuration 'figures' already exists" != str(e): raise PLURAL_SUFFIX = defaultdict(str('s').format, [('echo', 'es')]) SVG_SNIPPET = ["""\ <object class="svg-reportlet" type="image/svg+xml" data="./{0}"> Problem loading figure {0}. If the link below works, please try \ reloading the report in your browser.</object> </div> <div class="elem-filename"> Get figure file: <a href="./{0}" target="_blank">{0}</a> </div> """, """\ <img class="svg-reportlet" src="./{0}" style="width: 100%" />
"""Extending pyBIDS for querying TemplateFlow.""" from pkg_resources import resource_filename from bids.layout import BIDSLayout, add_config_paths add_config_paths( templateflow=resource_filename("templateflow", "conf/config.json")) class Layout(BIDSLayout): def __repr__(self): # A tidy summary of key properties s = """\ TemplateFlow Layout - Home: {} - Templates: {}.""".format(self.root, ", ".join(sorted(self.get_templates()))) return s
""" Extending pyBIDS """ from pkg_resources import resource_filename from bids.layout import BIDSLayout, add_config_paths add_config_paths( templateflow=resource_filename('templateflow', 'conf/config.json')) class Layout(BIDSLayout): def __repr__(self): # A tidy summary of key properties s = """\ TemplateFlow Layout - Home: {} - Templates: {}.""".format(self.root, ', '.join(sorted(self.get_templates()))) return s