@@ -25,30 +25,24 @@ setting up a workflow is separate from executing it.
2525
2626**1. Import appropriate modules **
2727
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
3230
3331**2. Define nodes **
3432
3533Here we take instances of interfaces and make them pipeline compatible by
3634wrapping them with pipeline specific elements. To determine the inputs and outputs
3735of 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:
4037
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
4640
4741This would be equivalent to:
4842
4943.. testcode ::
50-
51- realigner = pe.Node(interface=spm.Realign(infile='somefuncrun.nii',
44+
45+ realigner = pe.Node(interface=spm.Realign(infile=os.abspath( 'somefuncrun.nii') ,
5246 register_to_mean = True),
5347 name='realign')
5448
@@ -58,15 +52,17 @@ later or while initializing the interface.
5852
5953.. note ::
6054
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.
6458
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.
6661
67- .. testcode ::
62+ Similar to the realigner node, we now set up a smoothing node.
6863
69- smoother = pe.Node(interface=spm.Smooth(fwhm=6), name='smooth')
64+ .. literalinclude :: tutorial_101.py
65+ :lines: 20
7066
7167Now we have two nodes with their inputs defined. Note that we have not defined
7268an input file for the smoothing node. This will be done by connecting the
@@ -77,17 +73,15 @@ realigner to the smoother in step 5.
7773Here we create an instance of a workflow and indicate that it should operate in
7874the current directory.
7975
80- .. testcode ::
81-
82- workflow = pe.Workflow(name='preproc')
83- workflow.base_dir = '.'
76+ .. literalinclude :: tutorial_101.py
77+ :lines: 25-26
8478
8579**4. Adding nodes to workflows (optional) **
8680
8781If nodes are going to be connected (see step 5), this step is not
8882necessary. However, if you would like to run a node by itself without
8983connecting 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.
9185
9286.. testcode ::
9387
@@ -100,15 +94,14 @@ This results in a workflow containing two isolated nodes:
10094**5. Connecting nodes to each other **
10195
10296We want to connect the output produced by the node realignment to the input of
103- the node smoothing. This is done as follows.
104-
105- .. testcode ::
97+ the node smoothing. This is done as follows:
10698
107- workflow.connect(realigner, 'realigned_files', smoother, 'in_files')
99+ .. literalinclude :: tutorial_101.py
100+ :lines: 31
108101
109-
110- Although not shown here, the following notation can be used to connect multiple outputs from one node to
111- multiple inputs (see step 7 below).
102+ or alternatively, a more flexible notation can be used. Although not shown here,
103+ the following notation can be used to connect multiple outputs from one node to
104+ multiple inputs (see step 7 below):
112105
113106.. testcode ::
114107
@@ -121,8 +114,8 @@ This results in a workflow containing two connected nodes:
121114**6. Visualizing the workflow **
122115
123116The 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):
126119
127120.. testcode ::
128121
@@ -147,18 +140,9 @@ options:
147140Now that you have seen a basic pipeline let's add another node to the
148141above pipeline.
149142
150- .. testcode ::
151143
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- )])
144+ .. literalinclude :: tutorial_101.py
145+ :lines: 42-53
162146
163147.. note ::
164148
@@ -180,14 +164,17 @@ This results in
180164Assuming that **somefuncrun.nii ** is actually a file or you've
181165replaced it with an appropriate one, you can run the pipeline with:
182166
183- .. testcode ::
184-
185- workflow.run()
167+ .. literalinclude :: tutorial_101.py
168+ :lines: 59
186169
187170This should create a folder called preproc in your current directory,
188171inside which are three folders: realign, smooth and artdetect (the names
189172of the nodes). The outputs of these routines are in these folders.
190173
174+ .. admonition :: Example source code
175+
176+ You can download :download: `the source code of this example <tutorial_101.py >`.
177+
191178.. include :: ../links_names.txt
192179
193180.. glossary ::
0 commit comments