fsl.utils.bids

This module provides a few functions for working with BIDS data sets.

isBIDSDir

Returns True if dirname is the root directory of a BIDS dataset.

inBIDSDir

Returns True if filename looks like it is within a BIDS dataset directory, False otherwise.

isBIDSFile

Returns True if filename looks like a BIDS image or JSON file.

loadMetadata

Load all of the metadata associated with filename.

All of the other functions in this module should not be considered part of the public API.

Note

The pybids library is a more suitable choice if you are after a more robust and featured interface for working with BIDS datasets.

class fsl.utils.bids.BIDSFile(filename)[source]

Bases: object

The BIDSFile class parses and stores the entities and suffix contained in a BIDS file. See the parseFilename() function.

The match() method can be used to compare two BIDSFile instances.

The following attributes are available on a BIDSFile instance:

  • filename: Absolute path to the file

  • entities: Dict of key : value pairs, the entities that are present in the file name (e.g. {'sub' : '01})

  • suffix: File suffix (e.g. T1w, bold, etc.)

__init__(filename)[source]

Create a BIDSFile.

match(other)[source]

Compare this BIDSFile to other.

Parameters

otherBIDSFile to compare

Returns

True if self.suffix == other.suffix and if all of the entities in other are present in self, False otherwise.

__dict__ = mappingproxy({'__module__': 'fsl.utils.bids', '__doc__': "The ``BIDSFile`` class parses and stores the entities and suffix contained\n in a BIDS file. See the :func:`parseFilename` function.\n\n The :meth:`match` method can be used to compare two ``BIDSFile`` instances.\n\n The following attributes are available on a ``BIDSFile`` instance:\n\n - ``filename``: Absolute path to the file\n - ``entities``: Dict of ``key : value`` pairs, the entities that are\n present in the file name (e.g. ``{'sub' : '01}``)\n - ``suffix``: File suffix (e.g. ``T1w``, ``bold``, etc.)\n ", '__init__': <function BIDSFile.__init__>, 'match': <function BIDSFile.match>, '__dict__': <attribute '__dict__' of 'BIDSFile' objects>, '__weakref__': <attribute '__weakref__' of 'BIDSFile' objects>})
__module__ = 'fsl.utils.bids'
__weakref__

list of weak references to the object (if defined)

fsl.utils.bids.parseFilename(filename)[source]

Parses a BIDS-like file name. The file name must consist of zero or more “entities” (alpha-numeric name-value pairs), a “suffix”, all separated by underscores, and a regular file extension. For example, the following file:

sub-01_ses-01_task-stim_bold.nii.gz

has suffix bold, and entities sub=01, ses=01 and task=stim.

Returns

A tuple containing: - A dict containing the entities - The suffix

fsl.utils.bids.isBIDSDir(dirname)[source]

Returns True if dirname is the root directory of a BIDS dataset.

fsl.utils.bids.inBIDSDir(filename)[source]

Returns True if filename looks like it is within a BIDS dataset directory, False otherwise.

fsl.utils.bids.isBIDSFile(filename, strict=True)[source]

Returns True if filename looks like a BIDS image or JSON file.

Parameters
  • filename – Name of file to check

  • strict – If True (the default), the file must be within a BIDS dataset directory, as defined by inBIDSDir().

fsl.utils.bids.loadMetadata(filename)[source]

Load all of the metadata associated with filename.

Parameters

filename – Path to a data file in a BIDS dataset.

Returns

A dict containing all of the metadata associated with filename