diff --git a/fsl/utils/run.py b/fsl/utils/run.py index f469af4873effcb400a9ef2f3a181c98100f96f7..3fb7d979eb9848ed8c4a878a53edd6b0c39eb052 100644 --- a/fsl/utils/run.py +++ b/fsl/utils/run.py @@ -21,7 +21,6 @@ import sys import logging -import warnings import threading import contextlib import collections @@ -129,7 +128,7 @@ def run(*args, **kwargs): argument. An exception is raised if the command returns a non-zero exit code, unless - the ``ret`` option is set to ``True``. + the ``exitcode`` option is set to ``True``. :arg stdout: Must be passed as a keyword argument. Defaults to ``True``. If ``True``, standard output is captured and returned. @@ -162,8 +161,8 @@ def run(*args, **kwargs): - stderr: Optional file-like object to which the command's standard error stream can be forwarded. - - cmd: Optional file-like object to which the command itself - is logged. + - 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 @@ -323,11 +322,11 @@ def _realrun(tee, logStdout, logStderr, logCmd, *args): def runfsl(*args, **kwargs): - """Call a FSL command and return its output. - + """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`` @@ -342,7 +341,7 @@ def runfsl(*args, **kwargs): 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!') diff --git a/fsl/wrappers/bet.py b/fsl/wrappers/bet.py index 31660d122addd1f30fb0de857a97219d64f350f0..895f0aa88365fc5044d95fcae7694ee3dc87ed64 100644 --- a/fsl/wrappers/bet.py +++ b/fsl/wrappers/bet.py @@ -4,6 +4,7 @@ # # Author: Sean Fitzgibbon <sean.fitzgibbon@ndcn.ox.ac.uk> # Author: Paul McCarthy <pauldmccarthy@gmail.com> +# Author: Martin Craig <martin.craig@eng.ox.ac.uk> # """This module provides the :func:`bet` function, a wrapper for the FSL `BET <https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/BET>`_ command. @@ -58,7 +59,7 @@ 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 + # 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: diff --git a/fsl/wrappers/eddy.py b/fsl/wrappers/eddy.py index 3419c99d133045a4b34762e85de4d1e5f24528d1..53a90b9ca263984a1be1b168f6ea6a2c02e4e865 100644 --- a/fsl/wrappers/eddy.py +++ b/fsl/wrappers/eddy.py @@ -4,6 +4,7 @@ # # Author: Sean Fitzgibbon <sean.fitzgibbon@ndcn.ox.ac.uk> # Author: Paul McCarthy <pauldmccarthy@gmail.com> +# Author: Martin Craig <martin.craig@eng.ox.a.uk> # """This module provides wrapper functions for the FSL `TOPUP <https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/topup>`_ and `EDDY @@ -15,6 +16,7 @@ estimation and eddy-current distortion correction. eddy_cuda topup + applytopup """ @@ -93,8 +95,8 @@ def applytopup(imain, datain, index, **kwargs): asrt.assertIsNifti(imain) cmd = [ - 'applytopup', '--imain={}'.format(imain), - '--inindex={}'.format(index), + 'applytopup', '--imain={}'.format(imain), + '--inindex={}'.format(index), '--datain={}'.format(datain), ] cmd += wutils.applyArgStyle('--=', valmap=valmap, **kwargs) diff --git a/fsl/wrappers/fast.py b/fsl/wrappers/fast.py index b1cd712ac99e9e45d2e97f74f5dae5b38c6e80c0..5dbe2a412c4b3bbf30a7ce9c707a16de06bc8af8 100644 --- a/fsl/wrappers/fast.py +++ b/fsl/wrappers/fast.py @@ -45,7 +45,11 @@ def fast(imgs, out='fast', **kwargs): } cmd = ['fast', '-v', '--out=%s' % out] - cmd += wutils.applyArgStyle('--=', valmap=valmap, argmap=argmap, singlechar_args=True, **kwargs) + cmd += wutils.applyArgStyle('--=', + valmap=valmap, + argmap=argmap, + singlechar_args=True, + **kwargs) cmd += imgs return cmd diff --git a/fsl/wrappers/fsl_anat.py b/fsl/wrappers/fsl_anat.py index a1ea260c137049a0dd26b1a84dbbd3184dc1e78c..868dacb70d206fe5a9b53907668cc7641513bf52 100644 --- a/fsl/wrappers/fsl_anat.py +++ b/fsl/wrappers/fsl_anat.py @@ -46,6 +46,10 @@ def fsl_anat(img, out='fsl_anat', **kwargs): if smoothing is not None: cmd += ['-s', str(smoothing)] - cmd += wutils.applyArgStyle('--=', valmap=valmap, argmap=argmap, singlechar_args=True, **kwargs) + cmd += wutils.applyArgStyle('--=', + valmap=valmap, + argmap=argmap, + singlechar_args=True, + **kwargs) return cmd diff --git a/fsl/wrappers/wrapperutils.py b/fsl/wrappers/wrapperutils.py index 2bda19793ffca266038421e734738b55743604e4..88db1dc92b7774cc683aedbd6e55dbeef25fb032 100644 --- a/fsl/wrappers/wrapperutils.py +++ b/fsl/wrappers/wrapperutils.py @@ -4,6 +4,7 @@ # functions. # # Author: Paul McCarthy <pauldmccarthy@gmail.com> +# Author: Martin Craig <martin.craig@eng.ox.ac.uk> # """This module contains functions and decorators used by the FSL wrapper functions. @@ -159,7 +160,12 @@ def cmdwrapper(func): 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, stdout=stdout, exitcode=exitcode) + return run.run(cmd, + stderr=stderr, + log=log, + submit=submit, + stdout=stdout, + exitcode=exitcode) return _update_wrapper(wrapper, func) @@ -175,7 +181,12 @@ def fslwrapper(func): 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, stdout=stdout, exitcode=exitcode) + return run.runfsl(cmd, + stderr=stderr, + log=log, + submit=submit, + stdout=stdout, + exitcode=exitcode) return _update_wrapper(wrapper, func) @@ -197,7 +208,12 @@ generated command line arguments. """ -def applyArgStyle(style, valsep=None, argmap=None, valmap=None, singlechar_args=False, **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. @@ -256,8 +272,9 @@ def applyArgStyle(style, valsep=None, argmap=None, valmap=None, singlechar_args= 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 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. @@ -284,8 +301,10 @@ def applyArgStyle(style, valsep=None, argmap=None, valmap=None, singlechar_args= if valmap is None: valmap = {} def fmtarg(arg): - if style in ('-', '-=') or (singlechar_args and len(arg) == 1): arg = '-{}'.format(arg) - elif 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 # always returns a sequence @@ -1007,9 +1026,11 @@ def fileOrArray(*args, **kwargs): 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. + """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):