Skip to content

Commit 872cc58

Browse files
committed
Merge pull request #581 from satra/enh/tutorial_notebook
enh: updated tutorial
2 parents b7cb4b2 + 73ad85c commit 872cc58

File tree

1 file changed

+193
-48
lines changed

1 file changed

+193
-48
lines changed

examples/nipype_tutorial.ipynb

Lines changed: 193 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363
"# What is Nipype?\n",
6464
"\n",
6565
"<center>\n",
66-
"<img src=\"https://raw.github.com/satra/intro2nipype/master/images/nipype.png\" width=\"50%\" />\n",
66+
"<img src=\"https://raw.github.com/satra/intro2nipype/master/images/nipype.png\" width=\"40%\" />\n",
6767
"<br>\n",
68-
"created by: Arno Klein (www.mindboggle.info)\n",
68+
"Figure designed and created by: Arno Klein (www.mindboggle.info)\n",
6969
"</center>\n"
7070
]
7171
},
@@ -146,6 +146,35 @@
146146
"- part of an ecosystem"
147147
]
148148
},
149+
{
150+
"cell_type": "markdown",
151+
"metadata": {
152+
"slideshow": {
153+
"slide_type": "subslide"
154+
}
155+
},
156+
"source": [
157+
"# Python ecosystem\n",
158+
"<table width=\"1024px\">\n",
159+
"<tr>\n",
160+
"<td colspan=\"2\"><a href=\"http://ipython.org/\"><img src=\"http://ipython.org/_static/IPy_header.png\"></a></td>\n",
161+
"<td colspan=\"2\"><a href=\"http://nipy.org/\"><img src=\"http://nipy.org/_static/nipy-community-banner-gy.png\"></a></td>\n",
162+
"</tr>\n",
163+
"<tr>\n",
164+
"<td><a href=\"http://scipy.org/\"><img src=\"http://www.scipy.org/_static/images/tutorial.png\"></a></td>\n",
165+
"<td><a href=\"http://numpy.org/\"><img src=\"http://www.numpy.org/_static/numpy_logo.png\"></a></td>\n",
166+
"<td><a href=\"http://pymvpa.org/\"><img src=\"http://www.pymvpa.org/_static/pymvpa_logo.jpg\" width=\"256\"></a></td>\n",
167+
"<td><a href=\"http://scikit-learn.org/\"><img src=\"http://scikit-learn.org/stable/_static/scikit-learn-logo-small.png\"></a></td>\n",
168+
"</tr>\n",
169+
"<tr>\n",
170+
"<td><a href=\"http://networkx.github.io/\"><img src=\"https://raw.github.com/networkx/networkx/master/doc/source/static/art1.png\" width=\"256\"></a></td>\n",
171+
"<td><a href=\"http://matplotlib.org/\"><img src=\"http://matplotlib.org/_static/logo2.png\" width=\"256\"></a></td>\n",
172+
"<td><a href=\"http://code.enthought.com/projects/mayavi/\"><img src=\"http://code.enthought.com/img/mayavi-samp.png\" width=\"256\"></a></td>\n",
173+
"<td><a href=\"http://neuro.debian.net/\"><img src=\"http://neuro.debian.net/_static/button_w200.png\"></a></td>\n",
174+
"</tr>\n",
175+
"</table>\n"
176+
]
177+
},
149178
{
150179
"cell_type": "markdown",
151180
"metadata": {
@@ -219,24 +248,42 @@
219248
"source": [
220249
"#Software interfaces\n",
221250
"\n",
222-
"Currently supported (5-2-2013). `Click here for latest <http://www.mit.edu/~satra/nipype-nightly/documentation.html>`_\n",
223-
"\n",
224-
"- [AFNI](http://afni.nimh.nih.gov/afni)\n",
225-
"- [ANTS](http://www.picsl.upenn.edu/ANTS)\n",
226-
"- [BRAINS](http://www.psychiatry.uiowa.edu/mhcrc/IPLpages/BRAINS.htm)\n",
227-
"- [Camino](http://www.cs.ucl.ac.uk/research/medic/camino)\n",
228-
"- [Camino-TrackVis](http://www.nitrc.org/projects/camino-trackvis)\n",
229-
"- [ConnectomeViewerToolkit](http://www.connectomeviewer.org)\n",
230-
"- [dcm2nii](http://www.cabiatl.com/mricro/mricron/dcm2nii.html)\n",
231-
"- [Diffusion Toolkit](http://www.trackvis.org/dtk)\n",
232-
"- [FreeSurfer](http://freesurfer.net)\n",
233-
"- [FSL](http://www.fmrib.ox.ac.uk/fsl)\n",
234-
"- [MRtrx](http://www.brain.org.au/software/mrtrix/index.html)\n",
235-
"- [Nipy](http://nipy.org/nipy)\n",
236-
"- [Nitime](http://nipy.org/nitime)\n",
237-
"- [PyXNAT](http://github.com/pyxnat)\n",
238-
"- [Slicer](http://www.slicer.org)\n",
239-
"- [SPM](http://www.fil.ion.ucl.ac.uk/spm)\n",
251+
"Currently supported (5-2-2013). [Click here for latest](http://www.mit.edu/~satra/nipype-nightly/documentation.html)\n",
252+
"\n",
253+
"<style>\n",
254+
".rendered_html table{border:0px}\n",
255+
".rendered_html tr{border:0px}\n",
256+
".rendered_html td{border:0px}\n",
257+
"</style>\n",
258+
"\n",
259+
"<table>\n",
260+
"<tr>\n",
261+
"<td>\n",
262+
"<ul>\n",
263+
"<li><a href=\"http://afni.nimh.nih.gov/afni\">AFNI</a></li>\n",
264+
"<li><a href=\"http://www.picsl.upenn.edu/ANTS\">ANTS</a></li>\n",
265+
"<li><a href=\"http://www.psychiatry.uiowa.edu/mhcrc/IPLpages/BRAINS.htm\">BRAINS</a></li>\n",
266+
"<li><a href=\"http://www.cs.ucl.ac.uk/research/medic/camino\">Camino</a></li>\n",
267+
"<li><a href=\"http://www.nitrc.org/projects/camino-trackvis\">Camino-TrackVis</a></li>\n",
268+
"<li><a href=\"http://www.connectomeviewer.org\">ConnectomeViewerToolkit</a></li>\n",
269+
"<li><a href=\"http://www.cabiatl.com/mricro/mricron/dcm2nii.html\">dcm2nii</a></li>\n",
270+
"<li><a href=\"http://www.trackvis.org/dtk\">Diffusion Toolkit</a></li>\n",
271+
"</ul>\n",
272+
"</td>\n",
273+
"<td>\n",
274+
"<ul>\n",
275+
"<li><a href=\"http://freesurfer.net\">FreeSurfer</a></li>\n",
276+
"<li><a href=\"http://www.fmrib.ox.ac.uk/fsl\">FSL</a></li>\n",
277+
"<li><a href=\"http://www.brain.org.au/software/mrtrix/index.html\">MRtrx</a></li>\n",
278+
"<li><a href=\"http://nipy.org/nipy\">Nipy</a></li>\n",
279+
"<li><a href=\"http://nipy.org/nitime\">Nitime</a></li>\n",
280+
"<li><a href=\"http://github.com/pyxnat\">PyXNAT</a></li>\n",
281+
"<li><a href=\"http://www.slicer.org\">Slicer</a></li>\n",
282+
"<li><a href=\"http://www.fil.ion.ucl.ac.uk/spm\">SPM</a></li>\n",
283+
"</ul>\n",
284+
"</td>\n",
285+
"</tr>\n",
286+
"</table>\n",
240287
"\n",
241288
"Most used/contributed policy!\n",
242289
"\n",
@@ -511,7 +558,11 @@
511558
},
512559
{
513560
"cell_type": "markdown",
514-
"metadata": {},
561+
"metadata": {
562+
"slideshow": {
563+
"slide_type": "subslide"
564+
}
565+
},
515566
"source": [
516567
"### Finding interface inputs and outputs and examples"
517568
]
@@ -538,7 +589,11 @@
538589
},
539590
{
540591
"cell_type": "markdown",
541-
"metadata": {},
592+
"metadata": {
593+
"slideshow": {
594+
"slide_type": "subslide"
595+
}
596+
},
542597
"source": [
543598
"### Creating a directory for running interfaces"
544599
]
@@ -593,6 +648,17 @@
593648
"metadata": {},
594649
"outputs": []
595650
},
651+
{
652+
"cell_type": "markdown",
653+
"metadata": {
654+
"slideshow": {
655+
"slide_type": "subslide"
656+
}
657+
},
658+
"source": [
659+
"## Other ways"
660+
]
661+
},
596662
{
597663
"cell_type": "code",
598664
"collapsed": false,
@@ -1173,7 +1239,10 @@
11731239
"\n",
11741240
" 'base_directory/container/parameterization/destloc/filename'\n",
11751241
" \n",
1176-
" destloc = string[[.[@]]string[[.[@]]string]] and\n",
1242+
" destloc = [@]string[[.[@]]string[[.[@]]string]...] and\n",
1243+
" destloc = realigned.@parameters --> 'realigned'\n",
1244+
" destloc = realigned.parameters.@1 --> 'realigned/parameters'\n",
1245+
" destloc = realigned.parameters.@2 --> 'realigned/parameters'\n",
11771246
" filename comes from the input to the connect statement."
11781247
]
11791248
},
@@ -1231,7 +1300,7 @@
12311300
"language": "python",
12321301
"metadata": {
12331302
"slideshow": {
1234-
"slide_type": "subslide"
1303+
"slide_type": "-"
12351304
}
12361305
},
12371306
"outputs": []
@@ -1323,30 +1392,31 @@
13231392
}
13241393
},
13251394
"source": [
1326-
"# Or to other job managers\n",
1395+
"### Or to other job managers\n",
13271396
"\n",
1328-
"```\n",
1329-
" >>> connectedworkflow.run('PBS', plugin_args={'qsub_args': '-q many'})\n",
1330-
" >>> connectedworkflow.run('SGE', plugin_args={'qsub_args': '-q many'})\n",
1331-
" >>> connectedworkflow.run('LSF', plugin_args={'qsub_args': '-q many'})\n",
1332-
" >>> connectedworkflow.run('Condor')\n",
1333-
" >>> connectedworkflow.run('IPython')\n",
1334-
"```\n",
1397+
"- connectedworkflow.run('PBS', plugin_args={'qsub_args': '-q many'})\n",
1398+
"- connectedworkflow.run('SGE', plugin_args={'qsub_args': '-q many'})\n",
1399+
"- connectedworkflow.run('LSF', plugin_args={'qsub_args': '-q many'})\n",
1400+
"- connectedworkflow.run('Condor')\n",
1401+
"- connectedworkflow.run('IPython')\n",
13351402
"\n",
13361403
"### or submit graphs as a whole\n",
13371404
"\n",
1338-
"```\n",
1339-
" >>> connectedworkflow.run('PBSGraph', plugin_args={'qsub_args': '-q many'})\n",
1340-
" >>> connectedworkflow.run('SGEGraph', plugin_args={'qsub_args': '-q many'})\n",
1341-
" >>> connectedworkflow.run('CondorDAGMan')\n",
1342-
"```\n",
13431405
"\n",
1344-
"### Current Requirement: **shared filesystem**\n"
1406+
"- connectedworkflow.run('PBSGraph', plugin_args={'qsub_args': '-q many'})\n",
1407+
"- connectedworkflow.run('SGEGraph', plugin_args={'qsub_args': '-q many'})\n",
1408+
"- connectedworkflow.run('CondorDAGMan')\n",
1409+
"\n",
1410+
"### Current Requirement: **SHARED FILESYSTEM**"
13451411
]
13461412
},
13471413
{
13481414
"cell_type": "markdown",
1349-
"metadata": {},
1415+
"metadata": {
1416+
"slideshow": {
1417+
"slide_type": "subslide"
1418+
}
1419+
},
13501420
"source": [
13511421
"### You can also set node specific plugin arguments"
13521422
]
@@ -1355,9 +1425,8 @@
13551425
"cell_type": "markdown",
13561426
"metadata": {},
13571427
"source": [
1358-
"```\n",
1359-
" >>> node.plugin_args = {'qsub_args': '-l nodes=1:ppn=3', 'overwrite': True}\n",
1360-
"```"
1428+
"\n",
1429+
"- node.plugin_args = {'qsub_args': '-l nodes=1:ppn=3', 'overwrite': True}\n"
13611430
]
13621431
},
13631432
{
@@ -1375,30 +1444,70 @@
13751444
"cell_type": "code",
13761445
"collapsed": false,
13771446
"input": [
1447+
"from os.path import abspath as opap\n",
1448+
"\n",
13781449
"from nipype.interfaces.io import XNATSource\n",
13791450
"from nipype.pipeline.engine import Node, Workflow\n",
13801451
"from nipype.interfaces.fsl import BET\n",
13811452
"\n",
1453+
"subject_id = 'xnat_S00001'\n",
1454+
"\n",
13821455
"dg = Node(XNATSource(infields=['subject_id'],\n",
13831456
" outfields=['struct'],\n",
13841457
" config='/Users/satra/xnat_configs/nitrc_ir_config'),\n",
13851458
" name='xnatsource')\n",
13861459
"dg.inputs.query_template = ('/projects/fcon_1000/subjects/%s/experiments/xnat_E00001'\n",
13871460
" '/scans/%s/resources/NIfTI/files')\n",
13881461
"dg.inputs.query_template_args['struct'] = [['subject_id', 'anat_mprage_anonymized']]\n",
1389-
"dg.inputs.subject_id = 'xnat_S00001'\n",
1462+
"dg.inputs.subject_id = subject_id\n",
13901463
"\n",
13911464
"bet = Node(BET(), name='skull_stripper')\n",
13921465
"\n",
13931466
"wf = Workflow(name='testxnat')\n",
13941467
"wf.base_dir = opap('xnattest')\n",
1395-
"wf.connect(dg, 'struct', bet, 'in_file')\n",
1396-
"wf.run()"
1468+
"wf.connect(dg, 'struct', bet, 'in_file')"
13971469
],
13981470
"language": "python",
13991471
"metadata": {},
14001472
"outputs": []
14011473
},
1474+
{
1475+
"cell_type": "code",
1476+
"collapsed": false,
1477+
"input": [
1478+
"from nipype.interfaces.io import XNATSink\n",
1479+
"\n",
1480+
"ds = Node(XNATSink(config='/Users/satra/xnat_configs/central_config'),\n",
1481+
" name='xnatsink')\n",
1482+
"ds.inputs.project_id = 'NPTEST'\n",
1483+
"ds.inputs.subject_id = 'NPTEST_xnat_S00001'\n",
1484+
"ds.inputs.experiment_id = 'test_xnat'\n",
1485+
"ds.inputs.reconstruction_id = 'bet'\n",
1486+
"ds.inputs.share = True\n",
1487+
"wf.connect(bet, 'out_file', ds, 'brain')"
1488+
],
1489+
"language": "python",
1490+
"metadata": {
1491+
"slideshow": {
1492+
"slide_type": "skip"
1493+
}
1494+
},
1495+
"outputs": []
1496+
},
1497+
{
1498+
"cell_type": "code",
1499+
"collapsed": false,
1500+
"input": [
1501+
"wf.run()"
1502+
],
1503+
"language": "python",
1504+
"metadata": {
1505+
"slideshow": {
1506+
"slide_type": "subslide"
1507+
}
1508+
},
1509+
"outputs": []
1510+
},
14021511
{
14031512
"cell_type": "markdown",
14041513
"metadata": {
@@ -1448,7 +1557,11 @@
14481557
},
14491558
{
14501559
"cell_type": "markdown",
1451-
"metadata": {},
1560+
"metadata": {
1561+
"slideshow": {
1562+
"slide_type": "subslide"
1563+
}
1564+
},
14521565
"source": [
14531566
"Configurations can also be set at the node level."
14541567
]
@@ -1537,7 +1650,11 @@
15371650
"wf.run()"
15381651
],
15391652
"language": "python",
1540-
"metadata": {},
1653+
"metadata": {
1654+
"slideshow": {
1655+
"slide_type": "subslide"
1656+
}
1657+
},
15411658
"outputs": []
15421659
},
15431660
{
@@ -1578,6 +1695,34 @@
15781695
"metadata": {},
15791696
"outputs": []
15801697
},
1698+
{
1699+
"cell_type": "markdown",
1700+
"metadata": {
1701+
"slideshow": {
1702+
"slide_type": "slide"
1703+
}
1704+
},
1705+
"source": [
1706+
"# Summary\n",
1707+
"\n",
1708+
"\n",
1709+
"- This tutorial covers the concepts of Nipype\n",
1710+
"\n",
1711+
" 1. Installing and testing the installation \n",
1712+
" 2. Working with interfaces\n",
1713+
" 3. Using Nipype caching\n",
1714+
" 4. Creating Nodes, MapNodes and Workflows\n",
1715+
" 5. Getting and saving data\n",
1716+
" 6. Using Iterables\n",
1717+
" 7. Function nodes\n",
1718+
" 8. Distributed computation\n",
1719+
" 9. Connecting to databases\n",
1720+
" 10. Execution configuration options\n",
1721+
"\n",
1722+
"- It will allow you to reuse and debug the various workflows available in Nipype, BIPS and CPAC\n",
1723+
"- Please contribute new interfaces and workflows!"
1724+
]
1725+
},
15811726
{
15821727
"cell_type": "code",
15831728
"collapsed": false,
@@ -1599,4 +1744,4 @@
15991744
"metadata": {}
16001745
}
16011746
]
1602-
}
1747+
}

0 commit comments

Comments
 (0)