__init__.py 4.34 KB
Newer Older
1
2
#!/usr/bin/env python
#
Paul McCarthy's avatar
Paul McCarthy committed
3
4
5
# pylint: disable=unused-import
# flake8: noqa: F401
#
6
7
8
9
10
11
# __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
12
13


14
15
16
17
18
For example, you can call BET like so::

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

19
20
21
22
23
24
25
26
27
28
29
30
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.

31
32
33
34
35

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
36
37
38
39
40
41
42


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``).


43
44
Two exceptions to the above are :class:`.fslmaths` and :class:`.fslstats`,
which provide a more object-oriented interface::
45

Paul McCarthy's avatar
Paul McCarthy committed
46
47
    from fsl.wrappers import fslmaths, fslstats

48
49
    fslmaths('image.nii').mas('mask.nii').bin().run('output.nii')

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

52

Paul McCarthy's avatar
Paul McCarthy committed
53
54
55
56
57
58
59
60
61
62
63
64
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')
65
66
67
68
69
70
71
    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
72
    from fsl.wrappers import fslmaths
73
74
75

    image  = nib.load('image.nii')
    mask   = nib.load('mask.nii')
76
    output = fslmaths(image).mas(mask).bin().run()
Paul McCarthy's avatar
Paul McCarthy committed
77
78


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

Paul McCarthy's avatar
Paul McCarthy committed
84

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