diff --git a/fsl/data/model.py b/fsl/data/model.py index ededc41a58814eb78d5c9e9144affba05c600d3c..13b3510e607966a39ba2edb70428cf64012a0ea8 100644 --- a/fsl/data/model.py +++ b/fsl/data/model.py @@ -23,6 +23,8 @@ import numpy as np import six +from . import image as fslimage + log = logging.getLogger(__name__) @@ -149,3 +151,38 @@ def loadVTKPolydataFile(infile): indexOffset += polygonLengths[i] return vertices, polygonLengths, indices + + +def getFIRSTPrefix(modelfile): + """If the given ``vtk`` file was generated by `FIRST + <https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FIRST>`_, this function + will return the file prefix. Otherwise an ``Exception`` will be + raised. + """ + + if not modelfile.endswith('first.vtk'): + raise ValueError('Not a first vtk file: {}'.format(modelfile)) + + modelfile = op.basename(modelfile) + prefix = modelfile.split('-') + prefix = '-'.join(prefix[:-1]) + + return prefix + + +def findReferenceImage(modelfile): + """Given a ``vtk`` file, attempts to find a corresponding ``NIFTI`` + image file. Return the path to the image, or ``None`` if no image was + found. + + Currently this function will only return an image for ``vtk`` files + generated by `FIRST <https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FIRST>`_. + """ + + try: + + prefix = getFIRSTPrefix(modelfile) + return fslimage.addExt(prefix, mustExist=True) + + except: + return None diff --git a/fsl/utils/async.py b/fsl/utils/async.py index 4b835e28e5c156f9c8008e4912a5145d944e154b..4b403d794e101daf666acbb2731218d532784e99 100644 --- a/fsl/utils/async.py +++ b/fsl/utils/async.py @@ -372,7 +372,7 @@ def idle(task, *args, **kwargs): .. note:: You will run into difficulties if you schedule a function that expects/accepts its own keyword arguments called ``name``, - ``skipIfQueued``, ``after``, or ``timeout``. + ``skipIfQueued``, ``after``, ``timeout``, or ``alwaysQueue``. """ global _idleRegistered