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

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

parent e5cd3922
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
import sys import sys
import logging import logging
import warnings
import threading import threading
import contextlib import contextlib
import collections import collections
...@@ -129,7 +128,7 @@ def run(*args, **kwargs): ...@@ -129,7 +128,7 @@ def run(*args, **kwargs):
argument. argument.
An exception is raised if the command returns a non-zero exit code, unless 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``. :arg stdout: Must be passed as a keyword argument. Defaults to ``True``.
If ``True``, standard output is captured and returned. If ``True``, standard output is captured and returned.
...@@ -162,8 +161,8 @@ def run(*args, **kwargs): ...@@ -162,8 +161,8 @@ def run(*args, **kwargs):
- stderr: Optional file-like object to which the command's - stderr: Optional file-like object to which the command's
standard error stream can be forwarded. standard error stream can be forwarded.
- cmd: Optional file-like object to which the command itself - cmd: Optional file-like object to which the command
is logged. itself is logged.
:returns: If ``submit`` is provided, the return value of :returns: If ``submit`` is provided, the return value of
:func:`.fslsub` is returned. Otherwise returns a single :func:`.fslsub` is returned. Otherwise returns a single
...@@ -323,11 +322,11 @@ def _realrun(tee, logStdout, logStderr, logCmd, *args): ...@@ -323,11 +322,11 @@ def _realrun(tee, logStdout, logStderr, logCmd, *args):
def runfsl(*args, **kwargs): 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 This function searches for the command in the following
locations (ordered by priority): locations (ordered by priority):
1. ``FSL_PREFIX`` 1. ``FSL_PREFIX``
2. ``$FSLDEVDIR/bin`` 2. ``$FSLDEVDIR/bin``
3. ``$FSLDIR/bin`` 3. ``$FSLDIR/bin``
...@@ -342,7 +341,7 @@ def runfsl(*args, **kwargs): ...@@ -342,7 +341,7 @@ def runfsl(*args, **kwargs):
prefixes.append(op.join(fslplatform.fsldevdir, 'bin')) prefixes.append(op.join(fslplatform.fsldevdir, 'bin'))
if fslplatform.fsldir is not None: if fslplatform.fsldir is not None:
prefixes.append(op.join(fslplatform.fsldir, 'bin')) prefixes.append(op.join(fslplatform.fsldir, 'bin'))
if not prefixes: if not prefixes:
raise FSLNotPresent('$FSLDIR is not set - FSL cannot be found!') raise FSLNotPresent('$FSLDIR is not set - FSL cannot be found!')
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
# #
# Author: Sean Fitzgibbon <sean.fitzgibbon@ndcn.ox.ac.uk> # Author: Sean Fitzgibbon <sean.fitzgibbon@ndcn.ox.ac.uk>
# Author: Paul McCarthy <pauldmccarthy@gmail.com> # 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 """This module provides the :func:`bet` function, a wrapper for the FSL
`BET <https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/BET>`_ command. `BET <https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/BET>`_ command.
...@@ -58,7 +59,7 @@ def bet(input, output, **kwargs): ...@@ -58,7 +59,7 @@ def bet(input, output, **kwargs):
cmd = ['bet', input, output] cmd = ['bet', input, output]
# The 'centre' argument requires three co-ordinates and can't be passed # 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 # passed as a Python sequence
centre = kwargs.pop("c", None) centre = kwargs.pop("c", None)
if centre is not None: if centre is not None:
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
# #
# Author: Sean Fitzgibbon <sean.fitzgibbon@ndcn.ox.ac.uk> # Author: Sean Fitzgibbon <sean.fitzgibbon@ndcn.ox.ac.uk>
# Author: Paul McCarthy <pauldmccarthy@gmail.com> # Author: Paul McCarthy <pauldmccarthy@gmail.com>
# Author: Martin Craig <martin.craig@eng.ox.a.uk>
# #
"""This module provides wrapper functions for the FSL `TOPUP """This module provides wrapper functions for the FSL `TOPUP
<https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/topup>`_ and `EDDY <https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/topup>`_ and `EDDY
...@@ -15,6 +16,7 @@ estimation and eddy-current distortion correction. ...@@ -15,6 +16,7 @@ estimation and eddy-current distortion correction.
eddy_cuda eddy_cuda
topup topup
applytopup
""" """
...@@ -93,8 +95,8 @@ def applytopup(imain, datain, index, **kwargs): ...@@ -93,8 +95,8 @@ def applytopup(imain, datain, index, **kwargs):
asrt.assertIsNifti(imain) asrt.assertIsNifti(imain)
cmd = [ cmd = [
'applytopup', '--imain={}'.format(imain), 'applytopup', '--imain={}'.format(imain),
'--inindex={}'.format(index), '--inindex={}'.format(index),
'--datain={}'.format(datain), '--datain={}'.format(datain),
] ]
cmd += wutils.applyArgStyle('--=', valmap=valmap, **kwargs) cmd += wutils.applyArgStyle('--=', valmap=valmap, **kwargs)
......
...@@ -45,7 +45,11 @@ def fast(imgs, out='fast', **kwargs): ...@@ -45,7 +45,11 @@ def fast(imgs, out='fast', **kwargs):
} }
cmd = ['fast', '-v', '--out=%s' % out] 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 cmd += imgs
return cmd return cmd
...@@ -46,6 +46,10 @@ def fsl_anat(img, out='fsl_anat', **kwargs): ...@@ -46,6 +46,10 @@ def fsl_anat(img, out='fsl_anat', **kwargs):
if smoothing is not None: if smoothing is not None:
cmd += ['-s', str(smoothing)] 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 return cmd
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
# functions. # functions.
# #
# Author: Paul McCarthy <pauldmccarthy@gmail.com> # 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 """This module contains functions and decorators used by the FSL wrapper
functions. functions.
...@@ -159,7 +160,12 @@ def cmdwrapper(func): ...@@ -159,7 +160,12 @@ def cmdwrapper(func):
submit = kwargs.pop('submit', None) submit = kwargs.pop('submit', None)
log = kwargs.pop('log', {'tee' : True}) log = kwargs.pop('log', {'tee' : True})
cmd = func(*args, **kwargs) 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) return _update_wrapper(wrapper, func)
...@@ -175,7 +181,12 @@ def fslwrapper(func): ...@@ -175,7 +181,12 @@ def fslwrapper(func):
submit = kwargs.pop('submit', None) submit = kwargs.pop('submit', None)
log = kwargs.pop('log', {'tee' : True}) log = kwargs.pop('log', {'tee' : True})
cmd = func(*args, **kwargs) 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) return _update_wrapper(wrapper, func)
...@@ -197,7 +208,12 @@ generated command line arguments. ...@@ -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 """Turns the given ``kwargs`` into command line options. This function
is intended to be used to automatically generate command line options is intended to be used to automatically generate command line options
from arguments passed into a Python function. from arguments passed into a Python function.
...@@ -256,8 +272,9 @@ def applyArgStyle(style, valsep=None, argmap=None, valmap=None, singlechar_args= ...@@ -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`` The argument for any options not specified in the ``valmap``
will be converted into strings. will be converted into strings.
:arg singlechar_args: If True, single character arguments always take a single :arg singlechar_args: If True, single character arguments always take a
hyphen prefix (e.g. -h) regardless of the style single hyphen prefix (e.g. -h) regardless of the
style.
:arg kwargs: Arguments to be converted into command-line options. :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= ...@@ -284,8 +301,10 @@ def applyArgStyle(style, valsep=None, argmap=None, valmap=None, singlechar_args=
if valmap is None: valmap = {} if valmap is None: valmap = {}
def fmtarg(arg): def fmtarg(arg):
if style in ('-', '-=') or (singlechar_args and len(arg) == 1): arg = '-{}'.format(arg) if style in ('-', '-=') or (singlechar_args and len(arg) == 1):
elif style in ('--', '--='): arg = '--{}'.format(arg) arg = '-{}'.format(arg)
elif style in ('--', '--='):
arg = '--{}'.format(arg)
return arg return arg
# always returns a sequence # always returns a sequence
...@@ -1007,9 +1026,11 @@ def fileOrArray(*args, **kwargs): ...@@ -1007,9 +1026,11 @@ def fileOrArray(*args, **kwargs):
return decorator return decorator
def fileOrText(*args, **kwargs): def fileOrText(*args, **kwargs):
"""Decorator which can be used to ensure that any text output (e.g. log file are saved """Decorator which can be used to ensure that any text output (e.g. log
to text files, and output files can be loaded and returned as strings. file) are saved to text files, and output files can be loaded and returned
as strings.
""" """
def prepIn(workdir, name, val): def prepIn(workdir, name, val):
......
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