Inheritance diagram for nipy.io.imageformats.filename_parser:
Create filename pairs, triplets etc, with expected extensions
Split /pth/fname.ext.gz into /pth/fname, .ext, .gz
where .gz may be any of passed addext trailing suffixes.
Parameters : | filename : str
|
---|---|
Returns : | froot : str
ext : str
addext : str
|
Examples
>>> splitext_addext('fname.ext.gz')
('fname', '.ext', '.gz')
>>> splitext_addext('fname.ext')
('fname', '.ext', '')
>>> splitext_addext('fname.ext.foo', ('.foo', '.bar'))
('fname', '.ext', '.foo')
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
types_exts : sequence of sequences
trailing_suffixes : sequence of strings, optional
enforce_extensions : {True, False}, optional
|
---|---|
Returns : | types_fnames : dict
|
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