Skip to content
Snippets Groups Projects
Commit a040a24f authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

RF: Adjust Image.save workflow to ensure image data is synced

parent d9eb1949
No related branches found
No related tags found
No related merge requests found
...@@ -1204,6 +1204,9 @@ class Image(Nifti): ...@@ -1204,6 +1204,9 @@ class Image(Nifti):
@property @property
def nibImage(self): def nibImage(self):
"""Returns a reference to the ``nibabel`` NIFTI image instance. """Returns a reference to the ``nibabel`` NIFTI image instance.
Note that if the image data has been modified through this ``Image``,
it will be out of sync with what is returned by the ``nibabel`` object,
until a call to :meth:`save` is made.
""" """
return self.__nibImage return self.__nibImage
...@@ -1387,6 +1390,21 @@ class Image(Nifti): ...@@ -1387,6 +1390,21 @@ class Image(Nifti):
os.close(tmphd) os.close(tmphd)
try: try:
# First of all, the nibabel object won't know
# about any image data modifications, so if
# any have occurred, we need to create a new
# nibabel image using the data managed by the
# imagewrapper, and the old header.
#
# Assuming here that analyze/nifti1/nifti2
# nibabel classes have an __init__ which
# expects (data, affine, header)
if not self.saveState:
self.__nibImage = type(self.__nibImage)(self[:],
None,
self.header)
self.header = self.__nibImage.header
nib.save(self.__nibImage, tmpfname) nib.save(self.__nibImage, tmpfname)
# nibabel should close any old # nibabel should close any old
...@@ -1395,6 +1413,8 @@ class Image(Nifti): ...@@ -1395,6 +1413,8 @@ class Image(Nifti):
self.__nibImage = None self.__nibImage = None
self.header = None self.header = None
# Copy to final destination,
# and reload from there
imcp.imcp(tmpfname, filename, overwrite=True) imcp.imcp(tmpfname, filename, overwrite=True)
self.__nibImage = nib.load(filename) self.__nibImage = nib.load(filename)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment