From b91858920694614b9c5a6e6ec6bc3fe7547edc79 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Wed, 10 Oct 2018 15:36:36 +0100 Subject: [PATCH] BF: Fix various issues in Image.save method. --- fsl/data/image.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fsl/data/image.py b/fsl/data/image.py index 5c97e7e4a..036d0575e 100644 --- a/fsl/data/image.py +++ b/fsl/data/image.py @@ -34,7 +34,6 @@ and file names: import os import os.path as op -import shutil import string import logging import tempfile @@ -1106,6 +1105,8 @@ class Image(Nifti): if ``filename`` is ``None``. """ + import fsl.utils.imcp as imcp + if self.__dataSource is None and filename is None: raise ValueError('A file name must be specified') @@ -1124,7 +1125,7 @@ class Image(Nifti): # then close the old image, move the # temp file to the real destination, # then re-open the file. - tmphd, tmpfname = tempfile.mkstemp(suffix=op.splitext(filename)[1]) + tmphd, tmpfname = tempfile.mkstemp(suffix=getExt(filename)) os.close(tmphd) try: @@ -1136,14 +1137,13 @@ class Image(Nifti): self.__nibImage = None self.header = None - shutil.copy(tmpfname, filename) + imcp.imcp(tmpfname, filename, overwrite=True) self.__nibImage = nib.load(filename) self.header = self.__nibImage.header finally: os.remove(tmpfname) - raise # Because we've created a new nibabel image, # we have to create a new ImageWrapper -- GitLab