Commit 0258fda1 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

fsl.utils.run.dryrun() calls will now return the command line. Useful for

testing. Tweaks to various wrapper functions. fslmaths returns results dict,
rather than file name (for testing).
parent 435141a8
......@@ -45,6 +45,8 @@ class FSLNotPresent(Exception):
def dryrun(*args):
"""Context manager which causes all calls to :func:`run` to be logged but
not executed. See the :data:`DRY_RUN` flag.
The returned standard output will be equal to ``' '.join(args)``.
"""
global DRY_RUN
......@@ -106,7 +108,7 @@ def run(*args, **kwargs):
log.debug('run: {}'.format(' '.join(args)))
if DRY_RUN:
stdout = '<dryrun>'
stdout = ' '.join(args)
stderr = ''
else:
proc = sp.Popen(args, stdout=sp.PIPE, stderr=sp.PIPE)
......
......@@ -151,7 +151,7 @@ class fslmaths(object):
# will only be one entry in
# the result dict.
if output is None: return list(result.values())[0]
else: return output
else: return result
@wutils.fileOrImage()
@wutils.fslwrapper
......
......@@ -17,9 +17,13 @@ from . import wrapperutils as wutils
@wutils.fileOrImage('in', 'unwarp', 'warp', 'phasemap', 'savefmap',
'loadfmap', 'saveshift', 'loadshift', 'mask')
@wutils.fslwrapper
def fugue(**kwargs):
def fugue(input=None, **kwargs):
"""Wrapper for the ``fugue`` command."""
argmap = {
'input' : 'in'
}
valmap = {
'dwelltoasym' : wutils.SHOW_IF_TRUE,
'median' : wutils.SHOW_IF_TRUE,
......@@ -37,7 +41,12 @@ def fugue(**kwargs):
'verbose' : wutils.SHOW_IF_TRUE,
}
cmd = ['fugue'] + wutils.applyArgStyle('--=', valmap=valmap, **kwargs)
kwargs.update({'input' : input})
cmd = ['fugue'] + wutils.applyArgStyle('--=',
argmap=argmap,
valmap=valmap,
**kwargs)
return cmd
......
......@@ -52,7 +52,7 @@ def melodic(input, **kwargs):
asrt.assertIsNifti(input)
cmd = ['melodic', '--in', input]
cmd = ['melodic', '--in={}'.format(input)]
cmd += wutils.applyArgStyle('--=', valmap=valmap, **kwargs)
return cmd
......@@ -77,6 +77,6 @@ def fsl_regfilt(input, out, design, **kwargs):
'--in={}'.format(input),
'--out={}'.format(out),
'--design={}'.format(design)]
cmd += wutils.applyArgStyle('--=', valmap=valmap, **kwargs)
cmd += wutils.applyArgStyle('--=', valsep=',', valmap=valmap, **kwargs)
return cmd
......@@ -31,49 +31,33 @@ def fslreorient2std(input, output=None):
@wutils.fileOrImage('input', 'output')
@wutils.fslwrapper
def fslroi(input, output, xmin=None, xsize=None, ymin=None, ysize=None,
zmin=None, zsize=None, tmin=None, tsize=None):
def fslroi(input, output, *args):
"""Wrapper for the ``fslroi`` tool."""
assert ((tmin is not None and tsize is not None) or
(xmin is not None and xsize is not None and
ymin is not None and ysize is not None and
zmin is not None and zsize is not None)), \
"either time min/size or x/y/z min/size must be provided"
cmd = ['fslroi', input, output]
asrt.assertIsNifti(input)
if xmin is not None:
cmd += [str(v) for v in [xmin, xsize, ymin, ysize, zmin, zsize]]
if tmin is not None:
cmd += [str(tmin), str(tsize)]
cmd = ['fslroi', input, output] + [str(a) for a in args]
return cmd
@wutils.fileOrImage('input', 'input2')
@wutils.fslwrapper
def slicer(input, input2=None, label=None, lut=None, intensity=None,
edgethreshold=None, x=None, y=None, z=None):
def slicer(input, input2=None, **kwargs):
"""Wrapper for the ``slicer`` command. """
cmd = "slicer {0}".format(input)
cmd = ['slicer', input]
if input2 is not None:
cmd += " {0}".format(input2)
if label is not None:
cmd += " -L {0}".format(label)
if lut is not None:
cmd += " -l {0}".format(lut)
if intensity is not None:
cmd += " -i {0} {1}".format(intensity[0], intensity[1])
if edgethreshold is not None:
cmd += " -e {0}".format(edgethreshold)
if x is not None:
cmd += " -x {0} {1}".format(x[0], x[1])
if y is not None:
cmd += " -y {0} {1}".format(y[0], y[1])
if z is not None:
cmd += " -z {0} {1}".format(z[0], z[1])
cmd.append(input2)
# slicer output options must be
# applied after other options
outopts = ['x', 'y', 'z', 'a', 'A', 'S']
outargs = { k : kwargs.pop(k) for k in outopts if k in kwargs}
cmd = cmd + wutils.applyArgStyle('-', **kwargs) + \
wutils.applyArgStyle('-', **outargs)
return cmd
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment