本文整理汇总了Python中bids.layout.BIDSLayout方法的典型用法代码示例。如果您正苦于以下问题:Python layout.BIDSLayout方法的具体用法?Python layout.BIDSLayout怎么用?Python layout.BIDSLayout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bids.layout
的用法示例。
在下文中一共展示了layout.BIDSLayout方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
# 需要导入模块: from bids import layout [as 别名]
# 或者: from bids.layout import BIDSLayout [as 别名]
def init(cls):
"""Create a new BIDS Layout accessible with :attr:`~execution.layout`."""
if cls._layout is None:
import re
from bids.layout import BIDSLayout
work_dir = cls.work_dir / "bids.db"
work_dir.mkdir(exist_ok=True, parents=True)
cls._layout = BIDSLayout(
str(cls.bids_dir),
validate=False,
# database_path=str(work_dir),
ignore=(
"code",
"stimuli",
"sourcedata",
"models",
"derivatives",
re.compile(r"^\."),
),
)
cls.layout = cls._layout
# These variables are not necessary anymore
示例2: write_full_report
# 需要导入模块: from bids import layout [as 别名]
# 或者: from bids.layout import BIDSLayout [as 别名]
def write_full_report(report_dict, run_context, deriv_dir):
fl_layout = BIDSLayout(
deriv_dir, config=['bids', 'derivatives', 'fitlins'])
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(
searchpath=pkgr.resource_filename('fitlins', '/')))
tpl = env.get_template('data/full_report.tpl')
model = snake_to_camel(report_dict['model']['name'])
target_file = op.join(
deriv_dir, fl_layout.build_path(
{'model': model}, PATH_PATTERNS, validate=False))
html = tpl.render(deroot({**report_dict, **run_context}, op.dirname(target_file)))
Path(target_file).write_text(html)
示例3: __get_bids_layout
# 需要导入模块: from bids import layout [as 别名]
# 或者: from bids.layout import BIDSLayout [as 别名]
def __get_bids_layout(self):
'''run the BIDS validator and produce the bids_layout'''
run("bids-validator {}".format(self.bids_dir), dryrun = DRYRUN)
try:
layout = BIDSLayout(self.bids_dir, exclude=['derivatives'])
except:
logger.critical('Could not parse <bids_dir> {}'.format(self.bids_dir))
sys.exit(1)
return layout
示例4: __get_from_bids_layout
# 需要导入模块: from bids import layout [as 别名]
# 或者: from bids.layout import BIDSLayout [as 别名]
def __get_from_bids_layout(self, user_arg, entity):
'''for a given BIDSLayout entity, check the layout against the user arguments'''
all_ids = self.bids_layout.get(return_type = "id", target = entity)
if user_arg:
ids_to_analyze = user_arg.split(",")
for label in ids_to_analyze:
if label not in all_ids:
logger.critical("{} {} not in bids_dir".format(entity, label))
sys.exit(1)
# for all subjects
else:
ids_to_analyze = all_ids
return ids_to_analyze
示例5: get_derivatives_layout
# 需要导入模块: from bids import layout [as 别名]
# 或者: from bids.layout import BIDSLayout [as 别名]
def get_derivatives_layout(derivs_dir):
'''run pybids and produce the derivs_layout'''
try:
derivs_layout = BIDSLayout(derivs_dir,
validate = False, config = ['bids', 'derivatives'])
except:
logger.warning('Could not parse BIDS derivatives from {}'.format(derivs_dir))
return derivs_layout
示例6: testlayout
# 需要导入模块: from bids import layout [as 别名]
# 或者: from bids.layout import BIDSLayout [as 别名]
def testlayout():
data_dir = join(get_test_data_path(), 'synthetic')
return BIDSLayout(data_dir)
示例7: model
# 需要导入模块: from bids import layout [as 别名]
# 或者: from bids.layout import BIDSLayout [as 别名]
def model():
layout_path = join(get_test_data_path(), 'ds005')
layout = BIDSLayout(layout_path)
models = auto_model(layout, scan_length=480, one_vs_rest=True)
return models[0]
示例8: test_auto_model_analysis
# 需要导入模块: from bids import layout [as 别名]
# 或者: from bids.layout import BIDSLayout [as 别名]
def test_auto_model_analysis(model):
layout_path = join(get_test_data_path(), 'ds005')
layout = BIDSLayout(layout_path)
# Test to make sure an analaysis can be setup from the generated model
analysis = Analysis(layout, model)
analysis.setup(scan_length=480)
assert model['Name'] == 'ds005_mixedgamblestask'
# run level
block = model['Steps'][0]
assert block['Name'] == 'Run'
assert block['Level'] == 'Run'
assert block['Transformations'][0]['Name'] == 'Factor'
assert block['Contrasts'][0]['Name'] == 'run_parametric gain'
assert block['Contrasts'][0]['Weights'] == [1]
assert block['Contrasts'][0]['Type'] == 't'
# subject level
block = model['Steps'][1]
assert block['Name'] == 'Subject'
assert block['Level'] == 'Subject'
assert block['Model']['X'][0] == 'run_parametric gain'
assert block['Contrasts'][0]['Name'] == 'subject_run_parametric gain'
assert block['Contrasts'][0]['Type'] == 'FEMA'
# dataset level
block = model['Steps'][2]
assert block['Name'] == 'Dataset'
assert block['Level'] == 'Dataset'
assert block['Model']['X'][0] == 'subject_run_parametric gain'
assert block['Contrasts'][0]['Name'] == 'dataset_subject_run_parametric gain'
assert block['Contrasts'][0]['Type'] == 't'
示例9: collection
# 需要导入模块: from bids import layout [as 别名]
# 或者: from bids.layout import BIDSLayout [as 别名]
def collection():
if 'ds005' not in cached_collections:
layout_path = join(get_test_data_path(), 'ds005')
layout = BIDSLayout(layout_path)
cached_collections['ds005'] = layout.get_collections(
'run',
types=['events'],
scan_length=SCAN_LENGTH,
merge=True,
sampling_rate=10,
subject=SUBJECTS
)
# Always return a clone!
return cached_collections['ds005'].clone()
示例10: __init__
# 需要导入模块: from bids import layout [as 别名]
# 或者: from bids.layout import BIDSLayout [as 别名]
def __init__(self, layout, model):
if not isinstance(layout, BIDSLayout):
layout = BIDSLayout(layout)
self.layout = layout
self._load_model(model)
示例11: init_layout
# 需要导入模块: from bids import layout [as 别名]
# 或者: from bids.layout import BIDSLayout [as 别名]
def init_layout(self):
self.layout = BIDSLayout(self.root, config="figures", validate=False)
示例12: test_generated_reportlets
# 需要导入模块: from bids import layout [as 别名]
# 或者: from bids.layout import BIDSLayout [as 别名]
def test_generated_reportlets(bids_sessions, ordering):
# make independent report
out_dir = tempfile.mkdtemp()
report = Report(
Path(out_dir),
"fakeuuid",
reportlets_dir=Path(bids_sessions),
subject_id="01",
packagename="fmriprep",
)
config = Path(pkgrf("niworkflows", "reports/default.yml"))
settings = load(config.read_text())
# change settings to only include some missing ordering
settings["sections"][3]["ordering"] = ordering
report.index(settings["sections"])
# expected number of reportlets
expected_reportlets_num = len(report.layout.get(extension="svg"))
# bids_session uses these entities
needed_entities = ["session", "task", "ceagent", "run"]
# the last section is the most recently run
reportlets_num = len(report.sections[-1].reportlets)
# get the number of figures in the output directory
out_layout = BIDSLayout(out_dir, config="figures", validate=False)
out_figs = len(out_layout.get())
# if ordering does not contain all the relevent entities
# then there should be fewer reportlets than expected
if all(ent in ordering for ent in needed_entities):
assert reportlets_num == expected_reportlets_num == out_figs
else:
assert reportlets_num < expected_reportlets_num == out_figs
示例13: _process_orderings
# 需要导入模块: from bids import layout [as 别名]
# 或者: from bids.layout import BIDSLayout [as 别名]
def _process_orderings(orderings, layout):
"""
Generate relevant combinations of orderings with observed values.
Arguments
---------
orderings : :obj:`list` of :obj:`list` of :obj:`str`
Sections prescribing an ordering to select across sessions, acquisitions, runs, etc.
layout : :obj:`bids.layout.BIDSLayout`
The BIDS layout
Returns
-------
entities: :obj:`list` of :obj:`str`
The relevant orderings that had unique values
value_combos: :obj:`list` of :obj:`tuple`
Unique value combinations for the entities
"""
# get a set of all unique entity combinations
all_value_combos = {
tuple(bids_file.get_entities().get(k, None) for k in orderings)
for bids_file in layout.get()
}
# remove the all None member if it exists
none_member = tuple([None for k in orderings])
if none_member in all_value_combos:
all_value_combos.remove(tuple([None for k in orderings]))
# see what values exist for each entity
unique_values = [
{value[idx] for value in all_value_combos} for idx in range(len(orderings))
]
# if all values are None for an entity, we do not want to keep that entity
keep_idx = [
False if (len(val_set) == 1 and None in val_set) or not val_set else True
for val_set in unique_values
]
# the "kept" entities
entities = list(compress(orderings, keep_idx))
# the "kept" value combinations
value_combos = [
tuple(compress(value_combo, keep_idx)) for value_combo in all_value_combos
]
# sort the value combinations alphabetically from the first entity to the last entity
value_combos.sort(
key=lambda entry: tuple(
str(value) if value is not None else "0" for value in entry
)
)
return entities, value_combos