Commit 72131e59 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

DOC,STY: Tweaks to code style, docs, updated authors.

parent e5cd3922
......@@ -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!')
......
......@@ -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:
......
......@@ -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)
......
......@@ -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
......@@ -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
......@@ -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):
......
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