From 11d3422717b998766be98c4fc4c20511082734ba Mon Sep 17 00:00:00 2001 From: Gio at UMCU Date: Tue, 25 Jun 2019 17:02:15 +0200 Subject: [PATCH 1/5] added simple version of 3dTsmooth --- nipype/interfaces/afni/__init__.py | 2 +- nipype/interfaces/afni/preprocess.py | 47 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/nipype/interfaces/afni/__init__.py b/nipype/interfaces/afni/__init__.py index 7af80059f2..015f17df73 100644 --- a/nipype/interfaces/afni/__init__.py +++ b/nipype/interfaces/afni/__init__.py @@ -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, diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index a2e9cb7f4d..189216112c 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -2853,6 +2853,53 @@ 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', + position=1, + name_source='in_file', + genfile=True) + adaptive = traits.Int( + desc='adaptive', + argstr='-adaptive %d', + position=-2, + mandatory=False) + + +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 `3dBandpass Documentation. + `_ + + 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 -prefix functional_smooth -adaptive 5 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', From f3410892fadfd4ed7d5dc82d402614d3ff12c017 Mon Sep 17 00:00:00 2001 From: Gio at UMCU Date: Wed, 26 Jun 2019 10:03:45 +0200 Subject: [PATCH 2/5] add all options for 3dTsmooth --- nipype/interfaces/afni/preprocess.py | 37 ++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index 189216112c..12aefcc2a8 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -2865,21 +2865,48 @@ class TSmoothInputSpec(AFNICommandInputSpec): name_template='%s_smooth', desc='output file from 3dTSmooth', argstr='-prefix %s', - position=1, name_source='in_file', genfile=True) + 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( - desc='adaptive', argstr='-adaptive %d', - position=-2, - mandatory=False) + 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 `3dBandpass Documentation. + For complete details, see the `3dTsmooth Documentation. `_ Examples From 0a05ce98917fec14fd74355575fdf5dcb671d3bb Mon Sep 17 00:00:00 2001 From: Gio at UMCU Date: Wed, 26 Jun 2019 10:11:14 +0200 Subject: [PATCH 3/5] added autotest for TSmooth --- .../afni/tests/test_auto_TSmooth.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 nipype/interfaces/afni/tests/test_auto_TSmooth.py diff --git a/nipype/interfaces/afni/tests/test_auto_TSmooth.py b/nipype/interfaces/afni/tests/test_auto_TSmooth.py new file mode 100644 index 0000000000..9aa6eebe7f --- /dev/null +++ b/nipype/interfaces/afni/tests/test_auto_TSmooth.py @@ -0,0 +1,51 @@ +# 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', ), + datum=dict(argstr='-datum %s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + hamming=dict(argstr='-hamming %d', ), + in_file=dict( + argstr='%s', + copyfile=False, + 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', + genfile=True, + 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(), ) + 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 From 8d76fd2f44af0c94b40a5ef7228f048ca02924d7 Mon Sep 17 00:00:00 2001 From: Gio at UMCU Date: Thu, 5 Sep 2019 10:00:17 +0200 Subject: [PATCH 4/5] remove genfile from out_file of TSmooth and fix order of arguments in command line of 3dTsmooth --- nipype/interfaces/afni/preprocess.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index 12aefcc2a8..7b7d252c9f 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -2865,8 +2865,7 @@ class TSmoothInputSpec(AFNICommandInputSpec): name_template='%s_smooth', desc='output file from 3dTSmooth', argstr='-prefix %s', - name_source='in_file', - genfile=True) + name_source='in_file') datum = traits.Str( desc='Sets the data type of the output dataset', argstr='-datum %s') @@ -2918,7 +2917,7 @@ class TSmooth(AFNICommand): >>> smooth.inputs.in_file = 'functional.nii' >>> smooth.inputs.adaptive = 5 >>> smooth.cmdline - '3dTsmooth -prefix functional_smooth -adaptive 5 functional.nii' + '3dTsmooth -adaptive 5 -prefix functional_smooth functional.nii' >>> res = smooth.run() # doctest: +SKIP """ From 56e571532dc1470e63530d8a7e760db59d130ebd Mon Sep 17 00:00:00 2001 From: Gio at UMCU Date: Fri, 6 Sep 2019 16:20:34 +0200 Subject: [PATCH 5/5] added auto test for 3dTsmooth (without removing other files) --- nipype/interfaces/afni/tests/test_auto_TSmooth.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nipype/interfaces/afni/tests/test_auto_TSmooth.py b/nipype/interfaces/afni/tests/test_auto_TSmooth.py index 9aa6eebe7f..cbcc871bc7 100644 --- a/nipype/interfaces/afni/tests/test_auto_TSmooth.py +++ b/nipype/interfaces/afni/tests/test_auto_TSmooth.py @@ -8,7 +8,10 @@ def test_TSmooth_inputs(): adaptive=dict(argstr='-adaptive %d', ), args=dict(argstr='%s', ), blackman=dict(argstr='-blackman %d', ), - custom=dict(argstr='-custom %s', ), + custom=dict( + argstr='-custom %s', + extensions=None, + ), datum=dict(argstr='-datum %s', ), environ=dict( nohash=True, @@ -18,6 +21,7 @@ def test_TSmooth_inputs(): in_file=dict( argstr='%s', copyfile=False, + extensions=None, mandatory=True, position=-1, ), @@ -31,7 +35,7 @@ def test_TSmooth_inputs(): osf=dict(argstr='-osf', ), out_file=dict( argstr='-prefix %s', - genfile=True, + extensions=None, name_source='in_file', name_template='%s_smooth', ), @@ -43,7 +47,7 @@ def test_TSmooth_inputs(): for metakey, value in list(metadata.items()): assert getattr(inputs.traits()[key], metakey) == value def test_TSmooth_outputs(): - output_map = dict(out_file=dict(), ) + output_map = dict(out_file=dict(extensions=None, ), ) outputs = TSmooth.output_spec() for key, metadata in list(output_map.items()):