4
4
Tutorial : Interfaces
5
5
=======================
6
6
7
- Specifying options
8
- ------------------
7
+ Specifying input settings
8
+ -------------------------
9
9
10
10
The nipype interface modules provide a Python interface to external
11
11
packages like FSL _ and SPM _. Within the module are a series of Python
12
12
classes which wrap specific package functionality. For example, in
13
13
the fsl module, the class :class: `nipype.interfaces.fsl.Bet ` wraps the
14
14
``bet `` command-line tool. Using the command-line tool, one would
15
- specify options using flags like ``-o ``, ``-m ``, ``-f <f> ``, etc...
15
+ specify input settings using flags like ``-o ``, ``-m ``, ``-f <f> ``, etc...
16
16
However, in nipype, options are assigned to Python attributes and can
17
17
be specified in the following ways:
18
18
19
- Options can be assigned when you first create an interface object:
19
+ Settings can be assigned when you first create an interface object:
20
20
21
21
.. testcode ::
22
22
23
23
import nipype.interfaces.fsl as fsl
24
24
mybet = fsl.BET(in_file='foo.nii', out_file='bar.nii')
25
25
result = mybet.run()
26
26
27
- Options can be assigned through the ``inputs `` attribute:
27
+ Settings can be assigned through the ``inputs `` attribute:
28
28
29
29
.. testcode ::
30
30
@@ -34,14 +34,53 @@ Options can be assigned through the ``inputs`` attribute:
34
34
mybet.inputs.out_file = 'bar.nii'
35
35
result = mybet.run()
36
36
37
- Options can be assigned when calling the ``run `` method:
37
+ Settings can be assigned when calling the ``run `` method:
38
38
39
39
.. testcode ::
40
40
41
41
import nipype.interfaces.fsl as fsl
42
42
mybet = fsl.BET()
43
43
result = mybet.run(in_file='foo.nii', out_file='bar.nii', frac=0.5)
44
44
45
+ Settings can be saved to a json file:
46
+
47
+ .. testcode ::
48
+
49
+ import nipype.interfaces.fsl as fsl
50
+ mybet = fsl.BET(in_file='foo.nii', out_file='bar.nii', frac=0.5)
51
+ mybet.save_inputs_to_json('bet-settings.json')
52
+
53
+ Once saved, the three inputs set for `mybet ` will be stored in a JSON
54
+ file. These settings can also be loaded from a json file:
55
+
56
+ .. testcode ::
57
+
58
+ import nipype.interfaces.fsl as fsl
59
+ mybet = fsl.BET()
60
+ mybet.load_inputs_from_json('bet-settings.json', overwrite=False)
61
+
62
+
63
+ Loading settings will overwrite previously set inputs by default, unless
64
+ the `overwrite ` argument is `False `. Conveniently, the settings can be
65
+ also read during the interface instantiation:
66
+
67
+ .. testcode ::
68
+
69
+ import nipype.interfaces.fsl as fsl
70
+ mybet = fsl.BET(from_file='bet-settings.json')
71
+
72
+ If the user provides settings during interface creation, they will take
73
+ precedence over those loaded using `from_file `:
74
+
75
+ .. testcode ::
76
+
77
+ import nipype.interfaces.fsl as fsl
78
+ mybet = fsl.BET(from_file='bet-settings.json', frac=0.7)
79
+
80
+ In this case, `mybet.inputs.frac ` will contain the value `0.7 ` regardless
81
+ the value that could be stored in the `bet-settings.json ` file.
82
+
83
+
45
84
Getting Help
46
85
------------
47
86
0 commit comments