Skip to content

ENH: add interface for AFNI 3dTsmooth #2948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nipype/interfaces/afni/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
BlurInMask, BlurToFWHM, ClipLevel, DegreeCentrality, Despike, Detrend, ECM,
Fim, Fourier, Hist, LFCD, Maskave, Means, OutlierCount, QualityIndex,
ROIStats, Retroicor, Seg, SkullStrip, TCorr1D, TCorrMap, TCorrelate, TNorm,
TProject, TShift, Volreg, Warp, QwarpPlusMinus, Qwarp)
TProject, TShift, TSmooth, Volreg, Warp, QwarpPlusMinus, Qwarp)
from .svm import (SVMTest, SVMTrain)
from .utils import (
ABoverlap, AFNItoNIFTI, Autobox, Axialize, BrickStat, Bucket, Calc, Cat,
Expand Down
73 changes: 73 additions & 0 deletions nipype/interfaces/afni/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -2853,6 +2853,79 @@ def _list_outputs(self):
return outputs


class TSmoothInputSpec(AFNICommandInputSpec):
in_file = File(
desc='input file to 3dTSmooth',
argstr='%s',
position=-1,
mandatory=True,
exists=True,
copyfile=False)
out_file = File(
name_template='%s_smooth',
desc='output file from 3dTSmooth',
argstr='-prefix %s',
name_source='in_file')
datum = traits.Str(
desc='Sets the data type of the output dataset',
argstr='-datum %s')
lin = traits.Bool(
desc='3 point linear filter: 0.15*a + 0.70*b + 0.15*c'
'[This is the default smoother]',
argstr='-lin')
med = traits.Bool(
desc='3 point median filter: median(a,b,c)',
argstr='-med')
osf = traits.Bool(
desc='3 point order statistics filter:'
'0.15*min(a,b,c) + 0.70*median(a,b,c) + 0.15*max(a,b,c)',
argstr='-osf')
lin3 = traits.Int(
desc='3 point linear filter: 0.5*(1-m)*a + m*b + 0.5*(1-m)*c'
"Here, 'm' is a number strictly between 0 and 1.",
argstr='-3lin %d')
hamming = traits.Int(
argstr='-hamming %d',
desc='Use N point Hamming windows.'
'(N must be odd and bigger than 1.)')
blackman = traits.Int(
argstr='-blackman %d',
desc='Use N point Blackman windows.'
'(N must be odd and bigger than 1.)')
custom = File(
argstr='-custom %s',
desc='odd # of coefficients must be in a single column in ASCII file')
adaptive = traits.Int(
argstr='-adaptive %d',
desc='use adaptive mean filtering of width N '
'(where N must be odd and bigger than 3).')


class TSmooth(AFNICommand):
"""Smooths each voxel time series in a 3D+time dataset and produces
as output a new 3D+time dataset (e.g., lowpass filter in time).

For complete details, see the `3dTsmooth Documentation.
<https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dTSmooth.html>`_

Examples
========

>>> from nipype.interfaces import afni
>>> from nipype.testing import example_data
>>> smooth = afni.TSmooth()
>>> smooth.inputs.in_file = 'functional.nii'
>>> smooth.inputs.adaptive = 5
>>> smooth.cmdline
'3dTsmooth -adaptive 5 -prefix functional_smooth functional.nii'
>>> res = smooth.run() # doctest: +SKIP

"""
_cmd = '3dTsmooth'
input_spec = TSmoothInputSpec
output_spec = AFNICommandOutputSpec


class VolregInputSpec(AFNICommandInputSpec):
in_file = File(
desc='input file to 3dvolreg',
Expand Down
55 changes: 55 additions & 0 deletions nipype/interfaces/afni/tests/test_auto_TSmooth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
from __future__ import unicode_literals
from ..preprocess import TSmooth


def test_TSmooth_inputs():
input_map = dict(
adaptive=dict(argstr='-adaptive %d', ),
args=dict(argstr='%s', ),
blackman=dict(argstr='-blackman %d', ),
custom=dict(
argstr='-custom %s',
extensions=None,
),
datum=dict(argstr='-datum %s', ),
environ=dict(
nohash=True,
usedefault=True,
),
hamming=dict(argstr='-hamming %d', ),
in_file=dict(
argstr='%s',
copyfile=False,
extensions=None,
mandatory=True,
position=-1,
),
lin=dict(argstr='-lin', ),
lin3=dict(argstr='-3lin %d', ),
med=dict(argstr='-med', ),
num_threads=dict(
nohash=True,
usedefault=True,
),
osf=dict(argstr='-osf', ),
out_file=dict(
argstr='-prefix %s',
extensions=None,
name_source='in_file',
name_template='%s_smooth',
),
outputtype=dict(),
)
inputs = TSmooth.input_spec()

for key, metadata in list(input_map.items()):
for metakey, value in list(metadata.items()):
assert getattr(inputs.traits()[key], metakey) == value
def test_TSmooth_outputs():
output_map = dict(out_file=dict(extensions=None, ), )
outputs = TSmooth.output_spec()

for key, metadata in list(output_map.items()):
for metakey, value in list(metadata.items()):
assert getattr(outputs.traits()[key], metakey) == value