Ejemplo n.º 1
0
def test_isFEATDir():

    # We need these files for a directory
    # to be considered a FEAT directory
    paths = ['analysis.feat/filtered_func_data.nii.gz',
             'analysis.feat/design.fsf',
             'analysis.feat/design.mat',
             'analysis.feat/design.con']

    with tests.testdir(paths) as testdir:
        assert featanalysis.isFEATDir(op.join(testdir, 'analysis.feat'))

    # If the directory does not end in .feat,
    # then it's not a feat directory
    with tests.testdir([p.replace('feat', 'bleat') for p in paths]) as testdir:
        assert not featanalysis.isFEATDir(op.join(testdir, 'analysis.bleat'))

    # If the directory doesn't exist, then
    # it's not a feat directory
    assert not featanalysis.isFEATDir('nonexistent.feat')

    # If any of the above files are not
    # present, it is not a FEAT directory
    perms = it.chain(it.combinations(paths, 1),
                     it.combinations(paths, 2),
                     it.combinations(paths, 3))
    for p in perms:
        with tests.testdir(p) as testdir:
            assert not featanalysis.isFEATDir(
                op.join(testdir, 'analysis.feat'))
Ejemplo n.º 2
0
def guessDataSourceType(path):
    """A convenience function which, given the name of a file or directory,
    figures out a suitable overlay type.

    Returns a tuple containing two values - a type which should be able to
    load the path, and the path itself, possibly adjusted. If the type
    is unrecognised, the first tuple value will be ``None``.
    """

    import fsl.data.mesh as fslmesh
    import fsl.data.gifti as fslgifti
    import fsl.data.featimage as featimage
    import fsl.data.melodicimage as melimage
    import fsl.data.dtifit as dtifit
    import fsl.data.melodicanalysis as melanalysis
    import fsl.data.featanalysis as featanalysis

    # Support files opened via fsleyes:// URL
    if path.startswith('fsleyes://'):
        path = path[10:]

    path = op.abspath(path)

    # VTK files are easy
    if path.endswith('.vtk'):
        return fslmesh.TriangleMesh, path

    # So are GIFTIS
    if path.endswith('.gii'):
        return fslgifti.GiftiSurface, path

    # Analysis directory?
    if op.isdir(path):
        if melanalysis.isMelodicDir(path):
            return melimage.MelodicImage, path

        elif featanalysis.isFEATDir(path):
            return featimage.FEATImage, path

        elif dtifit.isDTIFitPath(path):
            return dtifit.DTIFitTensor, path

    # Assume it's a NIFTI image
    try:
        path = fslimage.addExt(path, mustExist=True)
    except fslimage.PathError:
        return None, path

    if melanalysis.isMelodicImage(path): return melimage.MelodicImage, path
    elif featanalysis.isFEATImage(path): return featimage.FEATImage, path
    else: return fslimage.Image, path

    # Otherwise, I don't
    # know what to do
    return None, path
Ejemplo n.º 3
0
def guessDataSourceType(path):
    """A convenience function which, given the name of a file or directory,
    figures out a suitable overlay type.

    Returns a tuple containing two values - a type which should be able to
    load the path, and the path itself, possibly adjusted. If the type
    is unrecognised, the first tuple value will be ``None``.
    """

    import fsl.data.vtk as fslvtk
    import fsl.data.gifti as fslgifti
    import fsl.data.freesurfer as fslfs
    import fsl.data.mghimage as fslmgh
    import fsl.data.featimage as featimage
    import fsl.data.melodicimage as melimage
    import fsl.data.dtifit as dtifit
    import fsl.data.melodicanalysis as melanalysis
    import fsl.data.featanalysis as featanalysis

    # Support files opened via fsleyes:// URL
    if path.startswith('fsleyes://'):
        path = path[10:]

    path = op.abspath(path)

    # Accept images sans-extension
    try:
        path = fslimage.addExt(path, mustExist=True)
    except fslimage.PathError:
        pass

    if op.isfile(path):

        # Some types are easy - just check the extensions
        if fslpath.hasExt(path, fslvtk.ALLOWED_EXTENSIONS):
            return fslvtk.VTKMesh, path
        elif fslpath.hasExt(path, fslgifti.ALLOWED_EXTENSIONS):
            return fslgifti.GiftiMesh, path
        elif fslfs.isGeometryFile(path):
            return fslfs.FreesurferMesh, path
        elif fslpath.hasExt(path, fslmgh.ALLOWED_EXTENSIONS):
            return fslmgh.MGHImage, path

        # Other specialised image types
        elif melanalysis.isMelodicImage(path):
            return melimage.MelodicImage, path
        elif featanalysis.isFEATImage(path):
            return featimage.FEATImage, path
        elif fslimage.looksLikeImage(path):
            return fslimage.Image, path

    # Analysis directory?
    elif op.isdir(path):
        if melanalysis.isMelodicDir(path):
            return melimage.MelodicImage, path
        elif featanalysis.isFEATDir(path):
            return featimage.FEATImage, path
        elif dtifit.isDTIFitPath(path):
            return dtifit.DTIFitTensor, path

    # Otherwise, I don't
    # know what to do
    return None, path