Note

This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the user guide for the big picture.

nilearn.interfaces.bids.parse_bids_filename

nilearn.interfaces.bids.parse_bids_filename(img_path)[source]

Return dictionary with parsed information from file path.

Parameters:
img_pathstr

Path to file from which to parse information.

Returns:
referencedict

Returns a dictionary with all key-value pairs in the file name parsed and other useful fields.

Added in Nilearn 0.13.0.

The dictionary will contain:

  • 'file_path',

  • 'file_basename',

  • 'extension',

  • 'suffix'

  • and 'entities'.

See the documentation on typical bids filename for more information.

Examples

>>> from nilearn.interfaces.bids import parse_bids_filename
>>> ref = parse_bids_filename("sub-01_task-rest_bold.nii.gz")
>>> ref["suffix"]
'bold'
>>> ref["extension"]
'nii.gz'
>>> ref["entities"] == {"sub": "01", "task": "rest"}
True