Skip to content
Snippets Groups Projects
Commit df1135e4 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

fsl.data.model module has a couple of convenience functions for trying to find

identifying reference image associated with a FIRST vtk file.
parent c0d83662
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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
......
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