From ad9fb0ea47f36fae32a84be17f11340d6f45f3d8 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Fri, 3 Jun 2016 19:02:47 +0100
Subject: [PATCH] Removed dead code - this will be added back in at some point
 in the future, but it's distracting me for the time being, so out it goes.

---
 fsl/data/image.py        | 140 ---------------------------------------
 fsl/data/imagewrapper.py |  61 -----------------
 2 files changed, 201 deletions(-)

diff --git a/fsl/data/image.py b/fsl/data/image.py
index 0cd061e86..9f9777292 100644
--- a/fsl/data/image.py
+++ b/fsl/data/image.py
@@ -33,8 +33,6 @@ file names:
 
 
 import               logging
-import               string
-import               os 
 import os.path    as op
 
 import               six 
@@ -548,32 +546,6 @@ class Image(Nifti1, notifier.Notifier):
         """
         return self.__imageWrapper.__getitem__(sliceobj)
 
-        
-    # def __setitem__(self, sliceobj, values):
-    #     """Changes the image data according to the given new values.
-    #     Any listeners registered on the :attr:`data` property will be
-    #     notified of the change.
-
-    #     :arg sliceobj:  Something with which the image array can be sliced.
-        
-    #     :arg values:    A numpy array containing the new image values.
-    #     """
-        
-    #     if values.size == 0:
-    #         return
-
-    #     self.__imageWrapper.__setitem__(sliceobj, values)
-    #     self.__saveState = False
-
-
-    # def save(self):
-    #     """Convenience method to save any changes made to the :attr:`data` of 
-    #     this :class:`Image` instance.
-
-    #     See the :func:`saveImage` function.
-    #     """
-    #     return saveImage(self)
-
 
 class ProxyImage(Image):
     """The ``ProxyImage`` class is a simple wrapper around an :class:`Image`
@@ -665,115 +637,3 @@ def addExt(prefix, mustExist=True):
                           ALLOWED_EXTENSIONS,
                           mustExist,
                           DEFAULT_EXTENSION)
-
-
-def saveImage(image, fromDir=None):
-    """Convenience function for interactively saving changes to an image.
-
-    If the :mod:`wx` package is available, a dialog is popped up, prompting
-    the user to select a destination. Or, if the image has been loaded 
-    from a file, the user is prompted to confirm that they want to overwrite  
-    the image.
-
-
-    :arg image:           The :class:`.Image` instance to be saved.
-
-    :arg fromDir:         Directory in which the file dialog should start.
-                          If ``None``, the most recently visited directory
-                          (via this method) is used, or the directory from
-                          the given image, or the current working directory.
-
-    :raise ImportError:  if :mod:`wx` is not present.
-    :raise RuntimeError: if a :class:`wx.App` has not been created.
-    """
-
-    if image.saved:
-        return
-    
-    import wx
-
-    app = wx.GetApp()
-
-    if app is None:
-        raise RuntimeError('A wx.App has not been created') 
-
-    lastDir = getattr(saveImage, 'lastDir', None)
-
-    if lastDir is None:
-        if image.dataSource is None: lastDir = os.getcwd()
-        else:                        lastDir = op.dirname(image.dataSource)
-
-    if image.dataSource is None:
-        filename = image.name
-
-        # Make sure the image name is safe to
-        # use as a file name - replace all
-        # non-alphanumeric/-/_ characters with _.
-        safechars = string.letters + string.digits + '_-'
-        filename  = ''.join([c if c in safechars else '_' for c in filename])
-    else:
-        filename = op.basename(image.dataSource)
-
-    filename = removeExt(filename)
-
-    saveLastDir = False
-    if fromDir is None:
-        fromDir = lastDir
-        saveLastDir = True
-
-    dlg = wx.FileDialog(app.GetTopWindow(),
-                        message='Save image file',
-                        defaultDir=fromDir,
-                        defaultFile=filename, 
-                        style=wx.FD_SAVE)
-
-    if dlg.ShowModal() != wx.ID_OK: return False
-
-    if saveLastDir: saveImage.lastDir = lastDir
-
-    path     = dlg.GetPath()
-    nibImage = image.nibImage
-
-    # Add a file extension if not specified
-    if not looksLikeImage(path):
-        path = addExt(path, False)
-
-    # this is an image which has been
-    # loaded from a file, and ungzipped
-    # to a temporary location
-    try:
-        if image.tempFile is not None:
-
-            # if selected path is same as original path,
-            # save to both temp file and to path
-
-            # else, if selected path is different from
-            # original path, save to temp file and to
-            # new path, and update the path
-
-            # actually, the two behaviours just described
-            # are identical
-            log.warn('Saving large images is not yet functional')
-            pass
-
-        # this is just a normal image
-        # which has been loaded from
-        # a file, or an in-memory image
-        else:
-
-            log.debug('Saving image ({}) to {}'.format(image, path))
-
-            import nibabel as nib
-            nib.save(nibImage, path)
-            image.dataSource = path
-            
-    except Exception as e:
-
-        msg = 'An error occurred saving the file. Details: {}'.format(e.msg)
-        log.warn(msg)
-        wx.MessageDialog(app.GetTopWindow(),
-                         message=msg,
-                         style=wx.OK | wx.ICON_ERROR).ShowModal()
-        return
-
-    image.saved = True
diff --git a/fsl/data/imagewrapper.py b/fsl/data/imagewrapper.py
index d3ebbdea7..bd8e73d9b 100644
--- a/fsl/data/imagewrapper.py
+++ b/fsl/data/imagewrapper.py
@@ -192,54 +192,6 @@ class ImageWrapper(notifier.Notifier):
                 self.__name, self.__range[0], self.__range[1]))
             self.notify()
 
-    
-    # def __updateDataRangeOnWrite(self, oldvals, newvals):
-    #     """Called by :meth:`__setitem__`. Re-calculates the image data
-    #     range, and returns a tuple containing the ``(min, max)`` values.
-    #     """
-
-    #     # The old known image wide data range.
-    #     oldmin, oldmax = self.dataRange
-
-    #     # The data range of the changed sub-array.
-    #     newvalmin = np.nanmin(newvals)
-    #     newvalmax = np.nanmax(newvals)
-
-    #     # Has the entire image been updated?
-    #     wholeImage = tuple(newvals.shape) == tuple(self.image.shape)
-
-    #     # If the minimum of the new values
-    #     # is less than the old image minimum, 
-    #     # then it becomes the new minimum.
-    #     if (newvalmin <= oldmin) or wholeImage:
-    #         newmin = newvalmin
-
-    #     # Or, if the old minimum is being
-    #     # replaced by the new values, we
-    #     # need to re-calculate the minimum
-    #     # from scratch.
-    #     elif np.nanmin(oldvals) == oldmin:
-    #         newmin = None
-
-    #     # Otherwise, the image minimum
-    #     # has not changed.
-    #     else:
-    #         newmin = oldmin
-
-    #     # The same logic applies to the maximum.
-    #     if   (newvalmax >= oldmax) or wholeImage: newmax = newvalmax
-    #     elif np.nanmax(oldvals) == oldmax:        newmax = None
-    #     else:                                     newmax = oldmax
-
-    #     if newmin is not None and np.isnan(newmin): newmin = oldmin
-    #     if newmax is not None and np.isnan(newmax): newmax = oldmax
-
-    #     if newmin != oldmin or newmax != oldmax:
-
-    #         log.debug('Image {} data range adjusted: {} - {}'.format(
-    #             self.__name, newmin, newmax))
-    #         self.notify() 
-    
 
     def __getitem__(self, sliceobj):
         """
@@ -271,16 +223,3 @@ class ImageWrapper(notifier.Notifier):
             self.__updateDataRangeOnRead(slices, data)
 
         return data
-
-
-    # def __setitem__(self, sliceobj, values):
-        
-    #     sliceobj = nib.fileslice.canonical_slicers(
-    #         sliceobj, self.__image.shape)
-
-    #     # This will cause the whole image to be
-    #     # loaded into memory and cached by nibabel
-    #     # (if it has not already done so).
-    #     self.__image.get_data()[sliceobj] = values
-
-    #     self.__updateDataRangeOnWrite(values)
-- 
GitLab