def save(self, type='', squeeze_data=True,  verbose=1):
        from nibabel import Nifti1Image, save
        from sct_utils import printv
        from numpy import squeeze
        from os import path, remove
        if squeeze_data:
            # remove singleton
            self.data = squeeze(self.data)
        if type != '':
            self.changeType(type)
        # update header
        if self.hdr:
            self.hdr.set_data_shape(self.data.shape)
        img = Nifti1Image(self.data, None, self.hdr)
        fname_out = self.path + self.file_name + self.ext
        if path.isfile(fname_out):
            printv('WARNING: File '+fname_out+' already exists. Deleting it.', verbose, 'warning')
            remove(fname_out)
        # save file
        save(img, fname_out)

    # flatten the array in a single dimension vector, its shape will be (d, 1) compared to the flatten built in method
    # which would have returned (d,)
Write an image in a nifti file
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/scripts/msct_image.py/Image.save