openers¶
Context manager openers for various fileobject types
|
Opener-type class to collect extra compressed extensions |
|
Class to accept, maybe open, and context-manage file-likes / filenames |
ImageOpener¶
-
class
nibabel.openers.ImageOpener(fileish, *args, **kwargs)¶ Bases:
nibabel.openers.OpenerOpener-type class to collect extra compressed extensions
A trivial sub-class of opener to which image classes can add extra extensions with custom openers, such as compressed openers.
To add an extension, add a line to the class definition (not __init__):
ImageOpener.compress_ext_map[ext] = func_def
extis a file extension beginning with ‘.’ and should be included in the image class’svalid_extstuple.func_defis a (function, (args,)) tuple, where function accepts a filename as the first parameter, and `args defines the other arguments that function accepts. These arguments must be any (unordered) subset of mode, compresslevel, and buffering.-
__init__(fileish, *args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
compress_ext_map= {'.gz': (<function _gzip_open>, ('mode', 'compresslevel', 'keep_open')), '.bz2': (<class 'bz2.BZ2File'>, ('mode', 'buffering', 'compresslevel')), None: (<built-in function open>, ('mode', 'buffering')), '.mgz': (<function _gzip_open>, ('mode', 'compresslevel', 'keep_open'))}¶
-
Opener¶
-
class
nibabel.openers.Opener(fileish, *args, **kwargs)¶ Bases:
objectClass to accept, maybe open, and context-manage file-likes / filenames
Provides context manager to close files that the constructor opened for you.
- Parameters
- fileishstr or file-like
if str, then open with suitable opening method. If file-like, accept as is
- *argspositional arguments
passed to opening method when fileish is str.
mode, if not specified, is rb.compresslevel, if relevant, and not specified, is set from class variabledefault_compresslevel.keep_open, if relevant, and not specified, isFalse.- **kwargskeyword arguments
passed to opening method when fileish is str. Change of defaults as for *args
-
__init__(fileish, *args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
bz2_def= (<class 'bz2.BZ2File'>, ('mode', 'buffering', 'compresslevel'))¶
-
close(*args, **kwargs)¶
-
close_if_mine()¶ Close
self.fobjiff we opened it in the constructor
-
property
closed¶
-
compress_ext_icase= True¶ whether to ignore case looking for compression extensions
-
compress_ext_map= {'.gz': (<function _gzip_open>, ('mode', 'compresslevel', 'keep_open')), '.bz2': (<class 'bz2.BZ2File'>, ('mode', 'buffering', 'compresslevel')), None: (<built-in function open>, ('mode', 'buffering'))}¶
-
default_compresslevel= 1¶ default compression level when writing gz and bz2 files
-
fileno()¶
-
gz_def= (<function _gzip_open>, ('mode', 'compresslevel', 'keep_open'))¶
-
property
mode¶
-
property
name¶ Return
self.fobj.nameor self._name if not presentself._name will be None if object was created with a fileobj, otherwise it will be the filename.
-
read(*args, **kwargs)¶
-
readinto(*args, **kwargs)¶
-
seek(*args, **kwargs)¶
-
tell(*args, **kwargs)¶
-
write(*args, **kwargs)¶