def __init__(self, source, header=None, load=False, **kwargs): """ :Parameters: source: str | ndarray If source is a string, it is assumed to be a filename and an attempt will be made to open the corresponding NIfTI file. In case of an ndarray the array data will be used for the to be created nifti image and a matching nifti header is generated. If an object of a different type is supplied as 'source' a ValueError exception will be thrown. header: dict Additional header data might be supplied. However, dimensionality and datatype are determined from the ndarray and not taken from a header dictionary. load: Boolean If set to True the image data will be loaded into memory. This is only useful if loading a NIfTI image from file. This flag is almost useless, as the data will be loaded automatically whenever it is accessed. **kwargs: Additional stuff is passed to :class:`~nifti.format.NiftiFormat`. """ # setup all nifti header related stuff NiftiFormat.__init__(self, source, header, **kwargs) # where the data will go to self._data = None # load data if type(source) == N.ndarray: # assign data from source array self._data = source[:] elif type(source) in (str, unicode): # only load image data from file if requested if load: self.load() else: raise ValueError, "Unsupported source type. Only NumPy arrays and filename " + "string are supported."