Skip to content

Commit eaf4953

Browse files
authored
Merge pull request #2871 from mgxd/enh/ciftismooth
enh: wb cifti-smoothing
2 parents 5a689fc + efdbc71 commit eaf4953

6 files changed

+239
-0
lines changed

nipype/interfaces/workbench/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
# vi: set ft=python sts=4 ts=4 sw=4 et:
44

55
from .metric import MetricResample
6+
from .cifti import CiftiSmooth

nipype/interfaces/workbench/cifti.py

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# -*- coding: utf-8 -*-
2+
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
3+
# vi: set ft=python sts=4 ts=4 sw=4 et:
4+
"""This module provides interfaces for workbench CIFTI commands"""
5+
from __future__ import (print_function, division, unicode_literals,
6+
absolute_import)
7+
8+
from ..base import (TraitedSpec, File, traits, CommandLineInputSpec)
9+
from .base import WBCommand
10+
from ... import logging
11+
12+
iflogger = logging.getLogger('nipype.interface')
13+
14+
15+
class CiftiSmoothInputSpec(CommandLineInputSpec):
16+
in_file = File(
17+
exists=True,
18+
mandatory=True,
19+
argstr="%s",
20+
position=0,
21+
desc="The input CIFTI file")
22+
sigma_surf = traits.Float(
23+
mandatory=True,
24+
argstr="%s",
25+
position=1,
26+
desc="the sigma for the gaussian surface smoothing kernel, in mm")
27+
sigma_vol = traits.Float(
28+
mandatory=True,
29+
argstr="%s",
30+
position=2,
31+
desc="the sigma for the gaussian volume smoothing kernel, in mm")
32+
direction = traits.Enum(
33+
"ROW",
34+
"COLUMN",
35+
mandatory=True,
36+
argstr="%s",
37+
position=3,
38+
desc="which dimension to smooth along, ROW or COLUMN")
39+
out_file = File(
40+
name_source=["in_file"],
41+
name_template="smoothed_%s.nii",
42+
keep_extension=True,
43+
argstr="%s",
44+
position=4,
45+
desc="The output CIFTI")
46+
left_surf = File(
47+
exists=True,
48+
mandatory=True,
49+
position=5,
50+
argstr="-left-surface %s",
51+
desc="Specify the left surface to use")
52+
left_corrected_areas = File(
53+
exists=True,
54+
position=6,
55+
argstr="-left-corrected-areas %s",
56+
desc="vertex areas (as a metric) to use instead of computing them from "
57+
"the left surface.")
58+
right_surf = File(
59+
exists=True,
60+
mandatory=True,
61+
position=7,
62+
argstr="-right-surface %s",
63+
desc="Specify the right surface to use")
64+
right_corrected_areas = File(
65+
exists=True,
66+
position=8,
67+
argstr="-right-corrected-areas %s",
68+
desc="vertex areas (as a metric) to use instead of computing them from "
69+
"the right surface")
70+
cerebellum_surf = File(
71+
exists=True,
72+
position=9,
73+
argstr="-cerebellum-surface %s",
74+
desc="specify the cerebellum surface to use")
75+
cerebellum_corrected_areas = File(
76+
exists=True,
77+
position=10,
78+
requires=["cerebellum_surf"],
79+
argstr="cerebellum-corrected-areas %s",
80+
desc="vertex areas (as a metric) to use instead of computing them from "
81+
"the cerebellum surface")
82+
cifti_roi = File(
83+
exists=True,
84+
position=11,
85+
argstr="-cifti-roi %s",
86+
desc="CIFTI file for ROI smoothing")
87+
fix_zeros_vol = traits.Bool(
88+
position=12,
89+
argstr="-fix-zeros-volume",
90+
desc="treat values of zero in the volume as missing data")
91+
fix_zeros_surf = traits.Bool(
92+
position=13,
93+
argstr="-fix-zeros-surface",
94+
desc="treat values of zero on the surface as missing data")
95+
merged_volume = traits.Bool(
96+
position=14,
97+
argstr="-merged-volume",
98+
desc="smooth across subcortical structure boundaries")
99+
100+
101+
class CiftiSmoothOutputSpec(TraitedSpec):
102+
out_file = File(exists=True, desc="output CIFTI file")
103+
104+
105+
class CiftiSmooth(WBCommand):
106+
"""
107+
Smooth a CIFTI file
108+
109+
The input cifti file must have a brain models mapping on the chosen
110+
dimension, columns for .dtseries, and either for .dconn. By default,
111+
data in different structures is smoothed independently (i.e., "parcel
112+
constrained" smoothing), so volume structures that touch do not smooth
113+
across this boundary. Specify ``merged_volume`` to ignore these
114+
boundaries. Surface smoothing uses the ``GEO_GAUSS_AREA`` smoothing method.
115+
116+
The ``*_corrected_areas`` options are intended for when it is unavoidable
117+
to smooth on group average surfaces, it is only an approximate correction
118+
for the reduction of structure in a group average surface. It is better
119+
to smooth the data on individuals before averaging, when feasible.
120+
121+
The ``fix_zeros_*`` options will treat values of zero as lack of data, and
122+
not use that value when generating the smoothed values, but will fill
123+
zeros with extrapolated values. The ROI should have a brain models
124+
mapping along columns, exactly matching the mapping of the chosen
125+
direction in the input file. Data outside the ROI is ignored.
126+
127+
>>> from nipype.interfaces.workbench import CiftiSmooth
128+
>>> smooth = CiftiSmooth()
129+
>>> smooth.inputs.in_file = 'sub-01_task-rest.dtseries.nii'
130+
>>> smooth.inputs.sigma_surf = 4
131+
>>> smooth.inputs.sigma_vol = 4
132+
>>> smooth.inputs.direction = 'COLUMN'
133+
>>> smooth.inputs.right_surf = 'sub-01.R.midthickness.32k_fs_LR.surf.gii'
134+
>>> smooth.inputs.left_surf = 'sub-01.L.midthickness.32k_fs_LR.surf.gii'
135+
>>> smooth.cmdline
136+
'wb_command -cifti-smoothing sub-01_task-rest.dtseries.nii 4.0 4.0 COLUMN \
137+
smoothed_sub-01_task-rest.dtseries.nii \
138+
-left-surface sub-01.L.midthickness.32k_fs_LR.surf.gii \
139+
-right-surface sub-01.R.midthickness.32k_fs_LR.surf.gii'
140+
"""
141+
input_spec = CiftiSmoothInputSpec
142+
output_spec = CiftiSmoothOutputSpec
143+
_cmd = 'wb_command -cifti-smoothing'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..cifti import CiftiSmooth
4+
5+
6+
def test_CiftiSmooth_inputs():
7+
input_map = dict(
8+
args=dict(argstr='%s', ),
9+
cerebellum_corrected_areas=dict(
10+
argstr='cerebellum-corrected-areas %s',
11+
position=10,
12+
requires=['cerebellum_surf'],
13+
),
14+
cerebellum_surf=dict(
15+
argstr='-cerebellum-surface %s',
16+
position=9,
17+
),
18+
cifti_roi=dict(
19+
argstr='-cifti-roi %s',
20+
position=11,
21+
),
22+
direction=dict(
23+
argstr='%s',
24+
mandatory=True,
25+
position=3,
26+
),
27+
environ=dict(
28+
nohash=True,
29+
usedefault=True,
30+
),
31+
fix_zeros_surf=dict(
32+
argstr='-fix-zeros-surface',
33+
position=13,
34+
),
35+
fix_zeros_vol=dict(
36+
argstr='-fix-zeros-volume',
37+
position=12,
38+
),
39+
in_file=dict(
40+
argstr='%s',
41+
mandatory=True,
42+
position=0,
43+
),
44+
left_corrected_areas=dict(
45+
argstr='-left-corrected-areas %s',
46+
position=6,
47+
),
48+
left_surf=dict(
49+
argstr='-left-surface %s',
50+
mandatory=True,
51+
position=5,
52+
),
53+
merged_volume=dict(
54+
argstr='-merged-volume',
55+
position=14,
56+
),
57+
out_file=dict(
58+
argstr='%s',
59+
keep_extension=True,
60+
name_source=['in_file'],
61+
name_template='smoothed_%s.nii',
62+
position=4,
63+
),
64+
right_corrected_areas=dict(
65+
argstr='-right-corrected-areas %s',
66+
position=8,
67+
),
68+
right_surf=dict(
69+
argstr='-right-surface %s',
70+
mandatory=True,
71+
position=7,
72+
),
73+
sigma_surf=dict(
74+
argstr='%s',
75+
mandatory=True,
76+
position=1,
77+
),
78+
sigma_vol=dict(
79+
argstr='%s',
80+
mandatory=True,
81+
position=2,
82+
),
83+
)
84+
inputs = CiftiSmooth.input_spec()
85+
86+
for key, metadata in list(input_map.items()):
87+
for metakey, value in list(metadata.items()):
88+
assert getattr(inputs.traits()[key], metakey) == value
89+
def test_CiftiSmooth_outputs():
90+
output_map = dict(out_file=dict(), )
91+
outputs = CiftiSmooth.output_spec()
92+
93+
for key, metadata in list(output_map.items()):
94+
for metakey, value in list(metadata.items()):
95+
assert getattr(outputs.traits()[key], metakey) == value

nipype/testing/data/sub-01.L.midthickness.32k_fs_LR.surf.gii

Whitespace-only changes.

nipype/testing/data/sub-01.R.midthickness.32k_fs_LR.surf.gii

Whitespace-only changes.

nipype/testing/data/sub-01_task-rest.dtseries.nii

Whitespace-only changes.

0 commit comments

Comments
 (0)