Skip to content

Commit eb504c7

Browse files
committed
Merge pull request #577 from satra/enh/tutorial_notebook
fix: updated tutorial to include download of data
2 parents 5469c62 + 7b1d550 commit eb504c7

File tree

1 file changed

+50
-31
lines changed

1 file changed

+50
-31
lines changed

examples/nipype_tutorial.ipynb

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"_draft": {
44
"nbviewer_url": "gisting : nipype.ipynb\r\n"
55
},
6-
"name": "nipype"
6+
"name": "nipype_tutorial"
77
},
88
"nbformat": 3,
99
"nbformat_minor": 0,
@@ -440,7 +440,7 @@
440440
"# Some preliminaries\n",
441441
"import os\n",
442442
"cwd = os.getcwd()\n",
443-
"tutorial_dir = '/software/temp/nipype-tutorial/mgh/'\n",
443+
"tutorial_dir = '/software/temp/nipype-tutorial/ohbm/'\n",
444444
"if not os.path.exists(tutorial_dir):\n",
445445
" os.mkdir(tutorial_dir)\n",
446446
"os.chdir(tutorial_dir)"
@@ -457,18 +457,21 @@
457457
"cell_type": "code",
458458
"collapsed": false,
459459
"input": [
460-
"if not os.path.exists('ds107_raw_0.tgz'):\n",
461-
" os.system('curl -O https://openfmri.org/system/files/ds107_raw_0.tgz')"
462-
],
463-
"language": "python",
464-
"metadata": {},
465-
"outputs": []
466-
},
467-
{
468-
"cell_type": "code",
469-
"collapsed": false,
470-
"input": [
471-
"subjects_dir = '/software/temp/nipype-tutorial/mgh/openfmri/ds107/'"
460+
"import urllib\n",
461+
"required_files = ['ds107/sub001/BOLD/task001_run001/bold.nii.gz',\n",
462+
" 'ds107/sub001/BOLD/task001_run002/bold.nii.gz',\n",
463+
" 'ds107/sub001/anatomy/highres001.nii.gz',\n",
464+
" 'ds107/sub044/BOLD/task001_run001/bold.nii.gz',\n",
465+
" 'ds107/sub044/BOLD/task001_run002/bold.nii.gz',\n",
466+
" 'ds107/sub044/anatomy/highres001.nii.gz'\n",
467+
" ]\n",
468+
"base_url = 'http://openfmri.aws.amazon.com.s3.amazonaws.com/'\n",
469+
"for filepath in required_files:\n",
470+
" file_location = os.path.join(tutorial_dir, filepath)\n",
471+
" if not os.path.exists(file_location):\n",
472+
" print('Retrieving: ' + file_location)\n",
473+
" os.makedirs(os.path.dirname(file_location))\n",
474+
" urllib.urlretrieve(base_url + filepath, file_location)"
472475
],
473476
"language": "python",
474477
"metadata": {},
@@ -1485,15 +1488,25 @@
14851488
"cell_type": "code",
14861489
"collapsed": false,
14871490
"input": [
1488-
"from nipype.workflows.smri.freesurfer.utils import create_getmask_flow\n",
1491+
"config.set_default_config()\n",
1492+
"logging.update_logging(config)"
1493+
],
1494+
"language": "python",
1495+
"metadata": {},
1496+
"outputs": []
1497+
},
1498+
{
1499+
"cell_type": "code",
1500+
"collapsed": false,
1501+
"input": [
1502+
"from nipype.workflows.fmri.fsl.preprocess import create_susan_smooth\n",
14891503
"\n",
1490-
"getmask = create_getmask_flow()\n",
1491-
"getmask.inputs.inputspec.source_file = 'mean.nii'\n",
1492-
"getmask.inputs.inputspec.subject_id = 'sub001'\n",
1493-
"getmask.inputs.inputspec.subjects_dir = subjects_dir\n",
1494-
"getmask.inputs.inputspec.contrast_type = 't2'\n",
1504+
"smooth = create_susan_smooth()\n",
1505+
"smooth.inputs.inputnode.in_files = opap('output/realigned/_subject_id_sub044/rbold_out.nii')\n",
1506+
"smooth.inputs.inputnode.fwhm = 5\n",
1507+
"smooth.inputs.inputnode.mask_file = 'mask.nii'\n",
14951508
"\n",
1496-
"getmask.run() # Will error because mean.nii does not exist"
1509+
"smooth.run() # Will error because mask.nii does not exist"
14971510
],
14981511
"language": "python",
14991512
"metadata": {},
@@ -1503,18 +1516,24 @@
15031516
"cell_type": "code",
15041517
"collapsed": false,
15051518
"input": [
1506-
"from nipype.interfaces.fsl.maths import MeanImage\n",
1519+
"from nipype.interfaces.fsl import BET, MeanImage, ImageMaths\n",
15071520
"from nipype.pipeline.engine import Node\n",
15081521
"\n",
1509-
"mi = Node(MeanImage(), name='mean_image')\n",
1510-
"mi.inputs.in_file = opap('ds107/sub001/BOLD/task001_run001/bold.nii.gz')\n",
1522+
"\n",
1523+
"remove_nan = Node(ImageMaths(op_string= '-nan'), name='nanremove')\n",
1524+
"remove_nan.inputs.in_file = opap('output/realigned/_subject_id_sub044/rbold_out.nii')\n",
1525+
"\n",
1526+
"mi = Node(MeanImage(), name='mean')\n",
1527+
"\n",
1528+
"mask = Node(BET(mask=True), name='mask')\n",
15111529
"\n",
15121530
"wf = Workflow('reuse')\n",
15131531
"wf.base_dir = opap('.')\n",
1514-
"wf.connect(mi, 'out_file', getmask, 'inputspec.source_file')\n",
1532+
"wf.connect(remove_nan, 'out_file', mi, 'in_file')\n",
1533+
"wf.connect(mi, 'out_file', mask, 'in_file')\n",
1534+
"wf.connect(mask, 'out_file', smooth, 'inputnode.mask_file')\n",
1535+
"wf.connect(remove_nan, 'out_file', smooth, 'inputnode.in_files')\n",
15151536
"\n",
1516-
"config.set_default_config()\n",
1517-
"logging.update_logging(config)\n",
15181537
"wf.run()"
15191538
],
15201539
"language": "python",
@@ -1536,10 +1555,10 @@
15361555
"cell_type": "code",
15371556
"collapsed": false,
15381557
"input": [
1539-
"print(getmask.list_node_names())\n",
1540-
"bin_node = getmask.get_node('threshold2')\n",
1541-
"bin_node.inputs.dilate = 3\n",
1542-
"bin_node.inputs.erode = 2"
1558+
"print(smooth.list_node_names())\n",
1559+
"\n",
1560+
"median = smooth.get_node('median')\n",
1561+
"median.inputs.op_string = '-k %s -p 60'"
15431562
],
15441563
"language": "python",
15451564
"metadata": {

0 commit comments

Comments
 (0)