NiBabel

Access a cacophony of neuro-imaging file formats

Previous topic

nibabel.filename_parser.splitext_addext

Next topic

nibabel.onetime

This Page

Reggie -- the one

nibabel.filename_parser.types_filenames

nibabel.filename_parser.types_filenames(template_fname, types_exts, trailing_suffixes=('.gz', '.bz2'), enforce_extensions=True, match_case=False)

Return filenames with standard extensions from template name

The typical case is returning image and header filenames for an Analyze image, that expects and ‘image’ file type, with, extension .img, and a ‘header’ file type, with extension .hdr.

Parameters :

template_fname : str

template filename from which to construct output dict of filenames, with given types_exts type to extension mapping. If self.enforce_extensions is True, then filename must have one of the defined extensions from the types list. If self.enforce_extensions is False, then the other filenames are guessed at by adding extensions to the base filename. Ignored suffixes (from trailing_suffixes) append themselves to the end of all the filenames.

types_exts : sequence of sequences

sequence of (name, extension) str sequences defining type to extension mapping.

trailing_suffixes : sequence of strings, optional

suffixes that should be ignored when looking for extensions - default is ('.gz', '.bz2')

enforce_extensions : {True, False}, optional

If True, raise an error when attempting to set value to type which has the wrong extension

match_case : bool, optional

If True, match case of extensions and trailing suffixes when searching in template_fname, otherwise do case-insensitive match.

Returns :

types_fnames : dict

dict with types as keys, and generated filenames as values. The types are given by the first elements of the tuples in types_exts.

Examples

>>> types_exts = (('t1','.ext1'),('t2', '.ext2'))
>>> tfns = types_filenames('/path/test.ext1', types_exts)
>>> tfns == {'t1': '/path/test.ext1', 't2': '/path/test.ext2'}
True

Bare file roots without extensions get them added

>>> tfns = types_filenames('/path/test', types_exts)
>>> tfns == {'t1': '/path/test.ext1', 't2': '/path/test.ext2'}
True

With enforce_extensions == False, allow first type to have any extension.

>>> tfns = types_filenames('/path/test.funny', types_exts,
...                        enforce_extensions=False)
>>> tfns == {'t1': '/path/test.funny', 't2': '/path/test.ext2'}
True