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

Merge remote-tracking branch 'upstream/msc' into mnt/msc

parents a3fdf3bb 448ac858
No related branches found
No related tags found
No related merge requests found
......@@ -162,8 +162,8 @@ def run(*args, **kwargs):
- stderr: Optional file-like object to which the command's
standard error stream can be forwarded.
- cmd: If ``True``, the command itself is logged to the
standard output stream(s).
- cmd: Optional file-like object to which the command itself
is logged.
:returns: If ``submit`` is provided, the return value of
:func:`.fslsub` is returned. Otherwise returns a single
......@@ -179,7 +179,7 @@ def run(*args, **kwargs):
tee = log .get('tee', False)
logStdout = log .get('stdout', None)
logStderr = log .get('stderr', None)
logCmd = log .get('cmd', False)
logCmd = log .get('cmd', None)
args = _prepareArgs(args)
if not bool(submit):
......@@ -257,8 +257,8 @@ def _realrun(tee, logStdout, logStderr, logCmd, *args):
:arg logStderr: Optional file-like object to which the command's standard
error stream can be forwarded.
:arg logCmd: If ``True``, the command itself is logged to the standard
output stream(s).
:arg logCmd: Optional file-like object to which the command itself is
logged.
:arg args: Command to run
......@@ -293,15 +293,13 @@ def _realrun(tee, logStdout, logStderr, logCmd, *args):
if logStdout is not None: outstreams.append(logStdout)
if logStderr is not None: errstreams.append(logStderr)
# log the command to
# stdout if requested
if logCmd:
# log the command if requested
if logCmd is not None:
cmd = ' '.join(args) + '\n'
for o in outstreams:
if 'b' in getattr(o, 'mode', 'w'):
o.write(cmd.encode('utf-8'))
else:
o.write(cmd)
if 'b' in getattr(logCmd, 'mode', 'w'):
logCmd.write(cmd.encode('utf-8'))
else:
logCmd.write(cmd)
stdoutt = _forwardStream(proc.stdout, *outstreams)
stderrt = _forwardStream(proc.stderr, *errstreams)
......@@ -325,23 +323,35 @@ def _realrun(tee, logStdout, logStderr, logCmd, *args):
def runfsl(*args, **kwargs):
"""Call a FSL command and return its output. This function simply prepends
``$FSLDIR/bin/`` to the command before passing it to :func:`run`.
"""Call a FSL command and return its output.
This function searches for the command in the following
locations (ordered by priority):
1. ``FSL_PREFIX``
2. ``$FSLDEVDIR/bin``
3. ``$FSLDIR/bin``
If found, the full path to the command is then passed to :func:`run`.
"""
prefix = None
prefixes = []
if FSL_PREFIX is not None:
prefix = FSL_PREFIX
elif fslplatform.fsldevdir is not None:
prefix = op.join(fslplatform.fsldevdir, 'bin')
elif fslplatform.fsldir is not None:
prefix = op.join(fslplatform.fsldir, 'bin')
else:
prefixes.append(FSL_PREFIX)
if fslplatform.fsldevdir is not None:
prefixes.append(op.join(fslplatform.fsldevdir, 'bin'))
if fslplatform.fsldir is not None:
prefixes.append(op.join(fslplatform.fsldir, 'bin'))
if not prefixes:
raise FSLNotPresent('$FSLDIR is not set - FSL cannot be found!')
args = _prepareArgs(args)
args[0] = op.join(prefix, args[0])
args = _prepareArgs(args)
for prefix in prefixes:
cmdpath = op.join(prefix, args[0])
if op.isfile(cmdpath):
args[0] = cmdpath
break
return run(*args, **kwargs)
......
......@@ -80,8 +80,10 @@ from .wrapperutils import (LOAD,) # noqa
from .bet import (bet, # noqa
robustfov)
from .eddy import (eddy_cuda, # noqa
topup)
topup,
applytopup)
from .fast import (fast,) # noqa
from .fsl_anat import (fsl_anat,) # noqa
from .flirt import (flirt, # noqa
invxfm,
applyxfm,
......
......@@ -35,6 +35,7 @@ def bet(input, output, **kwargs):
'robust' : 'R',
'fracintensity' : 'f',
'seg' : 'n',
'centre' : 'c',
}
valmap = {
......@@ -55,6 +56,14 @@ def bet(input, output, **kwargs):
}
cmd = ['bet', input, output]
# The 'centre' argument requires three co-ordinates and can't be passed
# as a single value, so needs to be handled separately. Assume it is
# passed as a Python sequence
centre = kwargs.pop("c", None)
if centre is not None:
cmd += ['-c', ] + [str(v) for v in centre]
cmd += wutils.applyArgStyle('-', argmap=argmap, valmap=valmap, **kwargs)
return cmd
......
......@@ -61,8 +61,8 @@ def eddy_cuda(imain, mask, index, acqp, bvecs, bvals, out, **kwargs):
return cmd
@wutils.fileOrImage('imain', 'fout', 'iout')
@wutils.fileOrArray('datain')
@wutils.fileOrImage('imain', 'fout', 'iout', outprefix='out')
@wutils.fileOrArray('datain', outprefix='out')
@wutils.fslwrapper
def topup(imain, datain, **kwargs):
"""Wrapper for the ``topup`` command."""
......@@ -78,3 +78,25 @@ def topup(imain, datain, **kwargs):
cmd += wutils.applyArgStyle('--=', valmap=valmap, **kwargs)
return cmd
@wutils.fileOrImage('imain', 'out')
@wutils.fileOrArray('datain')
@wutils.fslwrapper
def applytopup(imain, datain, index, **kwargs):
"""Wrapper for the ``applytopup`` command."""
valmap = {
'verbose' : wutils.SHOW_IF_TRUE
}
asrt.assertFileExists(datain)
asrt.assertIsNifti(imain)
cmd = [
'applytopup', '--imain={}'.format(imain),
'--inindex={}'.format(index),
'--datain={}'.format(datain),
]
cmd += wutils.applyArgStyle('--=', valmap=valmap, **kwargs)
return cmd
......@@ -33,12 +33,19 @@ def fast(imgs, out='fast', **kwargs):
asrt.assertIsNifti(*imgs)
valmap = {
'nobias' : wutils.SHOW_IF_TRUE,
'verbose' : wutils.SHOW_IF_TRUE,
'Prior' : wutils.SHOW_IF_TRUE,
'segments' : wutils.SHOW_IF_TRUE,
}
argmap = {
'n_classes' : 'class',
}
cmd = ['fast', '-v', '--out=%s' % out]
cmd += wutils.applyArgStyle('--=', argmap=argmap, **kwargs)
cmd += wutils.applyArgStyle('--=', valmap=valmap, argmap=argmap, singlechar_args=True, **kwargs)
cmd += imgs
return cmd
......@@ -59,14 +59,15 @@ def flirt(src, ref, **kwargs):
return cmd
def applyxfm(src, ref, mat, out, interp='spline'):
def applyxfm(src, ref, mat, out, interp='spline', **kwargs):
"""Convenience function which runs ``flirt -applyxfm ...``."""
return flirt(src,
ref,
out=out,
applyxfm=True,
init=mat,
interp=interp)
interp=interp,
**kwargs)
@wutils.fileOrArray()
......
......@@ -27,12 +27,12 @@ from . import wrapperutils as wutils
'refout', 'refmask', 'inmask')
@wutils.fileOrArray('aff')
@wutils.fslwrapper
def fnirt(src, ref, **kwargs):
def fnirt(src, **kwargs):
"""Wrapper for the ``fnirt`` command."""
asrt.assertIsNifti(src, ref)
asrt.assertIsNifti(src)
cmd = ['fnirt', '--in={}'.format(src), '--ref={}'.format(ref)]
cmd = ['fnirt', '--in={}'.format(src)]
cmd += wutils.applyArgStyle('--=', **kwargs)
return cmd
......@@ -41,7 +41,7 @@ def fnirt(src, ref, **kwargs):
@wutils.fileOrImage('src', 'ref', 'out', 'warp', 'mask')
@wutils.fileOrArray('premat', 'postmat')
@wutils.fslwrapper
def applywarp(src, ref, out, warp, **kwargs):
def applywarp(src, ref, out, **kwargs):
"""Wrapper for the ``applywarp`` command. """
valmap = {
......@@ -55,8 +55,7 @@ def applywarp(src, ref, out, warp, **kwargs):
cmd = ['applywarp',
'--in={}'.format(src),
'--ref={}'.format(ref),
'--out={}'.format(out),
'--warp={}'.format(warp)]
'--out={}'.format(out)]
cmd += wutils.applyArgStyle('--=', valmap=valmap, **kwargs)
......@@ -76,7 +75,7 @@ def invwarp(warp, ref, out, **kwargs):
'verbose' : wutils.SHOW_IF_TRUE,
}
asrt.assertIsNifti(warp, ref, out)
asrt.assertIsNifti(warp, ref)
cmd = ['invwarp',
'--warp={}'.format(warp),
......@@ -88,7 +87,7 @@ def invwarp(warp, ref, out, **kwargs):
return cmd
@wutils.fileOrImage('out', 'ref', 'warp1', 'warp2', 'shiftmap')
@wutils.fileOrImage('out', 'ref', 'warp1', 'warp2', 'shiftmap', 'jacobian')
@wutils.fileOrArray('premat', 'midmat', 'postmat')
@wutils.fslwrapper
def convertwarp(out, ref, **kwargs):
......@@ -99,7 +98,6 @@ def convertwarp(out, ref, **kwargs):
'rel' : wutils.SHOW_IF_TRUE,
'absout' : wutils.SHOW_IF_TRUE,
'relout' : wutils.SHOW_IF_TRUE,
'jacobian' : wutils.SHOW_IF_TRUE,
'jstats' : wutils.SHOW_IF_TRUE,
'constrainj' : wutils.SHOW_IF_TRUE,
'verbose' : wutils.SHOW_IF_TRUE,
......@@ -107,5 +105,4 @@ def convertwarp(out, ref, **kwargs):
cmd = ['convertwarp', '--ref={}'.format(ref), '--out={}'.format(out)]
cmd += wutils.applyArgStyle('--=', valmap=valmap, **kwargs)
return cmd
#!/usr/bin/env python
#
# fsl_anat.py - Wrapper for the FSL_ANAT command.
#
# Author: Martin Craig <martin.craig@eng.ox.ac.uk>
#
"""This module provides the :func:`fsl_anat` function, a wrapper for the FSL
`FSL_ANAT <https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/fsl_anat>`_ command.
"""
import six
import fsl.utils.assertions as asrt
from . import wrapperutils as wutils
@wutils.fileOrImage('img', outprefix='out')
@wutils.fslwrapper
def fsl_anat(img, out='fsl_anat', **kwargs):
"""Wrapper for the ``fsl_anat`` command.
:arg img: Input structural image
:arg out: Output directory name
"""
asrt.assertIsNifti(img)
valmap = {
'strongbias' : wutils.SHOW_IF_TRUE,
'weakbias' : wutils.SHOW_IF_TRUE,
'noreorient' : wutils.SHOW_IF_TRUE,
'nocrop' : wutils.SHOW_IF_TRUE,
'nobias' : wutils.SHOW_IF_TRUE,
'noreg' : wutils.SHOW_IF_TRUE,
'nononlinreg' : wutils.SHOW_IF_TRUE,
'noseg' : wutils.SHOW_IF_TRUE,
'nosubcortseg' : wutils.SHOW_IF_TRUE,
'nosearch' : wutils.SHOW_IF_TRUE,
'nocleanup' : wutils.SHOW_IF_TRUE,
}
argmap = {
}
img_type = kwargs.pop("img_type", "T1")
cmd = ['fsl_anat', '-i', img, '-o', out, '-t', img_type]
smoothing = kwargs.pop("bias_smoothing", None)
if smoothing is not None:
cmd += ['-s', str(smoothing)]
cmd += wutils.applyArgStyle('--=', valmap=valmap, argmap=argmap, singlechar_args=True, **kwargs)
return cmd
......@@ -153,11 +153,13 @@ def cmdwrapper(func):
:func:`fsl.utils.run.run` function in a standardised manner.
"""
def wrapper(*args, **kwargs):
submit = kwargs.pop('submit', None)
stdout = kwargs.pop('stdout', True)
stderr = kwargs.pop('stderr', True)
exitcode = kwargs.pop('exitcode', False)
submit = kwargs.pop('submit', None)
log = kwargs.pop('log', {'tee' : True})
cmd = func(*args, **kwargs)
return run.run(cmd, stderr=stderr, log=log, submit=submit)
return run.run(cmd, stderr=stderr, log=log, submit=submit, stdout=stdout, exitcode=exitcode)
return _update_wrapper(wrapper, func)
......@@ -167,11 +169,13 @@ def fslwrapper(func):
:func:`fsl.utils.run.runfsl` function in a standardised manner.
"""
def wrapper(*args, **kwargs):
submit = kwargs.pop('submit', None)
stdout = kwargs.pop('stdout', True)
stderr = kwargs.pop('stderr', True)
exitcode = kwargs.pop('exitcode', False)
submit = kwargs.pop('submit', None)
log = kwargs.pop('log', {'tee' : True})
cmd = func(*args, **kwargs)
return run.runfsl(cmd, stderr=stderr, log=log, submit=submit)
return run.runfsl(cmd, stderr=stderr, log=log, submit=submit, stdout=stdout, exitcode=exitcode)
return _update_wrapper(wrapper, func)
......@@ -193,7 +197,7 @@ generated command line arguments.
"""
def applyArgStyle(style, valsep=None, argmap=None, valmap=None, **kwargs):
def applyArgStyle(style, valsep=None, argmap=None, valmap=None, singlechar_args=False, **kwargs):
"""Turns the given ``kwargs`` into command line options. This function
is intended to be used to automatically generate command line options
from arguments passed into a Python function.
......@@ -252,6 +256,9 @@ def applyArgStyle(style, valsep=None, argmap=None, valmap=None, **kwargs):
The argument for any options not specified in the ``valmap``
will be converted into strings.
:arg singlechar_args: If True, single character arguments always take a single
hyphen prefix (e.g. -h) regardless of the style
:arg kwargs: Arguments to be converted into command-line options.
:returns: A list containing the generated command-line options.
......@@ -277,7 +284,7 @@ def applyArgStyle(style, valsep=None, argmap=None, valmap=None, **kwargs):
if valmap is None: valmap = {}
def fmtarg(arg):
if style in ('-', '-='): arg = '-{}'.format(arg)
if style in ('-', '-=') or (singlechar_args and len(arg) == 1): arg = '-{}'.format(arg)
elif style in ('--', '--='): arg = '--{}'.format(arg)
return arg
......@@ -304,11 +311,12 @@ def applyArgStyle(style, valsep=None, argmap=None, valmap=None, **kwargs):
for k, v in kwargs.items():
if v is None: continue
k = argmap.get(k, k)
mapv = valmap.get(k, fmtval(v))
k = fmtarg(k)
if mapv in (SHOW_IF_TRUE, HIDE_IF_TRUE):
if (mapv is SHOW_IF_TRUE and v) or \
(mapv is HIDE_IF_TRUE and not v):
......@@ -850,7 +858,6 @@ class _FileOrThing(object):
for prefixed in it.chain(*allPrefixed):
fullpath = prefixed
prefixed = op.relpath(prefixed, workdir)
for prefPat, prefName in prefixes.items():
if not fnmatch.fnmatch(prefixed, '{}*'.format(prefPat)):
continue
......@@ -863,10 +870,17 @@ class _FileOrThing(object):
# not of the correct type.
fval = self.__load(fullpath)
if fval is not None:
prefixed = self.__removeExt(prefixed)
noext = self.__removeExt(prefixed)
prefPat = prefPat.replace('\\', '\\\\')
prefixed = re.sub('^' + prefPat, prefName, prefixed)
result[prefixed] = fval
noext = re.sub('^' + prefPat, prefName, noext)
# If there is already an item in result with the
# name (stripped of prefix), then instead store
# the result with the full prefixed name
if noext not in result:
result[noext] = fval
else:
withext = re.sub('^' + prefPat, prefName, prefixed)
result[withext] = fval
break
return result
......@@ -888,8 +902,11 @@ def fileOrImage(*args, **kwargs):
infile = None
if isinstance(val, (fslimage.Image, nib.nifti1.Nifti1Image)):
intypes.append(type(val))
if isinstance(val, fslimage.Image):
intypes.append(fslimage.Image)
elif isinstance(val, nib.nifti1.Nifti1Image):
intypes.append(nib.nifti1.Nifti1Image)
if isinstance(val, fslimage.Image):
val = val.nibImage
......@@ -989,3 +1006,43 @@ def fileOrArray(*args, **kwargs):
return _update_wrapper(wrapper, func)
return decorator
def fileOrText(*args, **kwargs):
"""Decorator which can be used to ensure that any text output (e.g. log file are saved
to text files, and output files can be loaded and returned as strings.
"""
def prepIn(workdir, name, val):
infile = None
if isinstance(val, six.string_types):
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt') as f:
f.write(val)
infile = f.name
return infile
def prepOut(workdir, name, val):
return op.join(workdir, '{}.txt'.format(name))
def load(path):
try:
with open(path, "r") as f:
return f.read()
except Exception: return None
def decorator(func):
fot = _FileOrThing(func,
prepIn,
prepOut,
load,
fslpath.removeExt,
*args,
**kwargs)
def wrapper(*args, **kwargs):
return fot(*args, **kwargs)
return _update_wrapper(wrapper, func)
return decorator
......@@ -35,7 +35,7 @@ logging.getLogger().setLevel(logging.WARNING)
@contextlib.contextmanager
def mockFSLDIR():
def mockFSLDIR(**kwargs):
oldfsldir = fslplatform.fsldir
oldfsldevdir = fslplatform.fsldevdir
......@@ -45,6 +45,12 @@ def mockFSLDIR():
fsldir = op.join(td, 'fsl')
bindir = op.join(fsldir, 'bin')
os.makedirs(bindir)
for subdir, files in kwargs.items():
subdir = op.join(fsldir, subdir)
if not op.isdir(subdir):
os.makedirs(subdir)
for fname in files:
touch(op.join(subdir, fname))
fslplatform.fsldir = fsldir
fslplatform.fsldevdir = None
......
......@@ -353,20 +353,22 @@ def test_run_logcmd():
exit 0
""").strip()
expstdout = './script.sh 1 2 3\noutput 1 2 3\n'
expcmd = './script.sh 1 2 3\n'
expstdout = 'output 1 2 3\n'
with tempdir.tempdir():
mkexec('script.sh', test_script)
stdout = run.run('./script.sh 1 2 3', log={'cmd' : True})
assert stdout == expstdout
mkexec('script.sh', test_script)
stdout = run.run('./script.sh 1 2 3', log={'cmd' : True})
assert stdout == expstdout
with open('my_stdout', 'wt') as stdoutf:
stdout = run.run('./script.sh 1 2 3',
log={'cmd' : stdoutf})
assert stdout == expstdout
assert open('my_stdout', 'rt').read() == expcmd
with open('my_stdout', 'wt') as stdoutf:
stdout = run.run('./script.sh 1 2 3',
log={'cmd' : True, 'stdout' : stdoutf})
log={'cmd' : stdoutf, "stdout" : stdoutf})
assert stdout == expstdout
assert open('my_stdout', 'rt').read() == expstdout
assert open('my_stdout', 'rt').read() == expcmd + expstdout
......@@ -39,7 +39,7 @@ def checkResult(cmd, base, args, stripdir=None):
def test_bet():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('bet',)) as fsldir:
bet = op.join(fsldir, 'bin', 'bet')
result = fw.bet('input', 'output', mask=True, c=(10, 20, 30))
expected = (bet + ' input output', ('-m', '-c 10 20 30'))
......@@ -47,7 +47,7 @@ def test_bet():
def test_robustfov():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('robustfov',)) as fsldir:
rfov = op.join(fsldir, 'bin', 'robustfov')
result = fw.robustfov('input', 'output', b=180)
expected = (rfov + ' -i input', ('-r output', '-b 180'))
......@@ -55,7 +55,7 @@ def test_robustfov():
def test_eddy_cuda():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('eddy_cuda',)) as fsldir:
eddy = op.join(fsldir, 'bin', 'eddy_cuda')
result = fw.eddy_cuda('imain', 'mask', 'index', 'acqp',
'bvecs', 'bvals', 'out', dont_mask_output=True)
......@@ -72,7 +72,7 @@ def test_eddy_cuda():
def test_topup():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('topup',)) as fsldir:
topup = op.join(fsldir, 'bin', 'topup')
result = fw.topup('imain', 'datain', minmet=1)
expected = topup + ' --imain=imain --datain=datain --minmet=1'
......@@ -80,7 +80,7 @@ def test_topup():
def test_flirt():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('flirt',)) as fsldir:
flirt = op.join(fsldir, 'bin', 'flirt')
result = fw.flirt('src', 'ref', usesqform=True, anglerep='euler')
expected = (flirt + ' -in src -ref ref',
......@@ -89,7 +89,7 @@ def test_flirt():
def test_applyxfm():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('flirt',)) as fsldir:
flirt = op.join(fsldir, 'bin', 'flirt')
result = fw.applyxfm('src', 'ref', 'mat', 'out', interp='trilinear')
expected = (flirt + ' -in src -ref ref',
......@@ -101,7 +101,7 @@ def test_applyxfm():
def test_invxfm():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('convert_xfm',)) as fsldir:
cnvxfm = op.join(fsldir, 'bin', 'convert_xfm')
result = fw.invxfm('mat', 'output')
expected = cnvxfm + ' -omat output -inverse mat'
......@@ -109,7 +109,7 @@ def test_invxfm():
def test_concatxfm():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('convert_xfm',)) as fsldir:
cnvxfm = op.join(fsldir, 'bin', 'convert_xfm')
result = fw.concatxfm('mat1', 'mat2', 'output')
expected = cnvxfm + ' -omat output -concat mat2 mat1'
......@@ -117,7 +117,7 @@ def test_concatxfm():
def test_mcflirt():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('mcflirt',)) as fsldir:
mcflirt = op.join(fsldir, 'bin', 'mcflirt')
result = fw.mcflirt('input', out='output', cost='normcorr', dof=12)
expected = (mcflirt + ' -in input',
......@@ -128,28 +128,29 @@ def test_mcflirt():
def test_fnirt():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('fnirt',)) as fsldir:
fnirt = op.join(fsldir, 'bin', 'fnirt')
result = fw.fnirt('src', 'ref', iout='iout', fout='fout',
result = fw.fnirt('src', ref='ref', iout='iout', fout='fout',
subsamp=(8, 6, 4, 2))
expected = (fnirt + ' --in=src --ref=ref',
('--iout=iout',
expected = (fnirt + ' --in=src',
('--ref=ref',
'--iout=iout',
'--fout=fout',
'--subsamp=8,6,4,2'))
assert checkResult(result.output[0], *expected)
def test_applywarp():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('applywarp',)) as fsldir:
applywarp = op.join(fsldir, 'bin', 'applywarp')
result = fw.applywarp('src', 'ref', 'out', 'warp', abs=True, super=True)
expected = (applywarp + ' --in=src --ref=ref --out=out --warp=warp',
('--abs', '--super'))
result = fw.applywarp('src', 'ref', 'out', warp='warp', abs=True, super=True)
expected = (applywarp + ' --in=src --ref=ref --out=out',
('--warp=warp', '--abs', '--super'))
assert checkResult(result.output[0], *expected)
def test_invwarp():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('invwarp',)) as fsldir:
invwarp = op.join(fsldir, 'bin', 'invwarp')
result = fw.invwarp('warp', 'ref', 'out',
rel=True, noconstraint=True)
......@@ -159,16 +160,16 @@ def test_invwarp():
def test_convertwarp():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('convertwarp',)) as fsldir:
cnvwarp = op.join(fsldir, 'bin', 'convertwarp')
result = fw.convertwarp('out', 'ref', absout=True, jacobian=True)
result = fw.convertwarp('out', 'ref', absout=True, jacobian='jacobian')
expected = (cnvwarp + ' --ref=ref --out=out',
('--absout', '--jacobian'))
('--absout', '--jacobian=jacobian'))
assert checkResult(result.output[0], *expected)
def test_fugue():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('fugue',)) as fsldir:
fugue = op.join(fsldir, 'bin', 'fugue')
result = fw.fugue(input='input', warp='warp',
median=True, dwell=10)
......@@ -181,7 +182,7 @@ def test_fugue():
def test_sigloss():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('sigloss',)) as fsldir:
sigloss = op.join(fsldir, 'bin', 'sigloss')
result = fw.sigloss('input', 'sigloss', mask='mask', te=0.5)
expected = (sigloss + ' --in input --sigloss sigloss',
......@@ -190,7 +191,7 @@ def test_sigloss():
def test_melodic():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('melodic',)) as fsldir:
melodic = op.join(fsldir, 'bin', 'melodic')
result = fw.melodic('input', dim=50, mask='mask', Oall=True)
expected = (melodic + ' --in=input',
......@@ -199,7 +200,7 @@ def test_melodic():
def test_fsl_regfilt():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('fsl_regfilt',)) as fsldir:
regfilt = op.join(fsldir, 'bin', 'fsl_regfilt')
result = fw.fsl_regfilt('input', 'output', 'design',
filter=(1, 2, 3, 4), vn=True)
......@@ -210,7 +211,7 @@ def test_fsl_regfilt():
def test_fslreorient2std():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('fslreorient2std',)) as fsldir:
r2std = op.join(fsldir, 'bin', 'fslreorient2std')
result = fw.fslreorient2std('input', 'output')
expected = r2std + ' input output'
......@@ -218,7 +219,7 @@ def test_fslreorient2std():
def test_fslroi():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('fslroi',)) as fsldir:
fslroi = op.join(fsldir, 'bin', 'fslroi')
result = fw.fslroi('input', 'output', 1, 10)
......@@ -235,7 +236,7 @@ def test_fslroi():
def test_slicer():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('slicer',)) as fsldir:
slicer = op.join(fsldir, 'bin', 'slicer')
result = fw.slicer('input1', 'input2', i=(20, 100), x=(20, 'x.png'))
expected = slicer + ' input1 input2 -i 20 100 -x 20 x.png'
......@@ -243,7 +244,7 @@ def test_slicer():
def test_cluster():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('cluster',)) as fsldir:
cluster = op.join(fsldir, 'bin', 'cluster')
result = fw.cluster('input', 'thresh',
fractional=True, osize='osize')
......@@ -253,7 +254,7 @@ def test_cluster():
def test_fslmaths():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('fslmaths',)) as fsldir:
cmd = op.join(fsldir, 'bin', 'fslmaths')
result = fw.fslmaths('input') \
.abs().bin().binv().recip().Tmean().Tstd().Tmin().Tmax() \
......@@ -274,7 +275,7 @@ def test_fslmaths():
# TODO test LOAD output
def test_fast():
with asrt.disabled(), run.dryrun(), mockFSLDIR() as fsldir:
with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('fast',)) as fsldir:
cmd = op.join(fsldir, 'bin', 'fast')
......
......@@ -598,7 +598,7 @@ def test_fslwrapper():
def func(a, b):
return ['func', str(a), str(b)]
with run.dryrun(), mockFSLDIR() as fsldir:
with run.dryrun(), mockFSLDIR(bin=('func',)) as fsldir:
expected = '{} 1 2'.format(op.join(fsldir, 'bin', 'func'))
assert func(1, 2)[0] == expected
......
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