|
| 1 | +#!/usr/bin/env python |
| 2 | +""" |
| 3 | +============================================= |
| 4 | +sMRI: Regional Tessellation and Surface Smoothing |
| 5 | +============================================= |
| 6 | +
|
| 7 | +Introduction |
| 8 | +============ |
| 9 | +
|
| 10 | +This script, tessellation_tutorial.py, demonstrates the use of create_tessellation_flow from nipype.workflows.smri.freesurfer, and it can be run with: |
| 11 | +
|
| 12 | + python tessellation_tutorial.py |
| 13 | +
|
| 14 | +This example requires that the user has Freesurfer installed, and that the Freesurfer directory for 'fsaverage' is present. |
| 15 | +
|
| 16 | +.. seealso:: |
| 17 | +
|
| 18 | +ConnectomeViewer |
| 19 | +The Connectome Viewer connects Multi-Modal Multi-Scale Neuroimaging and Network Datasets For Analysis and Visualization in Python. |
| 20 | +
|
| 21 | +http://www.geuz.org/gmsh/ |
| 22 | +Gmsh: a three-dimensional finite element mesh generator with built-in pre- and post-processing facilities |
| 23 | +
|
| 24 | +http://www.blender.org/ |
| 25 | +Blender is the free open source 3D content creation suite, available for all major operating systems under the GNU General Public License. |
| 26 | +
|
| 27 | +.. warning:: |
| 28 | +
|
| 29 | +This workflow will take several hours to finish entirely, since smoothing |
| 30 | + the larger cortical surfaces is very time consuming. |
| 31 | +
|
| 32 | +Packages and Data Setup |
| 33 | +======================= |
| 34 | +
|
| 35 | +Import the necessary modules and workflow from nipype. |
| 36 | +""" |
| 37 | +import nipype.pipeline.engine as pe # pypeline engine |
| 38 | +import nipype.interfaces.io as nio # Data i/o |
| 39 | +import os, os.path as op |
| 40 | +from nipype.workflows.smri.freesurfer import create_tessellation_flow |
| 41 | + |
| 42 | +""" |
| 43 | +Directories |
| 44 | +=========== |
| 45 | +
|
| 46 | +Set the default directory and lookup table (LUT) paths |
| 47 | +""" |
| 48 | + |
| 49 | +fs_dir = os.environ['FREESURFER_HOME'] |
| 50 | +lookup_file = op.join(fs_dir,'FreeSurferColorLUT.txt') |
| 51 | +subjects_dir = op.join(fs_dir, 'subjects/') |
| 52 | +output_dir = './tessellate_tutorial' |
| 53 | + |
| 54 | +""" |
| 55 | +Inputs |
| 56 | +====== |
| 57 | +
|
| 58 | +Create the tessellation workflow and set inputs |
| 59 | +""" |
| 60 | + |
| 61 | +tessflow = create_tessellation_flow(name='tessflow') |
| 62 | +tessflow.inputs.inputspec.subject_id = 'fsaverage' |
| 63 | +tessflow.inputs.inputspec.subjects_dir = subjects_dir |
| 64 | +tessflow.inputs.inputspec.lookup_file = lookup_file |
| 65 | + |
| 66 | +""" |
| 67 | +Outputs |
| 68 | +======= |
| 69 | +
|
| 70 | +Create a datasink to organize the smoothed meshes |
| 71 | +""" |
| 72 | + |
| 73 | +datasink = pe.Node(interface=nio.DataSink(), name="datasink") |
| 74 | +datasink.inputs.base_directory = 'meshes' |
| 75 | + |
| 76 | +""" |
| 77 | +Execution |
| 78 | +========= |
| 79 | +
|
| 80 | +Finally, create and run another pipeline that connects the workflow and datasink |
| 81 | +""" |
| 82 | + |
| 83 | +tesspipe = pe.Workflow(name='tessellate_tutorial') |
| 84 | +tesspipe.base_dir = output_dir |
| 85 | +tesspipe.connect([(tessflow, datasink,[('outputspec.meshes', '@meshes.all')])]) |
| 86 | +tesspipe.run() |
0 commit comments