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

ENH: New makeWriteable function

parent fd0b848f
No related branches found
No related tags found
No related merge requests found
...@@ -9,4 +9,5 @@ models, constants, and other data-like things used throughout ``fslpy``. ...@@ -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)
...@@ -10,7 +10,7 @@ with the data types defined in the :mod:`fsl.data` package. ...@@ -10,7 +10,7 @@ with the data types defined in the :mod:`fsl.data` package.
import os.path as op import os.path as op
import numpy as np
def guessType(path): def guessType(path):
"""A convenience function which, given the name of a file or directory, """A convenience function which, given the name of a file or directory,
...@@ -77,3 +77,14 @@ def guessType(path): ...@@ -77,3 +77,14 @@ def guessType(path):
# Otherwise, I don't # Otherwise, I don't
# know what to do # know what to do
return None, path 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
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