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

TEST: Test utils.guessType

parent 52f698a7
No related branches found
No related tags found
No related merge requests found
...@@ -358,6 +358,56 @@ def make_mock_feat_analysis(featdir, ...@@ -358,6 +358,56 @@ def make_mock_feat_analysis(featdir,
return featdir return featdir
def make_mock_melodic_analysis(basedir, shape4D, ntimepoints, xform=None):
if xform is None:
xform = np.eye(4)
ncomps = shape4D[-1]
halftime = int(np.floor(ntimepoints / 2))
os.makedirs(basedir)
make_random_image(op.join(basedir, 'melodic_IC.nii.gz'),
dims=shape4D,
xform=xform)
mix = np.random.randint(1, 255, (ntimepoints, ncomps))
ftmix = np.random.randint(1, 255, (halftime, ncomps))
np.savetxt(op.join(basedir, 'melodic_mix'), mix)
np.savetxt(op.join(basedir, 'melodic_FTmix'), ftmix)
def make_mock_dtifit_analysis(basedir, shape3D, basename='dti', xform=None, tensor=False):
if xform is None:
xform = np.eye(4)
os.makedirs(basedir)
shape4D = tuple(shape3D) + (3,)
def mk(ident, shp):
make_random_image(
op.join(basedir, '{}_{}.nii.gz'.format(basename, ident)),
shp,
xform)
mk('V1', shape4D)
mk('V2', shape4D)
mk('V3', shape4D)
mk('L1', shape3D)
mk('L2', shape3D)
mk('L3', shape3D)
mk('S0', shape3D)
mk('MD', shape3D)
mk('MO', shape3D)
mk('FA', shape3D)
if tensor:
mk('tensor', tuple(shape3D) + (6,))
def make_random_mask(filename, shape, xform, premask=None, minones=1): def make_random_mask(filename, shape, xform, premask=None, minones=1):
"""Make a random binary mask image. """ """Make a random binary mask image. """
......
#!/usr/bin/env python
#
# test_fsl_data_utils.py -
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
import shutil
import os
import os.path as op
import fsl.utils.tempdir as tempdir
import fsl.data.utils as dutils
import fsl.utils.path as fslpath
import fsl.data.image as fslimage
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
from . import (touch,
make_mock_feat_analysis,
make_mock_melodic_analysis,
make_mock_dtifit_analysis)
def test_guessType():
def asrt(path, cls):
restype, respath = dutils.guessType(path)
assert restype is cls
if path.startswith('fsleyes://'):
path = path[10:]
# image path might not have an extension
try:
path = fslimage.addExt(path, mustExist=True)
except fslimage.PathError:
pass
assert respath == op.abspath(path)
with tempdir.tempdir() as td:
touch('foo.nii')
asrt('foo', fslimage.Image)
asrt('foo.nii', fslimage.Image)
asrt('fsleyes://foo', fslimage.Image)
asrt('fsleyes://foo.nii', fslimage.Image)
os.remove('foo.nii')
touch('foo.vtk')
asrt('foo.vtk', fslvtk.VTKMesh)
os.remove('foo.vtk')
touch('foo.surf.gii')
asrt('foo.surf.gii', fslgifti.GiftiMesh)
os.remove('foo.surf.gii')
touch('lh.pial')
asrt('lh.pial', fslfs.FreesurferMesh)
os.remove('lh.pial')
touch('foo.mgz')
asrt('foo.mgz', fslmgh.MGHImage)
os.remove('foo.mgz')
make_mock_melodic_analysis('filtered_func_data.ica',
(10, 10, 10, 10),
20)
asrt('filtered_func_data.ica/melodic_IC', melimage.MelodicImage)
asrt('filtered_func_data.ica/melodic_IC.nii.gz', melimage.MelodicImage)
asrt('filtered_func_data.ica', melimage.MelodicImage)
asrt('filtered_func_data.ica/', melimage.MelodicImage)
shutil.rmtree('filtered_func_data.ica')
featdir = op.join(op.dirname(__file__),
'testdata', 'test_feat', '1stlevel_1.feat')
make_mock_feat_analysis(featdir,
td,
(10, 10, 10, 10))
asrt('1stlevel_1.feat/filtered_func_data', featimage.FEATImage)
asrt('1stlevel_1.feat/filtered_func_data.nii.gz', featimage.FEATImage)
asrt('1stlevel_1.feat', featimage.FEATImage)
make_mock_dtifit_analysis('dti', (10, 10, 10))
asrt('dti', dtifit.DTIFitTensor)
shutil.rmtree('dti')
asrt('noexist', None)
touch('norecognise')
asrt('norecognise', None)
touch('norecognise.txt')
asrt('norecognise.txt', None)
os.remove('norecognise')
os.remove('norecognise.txt')
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