Skip to content

Commit 6c7383a

Browse files
author
Erik Ziegler
committed
MRIsSmooth is now SmoothTessellation. Tessellation example added
1 parent 316d399 commit 6c7383a

File tree

4 files changed

+94
-8
lines changed

4 files changed

+94
-8
lines changed

examples/tessellation_tutorial.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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()

nipype/interfaces/freesurfer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
SegStats, Label2Vol)
1212
from .utils import (SampleToSurface, SurfaceSmooth, SurfaceTransform,
1313
SurfaceSnapshots,ApplyMask, MRIsConvert, MRITessellate,
14-
MRIMarchingCubes, MRIsSmooth)
14+
MRIMarchingCubes, SmoothTessellation)

nipype/interfaces/freesurfer/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ def _gen_outfilename(self):
894894
_, name, ext = split_filename(self.inputs.in_file)
895895
return name + ext + '_' + str(self.inputs.label_value)
896896

897-
class MRIsSmoothInputSpec(FSTraitedSpec):
897+
class SmoothTessellationInputSpec(FSTraitedSpec):
898898
"""
899899
This program smooths the tessellation of a surface using 'mris_smooth'
900900
"""
@@ -917,14 +917,14 @@ class MRIsSmoothInputSpec(FSTraitedSpec):
917917
out_curvature_file = File(argstr='-c ./%s', desc='Write curvature to ?h.curvname (default "curv")')
918918
out_area_file = File(argstr='-b ./%s', desc='Write area to ?h.areaname (default "area")')
919919

920-
class MRIsSmoothOutputSpec(TraitedSpec):
920+
class SmoothTessellationOutputSpec(TraitedSpec):
921921
"""
922922
This program smooths the tessellation of a surface using 'mris_smooth'
923923
"""
924924
surface = File(exists=True, desc='Smoothed surface file ')
925925

926926

927-
class MRIsSmooth(FSCommand):
927+
class SmoothTessellation(FSCommand):
928928
"""
929929
This program smooths the tessellation of a surface using 'mris_smooth'
930930
@@ -936,13 +936,13 @@ class MRIsSmooth(FSCommand):
936936
Example:
937937
938938
import nipype.interfaces.freesurfer as fs
939-
smooth = fs.MRIsSmooth()
939+
smooth = fs.SmoothTessellation()
940940
smooth.inputs.in_file = 'lh.hippocampus.stl'
941941
smooth.run() # doctest: +SKIP
942942
"""
943943
_cmd = 'mris_smooth'
944-
input_spec = MRIsSmoothInputSpec
945-
output_spec = MRIsSmoothOutputSpec
944+
input_spec = SmoothTessellationInputSpec
945+
output_spec = SmoothTessellationOutputSpec
946946

947947
def _list_outputs(self):
948948
outputs = self.output_spec().get()

nipype/workflows/smri/freesurfer/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def create_tessellation_flow(name='tessellate', out_format='stl'):
313313
surfconvert = pe.MapNode(fs.MRIsConvert(out_datatype=out_format),
314314
iterfield=['in_file'],
315315
name='surfconvert')
316-
smoother = pe.MapNode(fs.MRIsSmooth(),
316+
smoother = pe.MapNode(fs.SmoothTessellation(),
317317
iterfield=['in_file'],
318318
name='smoother')
319319

0 commit comments

Comments
 (0)