@@ -25,30 +25,24 @@ setting up a workflow is separate from executing it.
25
25
26
26
**1. Import appropriate modules **
27
27
28
- .. testcode ::
29
-
30
- import nipype.interfaces.spm as spm # the spm interfaces
31
- import nipype.pipeline.engine as pe # the workflow and node wrappers
28
+ .. literalinclude :: tutorial_101.py
29
+ :lines: 2-4
32
30
33
31
**2. Define nodes **
34
32
35
33
Here we take instances of interfaces and make them pipeline compatible by
36
34
wrapping them with pipeline specific elements. To determine the inputs and outputs
37
35
of a given interface, please see :ref: `interface_tutorial `. Let's
38
- start with defining a realign node using the interface
39
- :class: `nipype.interfaces.spm.Realign `
36
+ start with defining a realign node using the :ref: `Realign <nipype.interfaces.spm.Realign >` interface:
40
37
41
- .. testcode ::
42
-
43
- realigner = pe.Node(interface=spm.Realign(), name='realign')
44
- realigner.inputs.in_files = 'somefuncrun.nii'
45
- realigner.inputs.register_to_mean = True
38
+ .. literalinclude :: tutorial_101.py
39
+ :lines: 16-18
46
40
47
41
This would be equivalent to:
48
42
49
43
.. testcode ::
50
44
51
- realigner = pe.Node(interface=spm.Realign(infile='somefuncrun.nii',
45
+ realigner = pe.Node(interface=spm.Realign(infile=os.abspath( 'somefuncrun.nii') ,
52
46
register_to_mean = True),
53
47
name='realign')
54
48
@@ -58,15 +52,17 @@ later or while initializing the interface.
58
52
59
53
.. note ::
60
54
61
- In the above example, 'somefuncrun.nii' has to exist, otherwise the
62
- commands won't work. A node will check if appropriate inputs are
63
- being supplied.
55
+ a) In the above example, 'somefuncrun.nii' has to exist in the current directory,
56
+ otherwise the commands won't work. A node will check if appropriate
57
+ inputs are being supplied.
64
58
65
- Similar to the realigner node, we now set up a smoothing node.
59
+ b) As noted above, you have to use the absolute path
60
+ of the file otherwise the workflow will fail to run.
66
61
67
- .. testcode ::
62
+ Similar to the realigner node, we now set up a smoothing node.
68
63
69
- smoother = pe.Node(interface=spm.Smooth(fwhm=6), name='smooth')
64
+ .. literalinclude :: tutorial_101.py
65
+ :lines: 20
70
66
71
67
Now we have two nodes with their inputs defined. Note that we have not defined
72
68
an input file for the smoothing node. This will be done by connecting the
@@ -77,17 +73,15 @@ realigner to the smoother in step 5.
77
73
Here we create an instance of a workflow and indicate that it should operate in
78
74
the current directory.
79
75
80
- .. testcode ::
81
-
82
- workflow = pe.Workflow(name='preproc')
83
- workflow.base_dir = '.'
76
+ .. literalinclude :: tutorial_101.py
77
+ :lines: 25-26
84
78
85
79
**4. Adding nodes to workflows (optional) **
86
80
87
81
If nodes are going to be connected (see step 5), this step is not
88
82
necessary. However, if you would like to run a node by itself without
89
83
connecting it to any other node, then you need to add it to the
90
- workflow. For adding nodes, order of nodes is not important.
84
+ workflow. When adding nodes, the order is not important.
91
85
92
86
.. testcode ::
93
87
@@ -100,15 +94,14 @@ This results in a workflow containing two isolated nodes:
100
94
**5. Connecting nodes to each other **
101
95
102
96
We want to connect the output produced by realignment to the input of
103
- smoothing. This is done as follows.
97
+ smoothing. This is done as follows:
104
98
105
- .. testcode ::
106
-
107
- workflow.connect(realigner, 'realigned_files', smoother, 'in_files')
99
+ .. literalinclude :: tutorial_101.py
100
+ :lines: 31
108
101
109
102
or alternatively, a more flexible notation can be used. Although not shown here,
110
103
the following notation can be used to connect multiple outputs from one node to
111
- multiple inputs (see step 7 below).
104
+ multiple inputs (see step 7 below):
112
105
113
106
.. testcode ::
114
107
@@ -121,8 +114,8 @@ This results in a workflow containing two connected nodes:
121
114
**6. Visualizing the workflow **
122
115
123
116
The workflow is represented as a directed acyclic graph (DAG) and one
124
- can visualize this using the following command. In fact, the pictures
125
- above were generated using this.
117
+ can visualize this using the following command (in fact, the pictures
118
+ above were generated using this):
126
119
127
120
.. testcode ::
128
121
@@ -147,18 +140,9 @@ options:
147
140
Now that you have seen a basic pipeline let's add another node to the
148
141
above pipeline.
149
142
150
- .. testcode ::
151
-
152
- import nipype.algorithms.rapidart as ra
153
- artdetect = pe.Node(interface=ra.ArtifactDetect(), name='artdetect')
154
- artdetect.inputs.use_differences = [True, False]
155
- art.inputs.use_norm = True
156
- art.inputs.norm_threshold = 0.5
157
- art.inputs.zintensity_threshold = 3
158
- workflow.connect([(realigner, artdetect,
159
- [('realigned_files', 'realigned_files'),
160
- ('realignment_parameters','realignment_parameters')]
161
- )])
143
+
144
+ .. literalinclude :: tutorial_101.py
145
+ :lines: 42-53
162
146
163
147
.. note ::
164
148
@@ -180,12 +164,15 @@ This results in
180
164
Assuming that **somefuncrun.nii ** is actually a file or you've
181
165
replaced it with an appropriate one, you can run the pipeline with:
182
166
183
- .. testcode ::
184
-
185
- workflow.run()
167
+ .. literalinclude :: tutorial_101.py
168
+ :lines: 59
186
169
187
170
This should create a folder called preproc in your current directory,
188
171
inside which are three folders: realign, smooth and artdetect (the names
189
172
of the nodes). The outputs of these routines are in these folders.
190
173
174
+ .. admonition :: Example source code
175
+
176
+ You can download :download: `the source code of this example <tutorial_101.py >`.
177
+
191
178
.. include :: ../links_names.txt
0 commit comments