From 0646aaf92641585f291ee3e9445d600e79659cdc Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Fri, 12 Apr 2019 15:23:17 +0100
Subject: [PATCH] ENH: New makeWriteable function

---
 fsl/data/__init__.py |  3 ++-
 fsl/data/utils.py    | 13 ++++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/fsl/data/__init__.py b/fsl/data/__init__.py
index c1890b375..3c5afc3f2 100644
--- a/fsl/data/__init__.py
+++ b/fsl/data/__init__.py
@@ -9,4 +9,5 @@ models, constants, and other data-like things used throughout ``fslpy``.
 """
 
 
-from .utils import guessType  # noqa
+from .utils import (guessType,  # noqa
+                    makeWriteable)
diff --git a/fsl/data/utils.py b/fsl/data/utils.py
index e0fae151e..d902dc18a 100644
--- a/fsl/data/utils.py
+++ b/fsl/data/utils.py
@@ -10,7 +10,7 @@ with the data types defined in the :mod:`fsl.data` package.
 
 
 import os.path as op
-
+import numpy   as np
 
 def guessType(path):
     """A convenience function which, given the name of a file or directory,
@@ -77,3 +77,14 @@ def guessType(path):
     # Otherwise, I don't
     # know what to do
     return None, path
+
+
+def makeWriteable(array):
+    """Updates the given ``numpy.array`` so that it is writeable. If this
+    is not possible, a copy is created and returned.
+    """
+    try:
+        array.flags['WRITEABLE'] = True
+    except ValueError:
+        array = np.array(array)
+    return array
-- 
GitLab