diff --git a/fsl/data/__init__.py b/fsl/data/__init__.py index c1890b375baadbf3a78f1ac8437145040cab8570..3c5afc3f2d09c49b5c1e5be18d20b7b5eab0cc56 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 e0fae151e05c02d5ecfe6289e5e1779ee9276a61..d902dc18a2b77c753c7d43f09d70398ebb25b71a 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