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

smriprep.utils.bids module

Utilities to handle BIDS inputs.

smriprep.utils.bids.collect_anat_derivatives(derivatives, subject_id, std_spaces, session_id=None)[source]

Gather precomputed anatomical derivatives from one or more datasets.

Parameters:
  • derivatives (list of os.PathLike) – Derivatives datasets to search. Later datasets take precedence for each image and surface they provide, and for each space they have transforms for. Forward and reverse transforms for a space are never combined across datasets. Each derivative a later dataset replaces is logged at DEBUG level.

  • subject_id (str) – Subject label, without sub-.

  • std_spaces (list of str) – Standard spaces to look for transforms to and from. Transforms to fsnative are always searched for.

  • session_id (str or None) – Session label, without ses-.

Returns:

images and surfaces map query names in anat_spec.yml to paths. transforms maps each space with precomputed transforms to its forward and/or reverse transform.

Return type:

dict

Raises:

ValueError – If a query matches more than one file in a dataset, for example derivatives from several sessions when session_id is not given.

smriprep.utils.bids.write_bidsignore(deriv_dir)[source]
smriprep.utils.bids.write_derivative_description(bids_dir, deriv_dir)[source]

Write a dataset_description.json for the derivatives folder.

>>> from smriprep.data import load
>>> from pathlib import Path
>>> from tempfile import TemporaryDirectory
>>> tmpdir = TemporaryDirectory()
>>> bids_dir = load('tests')
>>> deriv_desc = Path(tmpdir.name) / 'dataset_description.json'

>>> write_derivative_description(bids_dir, deriv_desc.parent)
>>> deriv_desc.is_file()
True
>>> tmpdir.cleanup()