__init__.py 4.05 KB
Newer Older
1
2
3
4
5
6
7
8
#!/usr/bin/env python
#
# __init__.py - Wrappers for FSL command-line tools.
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
"""This package contains wrappers for various FSL command line tools, allowing
them to be called from Python.
Paul McCarthy's avatar
Paul McCarthy committed
9
10


11
12
13
14
15
For example, you can call BET like so::

    from fsl.wrappers import bet
    bet('struct', 'struct_brain')

16
17
18
19
20
21
22
23
24
25
26
27
If you would like a command to be submitted as a cluster job, all wrappers
accept a ``submit`` keyword argument, which may be given a value of ``True``
indicating that the job should be submitted with default settings, or a
dictionary with submission settings::

    from fsl.wrappers import fnirt
    fnirt('srf', 'ref', 'out', submit=True)
    fnirt('srf', 'ref', 'out', submit={'queue' : 'long.q', 'ram' : '4GB'})


See the :mod:`.fslsub` module for more details.

28
29
30
31
32

Most of these wrapper functions strive to provide an interface which is as
close as possible to the underlying command-line tool. Most functions use
positional arguments for required options, and keyword arguments for all other
options, with argument names equivalent to command line option names.
Paul McCarthy's avatar
Paul McCarthy committed
33
34
35
36
37
38
39


For options where this is not possible (e.g. ``flirt -2D``),an alias is used
instead. Aliases may also be used to provide a more readable interface (e.g.
the :func:`.bet` function uses ``mask`` instead of ``m``).


40
41
Two exceptions to the above are :class:`.fslmaths` and :class:`.fslstats`,
which provide a more object-oriented interface::
42

Paul McCarthy's avatar
Paul McCarthy committed
43
44
    from fsl.wrappers import fslmaths, fslstats

45
46
    fslmaths('image.nii').mas('mask.nii').bin().run('output.nii')

Paul McCarthy's avatar
Paul McCarthy committed
47
48
    imean, imin, imax = fslstats('image.nii').k('mask.nii').m.R.run()

49

Paul McCarthy's avatar
Paul McCarthy committed
50
51
52
53
54
55
56
57
58
59
60
61
Wrapper functions for commands which accept NIfTI image or numeric text files
will for the most part accept either in-memory ``nibabel`` images/Numpy arrays
or file names as inputs. For commands which produce image or numeric text file
outputs, the special :data:`.LOAD` value can be used to indicate that the file
should be loaded and returned in-memory from the wrapper function. For example,
if we want to FLIRT two images and get the result, we can do this::

    import nibabel as nib
    from fsl.wrappers import flirt, LOAD

    src     = nib.load('src.nii')
    ref     = nib.load('ref.nii')
62
63
64
65
66
67
68
    init    = np.eye(4)
    aligned = flirt(src, ref, init=init, out=LOAD)['out']


Similarly, we can run a ``fslmaths`` command on in-memory images::

    import nibabel as nib
69
    from fsl.wrappers import fslmaths
70
71
72

    image  = nib.load('image.nii')
    mask   = nib.load('mask.nii')
73
    output = fslmaths(image).mas(mask).bin().run()
Paul McCarthy's avatar
Paul McCarthy committed
74
75


76
77
78
If you are *writing* wrapper functions, take a look at the
:mod:`.wrapperutils` module - it contains several useful functions and
decorators.
79
80
"""

Paul McCarthy's avatar
Paul McCarthy committed
81
82
83
84

from .wrapperutils import (LOAD,)           # noqa
from .bet          import (bet,             # noqa
                           robustfov)
Paul McCarthy's avatar
Paul McCarthy committed
85
from .eddy         import (eddy_cuda,       # noqa
Martin Craig's avatar
Martin Craig committed
86
87
                           topup,
                           applytopup)
Paul McCarthy's avatar
Paul McCarthy committed
88
from .fast         import (fast,)           # noqa
Martin Craig's avatar
Martin Craig committed
89
from .fsl_anat     import (fsl_anat,)       # noqa
Paul McCarthy's avatar
Paul McCarthy committed
90
91
92
from .flirt        import (flirt,           # noqa
                           invxfm,
                           applyxfm,
Paul McCarthy's avatar
Paul McCarthy committed
93
                           applyxfm4D,
Paul McCarthy's avatar
Paul McCarthy committed
94
95
96
97
98
99
100
                           concatxfm,
                           mcflirt)
from .fnirt        import (fnirt,           # noqa
                           applywarp,
                           invwarp,
                           convertwarp)
from .fslmaths     import (fslmaths,)       # noqa
101
from .fslstats     import (fslstats,)       # noqa
Paul McCarthy's avatar
Paul McCarthy committed
102
from .fugue        import (fugue,           # noqa
Paul McCarthy's avatar
Paul McCarthy committed
103
                           prelude,
104
105
                           sigloss,
                           fsl_prepare_fieldmap)
Paul McCarthy's avatar
Paul McCarthy committed
106
107
108
109
110
from .melodic      import (melodic,         # noqa
                           fsl_regfilt)
from .misc         import (fslreorient2std, # noqa
                           fslroi,
                           slicer,
Michiel Cottaar's avatar
Michiel Cottaar committed
111
112
                           cluster,
                           gps)
113
from .epi_reg      import  epi_reg
114
from .             import  tbss             # noqa