This script, tessellation_tutorial.py, demonstrates the use of create_tessellation_flow from nipype.workflows.smri.freesurfer, and it can be run with:
python tessellation_tutorial.py
This example requires that the user has Freesurfer installed, and that the Freesurfer directory for ‘fsaverage’ is present.
See also
Warning
This workflow will take several hours to finish entirely, since smoothing
the larger cortical surfaces is very time consuming.
Import the necessary modules and workflow from nipype.
Set the default directory and lookup table (LUT) paths
fs_dir = os.environ['FREESURFER_HOME']
lookup_file = op.join(fs_dir,'FreeSurferColorLUT.txt')
subjects_dir = op.join(fs_dir, 'subjects/')
output_dir = './tessellate_tutorial'
Create the tessellation workflow and set inputs
tessflow = create_tessellation_flow(name='tessflow')
tessflow.inputs.inputspec.subject_id = 'fsaverage'
tessflow.inputs.inputspec.subjects_dir = subjects_dir
tessflow.inputs.inputspec.lookup_file = lookup_file
Create a datasink to organize the smoothed meshes Using regular-expression substitutions we can remove the extraneous folders generated by the mapnode.
datasink = pe.Node(interface=nio.DataSink(), name="datasink")
datasink.inputs.base_directory = 'meshes'
datasink.inputs.regexp_substitutions = [('_smoother[\d]*/', '')]
Finally, create and run another pipeline that connects the workflow and datasink
tesspipe = pe.Workflow(name='tessellate_tutorial')
tesspipe.base_dir = output_dir
tesspipe.connect([(tessflow, datasink,[('outputspec.meshes', '@meshes.all')])])
tesspipe.run()
Example source code
You can download the full source code of this example. This same script is also included in the Nipype source distribution under the examples directory.