From 094c4756193252cf400a337620c6f7466fce12d1 Mon Sep 17 00:00:00 2001 From: Kesshi Jordan Date: Mon, 11 Sep 2017 11:04:55 -0700 Subject: [PATCH 01/53] changes made by make, I think --- nipype/interfaces/afni/preprocess.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index e0e2518ef1..91a68bd97b 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -119,7 +119,7 @@ class AlignEpiAnatPyOutputSpec(TraitedSpec): desc="matrix to volume register and align epi" "to anatomy and put into standard space") epi_vr_motion = File( - desc="motion parameters from EPI time-series" + desc="motion parameters from EPI time-series" "registration (tsh included in name if slice" "timing correction is also included).") skullstrip = File( @@ -131,20 +131,20 @@ class AlignEpiAnatPy(AFNIPythonCommand): an EPI and an anatomical structural dataset, and applies the resulting transformation to one or the other to bring them into alignment. - This script computes the transforms needed to align EPI and - anatomical datasets using a cost function designed for this purpose. The - script combines multiple transformations, thereby minimizing the amount of + This script computes the transforms needed to align EPI and + anatomical datasets using a cost function designed for this purpose. The + script combines multiple transformations, thereby minimizing the amount of interpolation applied to the data. - + Basic Usage: align_epi_anat.py -anat anat+orig -epi epi+orig -epi_base 5 - + The user must provide EPI and anatomical datasets and specify the EPI - sub-brick to use as a base in the alignment. + sub-brick to use as a base in the alignment. Internally, the script always aligns the anatomical to the EPI dataset, - and the resulting transformation is saved to a 1D file. - As a user option, the inverse of this transformation may be applied to the + and the resulting transformation is saved to a 1D file. + As a user option, the inverse of this transformation may be applied to the EPI dataset in order to align it to the anatomical data instead. This program generates several kinds of output in the form of datasets @@ -182,7 +182,7 @@ def _list_outputs(self): epi_prefix = ''.join(self._gen_fname(self.inputs.in_file).split('+')[:-1]) outputtype = self.inputs.outputtype if outputtype == 'AFNI': - ext = '.HEAD' + ext = '.HEAD' else: Info.output_type_to_ext(outputtype) matext = '.1D' @@ -620,7 +620,7 @@ class AutoTLRCInputSpec(CommandLineInputSpec): mandatory=True, exists=True, copyfile=False) - base = traits.Str( + base = traits.Str( desc = ' Reference anatomical volume' ' Usually this volume is in some standard space like' ' TLRC or MNI space and with afni dataset view of' @@ -706,7 +706,7 @@ def _list_outputs(self): ext = '.HEAD' outputs['out_file'] = os.path.abspath(self._gen_fname(self.inputs.in_file, suffix='+tlrc')+ext) return outputs - + class BandpassInputSpec(AFNICommandInputSpec): in_file = File( desc='input file to 3dBandpass', From 0c28b39172da5f91776964cf7270a5961055a80f Mon Sep 17 00:00:00 2001 From: Satrajit Ghosh Date: Fri, 23 Feb 2018 16:03:27 -0500 Subject: [PATCH 02/53] fix: dtitk interface specs --- nipype/interfaces/afni/preprocess.py | 2 +- nipype/interfaces/dtitk/registration.py | 330 +++++++++++------------- nipype/interfaces/dtitk/utils.py | 221 +++++----------- 3 files changed, 213 insertions(+), 340 deletions(-) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index 666f4b7be1..0f68ed4b47 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -2516,7 +2516,7 @@ class TProjectInputSpec(AFNICommandInputSpec): rather than the value stored in the dataset header.""", argstr='-TR %g') mask = File( - exist=True, + exists=True, desc="""Only operate on voxels nonzero in the mset dataset. ++ Voxels outside the mask will be filled with zeros. ++ If no masking option is given, then all voxels diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 3dd1c068c8..4be863cce6 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -1,16 +1,28 @@ -from ..base import TraitedSpec, CommandLineInputSpec, traits, isdefined +# -*- coding: utf-8 -*- +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- +# vi: set ft=python sts=4 ts=4 sw=4 et: +"""DTITK registration interfaces + + Change directory to provide relative paths for doctests + >>> import os + >>> filepath = os.path.dirname( os.path.realpath( __file__ ) ) + >>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data')) + >>> os.chdir(datadir) +""" + +from ..base import TraitedSpec, CommandLineInputSpec, traits, isdefined, File from ...utils.filemanip import fname_presuffix import os from .base import CommandLineDtitk class RigidInputSpec(CommandLineInputSpec): - fixed_file = traits.Str(desc="fixed diffusion tensor image", - exists=True, mandatory=True, - position=0, argstr="%s") - moving_file = traits.Str(desc="diffusion tensor image path", exists=True, - mandatory=True, position=1, argstr="%s") - similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', exists=True, + fixed_file = File(desc="fixed diffusion tensor image", + exists=True, mandatory=True, + position=0, argstr="%s") + moving_file = File(desc="diffusion tensor image path", exists=True, + mandatory=True, position=1, argstr="%s", copyfile=False) + similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', mandatory=True, position=2, argstr="%s", desc="similarity metric") samplingX = traits.Float(mandatory=True, position=3, argstr="%s", @@ -24,35 +36,34 @@ class RigidInputSpec(CommandLineInputSpec): default_value=4) ftol = traits.Float(mandatory=True, position=6, argstr="%s", desc="cost function tolerance", default_value=0.01) - useInTrans = traits.Float(mandatory=False, position=7, argstr="%s", + useInTrans = traits.Float(position=7, argstr="%s", desc="to initialize with existing xfm set as 1", default_value=1) class RigidOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) - out_file_xfm = traits.File(exists=True) + out_file = File(exists=True) + out_file_xfm = File(exists=True) class RigidTask(CommandLineDtitk): + """Performs rigid registration between two tensor volumes + + Example + ------- + + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.RigidTask() + >>> node.inputs.fixed_file = 'diffusion.nii.gz' + >>> node.inputs.moving_file = 'diffusion2.nii.gz' + >>> node.inputs.similarity_metric = 'EDS' + >>> node.inputs.samplingX = 4 + >>> node.inputs.samplingY = 4 + >>> node.inputs.samplingZ = 4 + >>> node.inputs.ftol = 0.01 + >>> node.inputs.useInTrans = 1 + >>> node.run() # doctest: +SKIP """ - Performs rigid registration between two tensor volumes - - Example - ------- - - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.RigidTask() - >>> node.inputs.fixed_file = 'diffusion.nii.gz' - >>> node.inputs.moving_file = 'diffusion2.nii.gz' - >>> node.inputs.similarity_metric = 'EDS' - >>> node.inputs.samplingX = 4 - >>> node.inputs.samplingY = 4 - >>> node.inputs.samplingZ = 4 - >>> node.inputs.ftol = 0.01 - >>> node.inputs.useInTrans = 1 - >>> node.run() # doctest: +SKIP - """ input_spec = RigidInputSpec output_spec = RigidOutputSpec _cmd = 'dti_rigid_reg' @@ -67,12 +78,12 @@ def _list_outputs(self): class AffineInputSpec(CommandLineInputSpec): - fixed_file = traits.Str(desc="fixed diffusion tensor image", - exists=True, mandatory=True, - position=0, argstr="%s") - moving_file = traits.Str(desc="diffusion tensor image path", exists=True, - mandatory=True, position=1, argstr="%s") - similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', exists=True, + fixed_file = File(desc="fixed diffusion tensor image", + exists=True, mandatory=True, + position=0, argstr="%s") + moving_file = File(desc="diffusion tensor image path", exists=True, + mandatory=True, position=1, argstr="%s", copyfile=False) + similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', mandatory=True, position=2, argstr="%s", desc="similarity metric") samplingX = traits.Float(mandatory=True, position=3, argstr="%s", @@ -86,35 +97,34 @@ class AffineInputSpec(CommandLineInputSpec): default_value=4) ftol = traits.Float(mandatory=True, position=6, argstr="%s", desc="cost function tolerance", default_value=0.01) - useInTrans = traits.Float(mandatory=False, position=7, argstr="%s", + useInTrans = traits.Float(position=7, argstr="%s", desc="to initialize with existing xfm set as 1", default_value=1) class AffineOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) - out_file_xfm = traits.File(exists=True) + out_file = File(exists=True) + out_file_xfm = File(exists=True) class AffineTask(CommandLineDtitk): + """Performs affine registration between two tensor volumes + + Example + ------- + + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.AffineTask() + >>> node.inputs.fixed_file = 'diffusion.nii.gz' + >>> node.inputs.moving_file = 'diffusion2.nii.gz' + >>> node.inputs.similarity_metric = 'EDS' + >>> node.inputs.samplingX = 4 + >>> node.inputs.samplingY = 4 + >>> node.inputs.samplingZ = 4 + >>> node.inputs.ftol = 0.01 + >>> node.inputs.useInTrans = 1 + >>> node.run() # doctest: +SKIP """ - Performs affine registration between two tensor volumes - - Example - ------- - - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.AffineTask() - >>> node.inputs.fixed_file = 'diffusion.nii.gz' - >>> node.inputs.moving_file = 'diffusion2.nii.gz' - >>> node.inputs.similarity_metric = 'EDS' - >>> node.inputs.samplingX = 4 - >>> node.inputs.samplingY = 4 - >>> node.inputs.samplingZ = 4 - >>> node.inputs.ftol = 0.01 - >>> node.inputs.useInTrans = 1 - >>> node.run() # doctest: +SKIP - """ input_spec = AffineInputSpec output_spec = AffineOutputSpec _cmd = 'dti_affine_reg' @@ -129,14 +139,11 @@ def _list_outputs(self): class DiffeoInputSpec(CommandLineInputSpec): - fixed_file = traits.Str(desc="fixed diffusion tensor image", - exists=True, mandatory=False, position=0, - argstr="%s") - moving_file = traits.Str(desc="moving diffusion tensor image", - exists=True, mandatory=False, - position=1, argstr="%s") - mask = traits.Str(desc="mask", exists=True, mandatory=False, position=2, - argstr="%s") + fixed_file = File(desc="fixed diffusion tensor image", + exists=True, position=0, argstr="%s") + moving_file = File(desc="moving diffusion tensor image", + exists=True, position=1, argstr="%s", copyfile=False) + mask = File(desc="mask", exists=True, position=2, argstr="%s") legacy = traits.Float(desc="legacy parameter; always set to 1", exists=True, mandatory=True, position=3, default_value=1, argstr="%s") @@ -149,27 +156,26 @@ class DiffeoInputSpec(CommandLineInputSpec): class DiffeoOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) - out_file_xfm = traits.File(exists=True) + out_file = File(exists=True) + out_file_xfm = File(exists=True) class DiffeoTask(CommandLineDtitk): + """Performs diffeomorphic registration between two tensor volumes + + Example + ------- + + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.DiffeoTask() + >>> node.inputs.fixed_file = 'diffusion.nii.gz' + >>> node.inputs.moving_file = 'diffusion2.nii.gz' + >>> node.inputs.mask = 'mask.nii.gz' + >>> node.inputs.legacy = 1 + >>> node.inputs.n_iters = 6 + >>> node.inputs.ftol = 0.002 + >>> node.run() # doctest: +SKIP """ - Performs diffeomorphic registration between two tensor volumes - - Example - ------- - - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.DiffeoTask() - >>> node.inputs.fixed_file = 'diffusion.nii.gz' - >>> node.inputs.moving_file = 'diffusion2.nii.gz' - >>> node.inputs.mask = 'mask.nii.gz' - >>> node.inputs.legacy = 1 - >>> node.inputs.n_iters = 6 - >>> node.inputs.ftol = 0.002 - >>> node.run() # doctest: +SKIP - """ input_spec = DiffeoInputSpec output_spec = DiffeoOutputSpec _cmd = 'dti_diffeomorphic_reg' @@ -184,32 +190,32 @@ def _list_outputs(self): class ComposeXfmInputSpec(CommandLineInputSpec): - in_df = traits.Str(desc='diffeomorphic file.df.nii.gz', exists=True, - mandatory=False, position=1, argstr="-df %s") - in_aff = traits.Str(desc='affine file.aff', exists=True, mandatory=False, + in_df = File(desc='diffeomorphic file.df.nii.gz', exists=True, + position=1, argstr="-df %s", copyfile=False) + in_aff = File(desc='affine file.aff', exists=True, position=0, argstr="-aff %s") - out_file = traits.Str(desc='output_path', exists=True, mandatory=False, + out_file = traits.Str(desc='output_path', exists=True, position=2, argstr="-out %s", name_source="in_df", name_template="%s_comboaff.nii.gz") class ComposeXfmOutputSpec(TraitedSpec): - out_file = traits.File(desc='cheese', exists=True) + out_file = File(desc='cheese', exists=True) class ComposeXfmTask(CommandLineDtitk): """ Combines diffeomorphic and affine transforms - Example - ------- + Example + ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.ComposeXfmTask() - >>> node.inputs.in_df = 'ants_Warp.nii.gz' - >>> node.inputs.in_aff= 'ants_Affine.txt' - >>> node.run() # doctest: +SKIP - """ + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.ComposeXfmTask() + >>> node.inputs.in_df = 'ants_Warp.nii.gz' + >>> node.inputs.in_aff= 'ants_Affine.txt' + >>> node.run() # doctest: +SKIP + """ input_spec = ComposeXfmInputSpec output_spec = ComposeXfmOutputSpec _cmd = 'dfRightComposeAffine' @@ -222,173 +228,145 @@ def _list_outputs(self): class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): - in_tensor = traits.Str(desc='moving tensor', exists=True, mandatory=False, + in_tensor = File(desc='moving tensor', exists=True, position=0, argstr="-in %s") - in_xfm = traits.Str(desc='transform to apply', exists=True, - mandatory=False, - position=1, argstr="-trans %s") - in_target = traits.Str(desc='', exists=True, mandatory=False, position=2, + in_xfm = File(desc='transform to apply', exists=True, + position=1, argstr="-trans %s") + in_target = File(desc='', exists=True, position=2, argstr="-target %s") - out_file = traits.Str(desc='', exists=True, mandatory=False, position=3, + out_file = traits.Str(desc='', exists=True, position=3, argstr="-out %s", name_source="in_tensor", name_template="%s_diffeoxfmd.nii.gz") class diffeoSymTensor3DVolOutputSpec(TraitedSpec): - out_file = traits.File(desc='cheese', exists=True) + out_file = File(desc='cheese', exists=True) class diffeoSymTensor3DVolTask(CommandLineDtitk): """ Applies diffeomorphic transform to a tensor volume - Example - ------- + Example + ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.diffeoSymTensor3DVolTask() - >>> node.inputs.in_tensor = 'diffusion.nii' - >>> node.inputs.in_xfm = 'ants_Warp.nii.gz' - >>> node.run() # doctest: +SKIP - """ + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.diffeoSymTensor3DVolTask() + >>> node.inputs.in_tensor = 'diffusion.nii' + >>> node.inputs.in_xfm = 'ants_Warp.nii.gz' + >>> node.run() # doctest: +SKIP + """ input_spec = diffeoSymTensor3DVolInputSpec output_spec = diffeoSymTensor3DVolOutputSpec _cmd = 'deformationSymTensor3DVolume' - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - return outputs - class affSymTensor3DVolInputSpec(CommandLineInputSpec): - in_tensor = traits.Str(desc='moving tensor', exists=True, mandatory=False, + in_tensor = File(desc='moving tensor', exists=True, position=0, argstr="-in %s") - in_xfm = traits.Str(desc='transform to apply', exists=True, - mandatory=False, position=1, argstr="-trans %s") - in_target = traits.Str(desc='', exists=True, mandatory=False, position=2, + in_xfm = File(desc='transform to apply', exists=True, + position=1, argstr="-trans %s") + in_target = File(desc='', exists=True, position=2, argstr="-target %s") - out_file = traits.Str(desc='', exists=True, mandatory=False, position=3, + out_file = traits.Str(desc='', exists=True, position=3, argstr="-out %s", name_source="in_tensor", name_template="%s_affxfmd.nii.gz") class affSymTensor3DVolOutputSpec(TraitedSpec): - out_file = traits.File(desc='cheese', exists=True) + out_file = File(desc='cheese', exists=True) class affSymTensor3DVolTask(CommandLineDtitk): """ Applies affine transform to a tensor volume - Example - ------- + Example + ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.affSymTensor3DVolTask() - >>> node.inputs.in_tensor = 'diffusion.nii' - >>> node.inputs.in_xfm = 'ants_Affine.txt' - >>> node.run() # doctest: +SKIP - """ + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.affSymTensor3DVolTask() + >>> node.inputs.in_tensor = 'diffusion.nii' + >>> node.inputs.in_xfm = 'ants_Affine.txt' + >>> node.run() # doctest: +SKIP + """ input_spec = affSymTensor3DVolInputSpec output_spec = affSymTensor3DVolOutputSpec _cmd = 'affineSymTensor3DVolume' - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = os.path.abspath(self.inputs.out_file) - return outputs - class affScalarVolInputSpec(CommandLineInputSpec): - in_volume = traits.Str(desc='moving volume', exists=True, mandatory=False, + in_volume = File(desc='moving volume', exists=True, position=0, argstr="-in %s") - in_xfm = traits.Str(desc='transform to apply', exists=True, - mandatory=False, + in_xfm = File(desc='transform to apply', exists=True, position=1, argstr="-trans %s") - in_target = traits.Str(desc='', position=2, argstr="-target %s") - out_file = traits.Str(desc='', mandatory=False, position=3, + in_target = File(desc='', position=2, argstr="-target %s") + out_file = traits.Str(desc='', position=3, argstr="-out %s", name_source="in_volume", name_template="%s_affxfmd.nii.gz") class affScalarVolOutputSpec(TraitedSpec): - out_file = traits.File(desc='moved volume', exists=True) + out_file = File(desc='moved volume', exists=True) class affScalarVolTask(CommandLineDtitk): """ Applies affine transform to a scalar volume - Example - ------- + Example + ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.affScalarVolTask() - >>> node.inputs.in_volume = 'fa.nii.gz' - >>> node.inputs.in_xfm = 'ants_Affine.txt' - >>> node.run() # doctest: +SKIP - """ + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.affScalarVolTask() + >>> node.inputs.in_volume = 'fa.nii.gz' + >>> node.inputs.in_xfm = 'ants_Affine.txt' + >>> node.run() # doctest: +SKIP + """ input_spec = affScalarVolInputSpec output_spec = affScalarVolOutputSpec _cmd = 'affineScalarVolume' - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = os.path.abspath(self.inputs.out_file) - return outputs - class diffeoScalarVolInputSpec(CommandLineInputSpec): - in_volume = traits.Str(desc='moving volume', exists=True, mandatory=False, + in_volume = File(desc='moving volume', exists=True, position=0, argstr="-in %s") - in_xfm = traits.Str(desc='transform to apply', exists=True, - mandatory=False, + in_xfm = File(desc='transform to apply', exists=True, position=2, argstr="-trans %s") - in_target = traits.Str(desc='', exists=True, mandatory=False, position=3, + in_target = File(desc='', exists=True, position=3, argstr="-target %s") out_file = traits.Str(desc='', position=1, argstr="-out %s", name_source="in_volume", name_template="%s_diffeoxfmd.nii.gz") - in_vsize = traits.Str(desc='', exists=True, mandatory=False, position=4, + in_vsize = File(desc='', exists=True, position=4, argstr="-vsize %s") - in_flip = traits.Str(desc='', exists=True, mandatory=False, position=5, + in_flip = File(desc='', exists=True, position=5, argstr="-flip %s") - in_type = traits.Str(desc='', exists=True, mandatory=False, position=6, + in_type = File(desc='', exists=True, position=6, argstr="-type %s") - in_interp = traits.Str(desc='0 trilin, 1 NN', exists=True, mandatory=False, + in_interp = File(desc='0 trilin, 1 NN', exists=True, position=7, argstr="-interp %s") class diffeoScalarVolOutputSpec(TraitedSpec): - out_file = traits.File(desc='moved volume', exists=True) + out_file = File(desc='moved volume', exists=True) class diffeoScalarVolTask(CommandLineDtitk): """ Applies diffeomorphic transform to a scalar volume - Example - ------- + Example + ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.diffeoScalarVolTask() - >>> node.inputs.in_volume = 'fa.nii.gz' - >>> node.inputs.in_xfm = 'ants_Warp.nii.gz' - >>> node.run() # doctest: +SKIP - """ + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.diffeoScalarVolTask() + >>> node.inputs.in_volume = 'fa.nii.gz' + >>> node.inputs.in_xfm = 'ants_Warp.nii.gz' + >>> node.run() # doctest: +SKIP + """ input_spec = diffeoScalarVolInputSpec output_spec = diffeoScalarVolOutputSpec _cmd = 'deformationScalarVolume' - - def _list_outputs(self): - outputs = self.output_spec().get() - if not isdefined(self.inputs.out_file): - self.inputs.out_file = fname_presuffix(self.inputs.in_volume, - suffix="_diffeoxfmd", - newpath=os.path.abspath( - ".")) - outputs['out_file'] = os.path.abspath(self.inputs.out_file) - return outputs diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index 86e0c08b8c..15b8077c4e 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -1,3 +1,14 @@ +# -*- coding: utf-8 -*- +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- +# vi: set ft=python sts=4 ts=4 sw=4 et: +"""DTITK utility interfaces + + Change directory to provide relative paths for doctests + >>> import os + >>> filepath = os.path.dirname( os.path.realpath( __file__ ) ) + >>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data')) + >>> os.chdir(datadir) +""" __author__ = 'kjordan' from ..base import TraitedSpec, CommandLineInputSpec, File, \ @@ -9,14 +20,14 @@ class TVAdjustOriginInputSpec(CommandLineInputSpec): in_file = File(desc="image to resample", exists=True, mandatory=True, position=0, argstr="-in %s") - out_file = traits.Str(genfile=True, desc='output path', position=1, - argstr="-out %s") - origin = traits.Str(desc='xyz voxel size', exists=True, mandatory=False, + out_file = traits.Str(desc='output path', position=1, argstr="-out %s", + namesource=['in_file'], name_template='%s_originzero') + origin = traits.Str(desc='xyz voxel size', position=4, argstr='-origin %s') class TVAdjustOriginOutputSpec(TraitedSpec): - out_file = traits.Str(exists=True) + out_file = File(exists=True) class TVAdjustOriginTask(CommandLineDtitk): @@ -35,41 +46,24 @@ class TVAdjustOriginTask(CommandLineDtitk): input_spec = TVAdjustOriginInputSpec output_spec = TVAdjustOriginOutputSpec _cmd = 'TVAdjustVoxelspace' - _suffix = "_originzero" - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - if not isdefined(self.inputs.out_file): - outputs["out_file"] = self._gen_fname(self.inputs.in_file, - suffix=self._suffix, - ext='.'+'.'.join( - self.inputs.in_file. - split(".")[1:])) - outputs["out_file"] = os.path.abspath(outputs["out_file"]) - return outputs - - def _gen_filename(self, name): - if name == "out_file": - return self._list_outputs()["out_file"] - return None class TVAdjustVoxSpInputSpec(CommandLineInputSpec): in_file = File(desc="image to resample", exists=True, mandatory=True, position=0, argstr="-in %s") out_file = traits.Str(genfile=True, desc='output path', position=1, - argstr="-out %s") - origin = traits.Str(desc='xyz voxel size', exists=True, mandatory=False, + argstr="-out %s", name_source='in_file', + name_template='%s_reslice', keep_extension=True) + origin = traits.Str(desc='xyz voxel size', mandatory=True, position=4, argstr='-origin %s') - target = traits.Str(desc='target volume', exists=True, mandatory=False, + target = traits.Str(desc='target volume', mandaotry=True, position=2, argstr="-target %s") - vsize = traits.Str(desc='resampled voxel size', exists=True, - mandatory=False, position=3, argstr="-vsize %s") + vsize = traits.Str(desc='resampled voxel size', mandatory=True, + position=3, argstr="-vsize %s") class TVAdjustVoxSpOutputSpec(TraitedSpec): - out_file = traits.Str(exists=True) + out_file = File(exists=True) class TVAdjustVoxSpTask(CommandLineDtitk): @@ -87,46 +81,26 @@ class TVAdjustVoxSpTask(CommandLineDtitk): input_spec = TVAdjustVoxSpInputSpec output_spec = TVAdjustVoxSpOutputSpec _cmd = 'TVAdjustVoxelspace' - _suffix = '_reslice' - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - if not isdefined(self.inputs.out_file): - outputs["out_file"] = self._gen_fname(self.inputs.in_file, - suffix=self._suffix, - ext='.'+'.'.join( - self.inputs.in_file. - split(".")[1:])) - outputs["out_file"] = os.path.abspath(outputs["out_file"]) - return outputs - - def _gen_filename(self, name): - if name == "out_file": - return self._list_outputs()["out_file"] - return None # TODO not using these yet... need to be tested - class SVAdjustVoxSpInputSpec(CommandLineInputSpec): - in_file = traits.Str(desc="image to resample", exists=True, + in_file = File(desc="image to resample", exists=True, mandatory=True, position=0, argstr="-in %s") - in_target = traits.Str(desc='target volume', exists=True, mandatory=False, + in_target = File(desc='target volume', mandatory=True, position=2, argstr="-target %s") - in_voxsz = traits.Str(desc='resampled voxel size', exists=True, - mandatory=False, position=3, argstr="-vsize %s") - out_file = traits.Str(desc='output path', exists=True, mandatory=False, - position=1, argstr="-out %s", - name_source="in_file", - name_template='%s_origmvd.nii.gz') - origin = traits.Str(desc='xyz voxel size', exists=True, mandatory=False, + in_voxsz = traits.Str(desc='resampled voxel size', mandatory=True, + position=3, argstr="-vsize %s") + out_file = traits.Str(desc='output path', position=1, argstr="-out %s", + name_source="in_file", name_template='%s_reslice', + keep_extension=True) + origin = traits.Str(desc='xyz voxel size', mandatory=True, position=4, argstr='-origin %s') class SVAdjustVoxSpOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) + out_file = File(exists=True) class SVAdjustVoxSpTask(CommandLineDtitk): @@ -144,41 +118,22 @@ class SVAdjustVoxSpTask(CommandLineDtitk): input_spec = SVAdjustVoxSpInputSpec output_spec = SVAdjustVoxSpOutputSpec _cmd = 'SVAdjustVoxelspace' - _suffix = '_reslice' - - def _gen_filename(self, name): - if name == "out_file": - return self._list_outputs()["out_file"] - return None - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - if not isdefined(self.inputs.out_file): - outputs["out_file"] = self._gen_filename(self.inputs.in_file, - suffix=self._suffix, - ext='.' + '.'.join( - self.inputs.in_file. - split(".")[1:])) - outputs["out_file"] = os.path.abspath(outputs["out_file"]) - return outputs class TVResampleInputSpec(CommandLineInputSpec): - in_file = traits.Str(desc="image to resample", exists=True, + in_file = File(desc="image to resample", exists=True, mandatory=True, position=0, argstr="-in %s") in_arraysz = traits.Str(desc='resampled array size', exists=True, - mandatory=False, position=1, argstr="-size %s") + position=1, argstr="-size %s") in_voxsz = traits.Str(desc='resampled voxel size', exists=True, - mandatory=False, position=2, argstr="-vsize %s") - out_file = traits.Str(desc='output path', exists=True, mandatory=False, - position=3, argstr="-out %s", - name_source="in_file", - name_template="%s_resampled.nii.gz") + position=2, argstr="-vsize %s") + out_file = traits.Str(desc='output path', position=3, argstr="-out %s", + name_source="in_file", name_template="%s_resampled", + keep_extesnion=True) class TVResampleOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) + out_file = File(exists=True) class TVResampleTask(CommandLineDtitk): @@ -196,42 +151,14 @@ class TVResampleTask(CommandLineDtitk): input_spec = TVResampleInputSpec output_spec = TVResampleOutputSpec _cmd = 'TVResample' - _suffix = '_resampled' - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - if not isdefined(self.inputs.out_file): - outputs["out_file"] = self._gen_fname(self.inputs.in_file, - suffix=self._suffix, - ext='.' + '.'.join( - self.inputs.in_file. - split(".")[1:])) - outputs["out_file"] = os.path.abspath(outputs["out_file"]) - return outputs - - def _gen_filename(self, name): - if name == "out_file": - return self._list_outputs()["out_file"] - return None -class SVResampleInputSpec(CommandLineInputSpec): - in_file = traits.Str(desc="image to resample", exists=True, - mandatory=True, position=0, argstr="-in %s") - in_arraysz = traits.Str(desc='resampled array size', exists=True, - mandatory=False, position=1, - argstr="-size %s") - in_voxsz = traits.Str(desc='resampled voxel size', exists=True, - mandatory=False, position=2, argstr="-vsize %s") - out_file = traits.Str(desc='output path', exists=True, mandatory=False, - position=3, argstr="-out %s", - name_source="in_file", - name_template="%s_resampled.nii.gz") +class SVResampleInputSpec(TVResampleInputSpec): + pass -class SVResampleOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) +class SVResampleOutputSpec(TVResampleOutputSpec): + pass class SVResampleTask(CommandLineDtitk): @@ -244,40 +171,23 @@ class SVResampleTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.SVResampleTask() >>> node.inputs.in_file = 'diffusion.nii' + >>> node.inputs.in_file = 'diffusion.nii' >>> node.run() # doctest: +SKIP """ input_spec = SVResampleInputSpec output_spec = SVResampleOutputSpec _cmd = 'SVResample' - _suffix = '_resampled' - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - if not isdefined(self.inputs.out_file): - outputs["out_file"] = self._gen_fname(self.inputs.in_file, - suffix=self._suffix, - ext='.' + '.'.join( - self.inputs.in_file. - split(".")[1:])) - outputs["out_file"] = os.path.abspath(outputs["out_file"]) - return outputs - - def _gen_filename(self, name): - if name == "out_file": - return self._list_outputs()["out_file"] - return None class TVtoolInputSpec(CommandLineInputSpec): - in_file = traits.Str(desc="image to resample", exists=True, - mandatory=False, position=0, argstr="-in %s") + in_file = File(desc="image to resample", exists=True, + position=0, argstr="-in %s") in_flag = traits.Enum('fa', 'tr', 'ad', 'rd', 'pd', 'rgb', exists=True, - mandatory=False, position=1, argstr="-%s", desc='') + position=1, argstr="-%s", desc='') class TVtoolOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) + out_file = File(exists=True) class TVtoolTask(CommandLineDtitk): @@ -317,17 +227,18 @@ def _gen_filename(self, name): class BinThreshInputSpec(CommandLineInputSpec): - in_file = traits.Str(desc='', exists=True, mandatory=False, position=0, + in_file = File(desc='', exists=True, position=0, argstr="%s") - out_file = traits.Str(desc='', exists=True, mandatory=False, position=1, - argstr="%s") - in_numbers = traits.Str(desc='LB UB inside_value outside_value', - exists=True, mandatory=False, position=2, - argstr="%s") + out_file = traits.Str(desc='', position=1, argstr="%s", + keep_extension=True, name_source='in_file', + name_template='%s_bin') + in_numbers = traits.List(traits.Float, minlen=4, maxlen=4, + desc='LB UB inside_value outside_value', + position=2, argstr="%s") class BinThreshOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) + out_file = File(exists=True) class BinThreshTask(CommandLineDtitk): @@ -340,28 +251,12 @@ class BinThreshTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.BinThreshTask() >>> node.inputs.in_file = 'diffusion.nii' - >>> node.inputs.in_numbers = '0 100 1 0' + >>> node.inputs.in_numbers = [0, 100, 1, 0] + >>> node.cmdline + 'BinaryThresholdImageFilter diffusion.nii diffusion_bin.nii 0.0 100.0 1.0 0.0' >>> node.run() # doctest: +SKIP """ input_spec = BinThreshInputSpec output_spec = BinThreshOutputSpec _cmd = 'BinaryThresholdImageFilter' - _suffix = '_bin' - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - if not isdefined(self.inputs.out_file): - outputs["out_file"] = self._gen_fname(self.inputs.in_file, - suffix=self._suffix, - ext='.'+'.'.join( - self.inputs.in_file. - split(".")[1:])) - outputs["out_file"] = os.path.abspath(outputs["out_file"]) - return outputs - - def _gen_filename(self, name): - if name == "out_file": - return self._list_outputs()["out_file"] - return None From 70d8d6347f248eb308373cdb1dcdf097cc500ef1 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Tue, 27 Feb 2018 12:48:20 -0800 Subject: [PATCH 03/53] redo input for rigid registration such that default values are passed instead of being mandatory --- nipype/interfaces/dtitk/registration.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 4be863cce6..c112191f3e 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -23,20 +23,20 @@ class RigidInputSpec(CommandLineInputSpec): moving_file = File(desc="diffusion tensor image path", exists=True, mandatory=True, position=1, argstr="%s", copyfile=False) similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', - mandatory=True, position=2, argstr="%s", - desc="similarity metric") - samplingX = traits.Float(mandatory=True, position=3, argstr="%s", + mandatory=False, position=2, argstr="%s", + desc="similarity metric", usedefault=True) + samplingX = traits.Float(mandatory=False, position=3, argstr="%s", desc="dist between samp points (mm)", - default_value=4) - samplingY = traits.Float(mandatory=True, position=4, argstr="%s", + default_value=4, usedefault=True) + samplingY = traits.Float(mandatory=False, position=4, argstr="%s", desc="dist between samp points (mm)", - default_value=4) - samplingZ = traits.Float(mandatory=True, position=5, argstr="%s", + default_value=4, usedefault=True) + samplingZ = traits.Float(mandatory=False, position=5, argstrr="%s", desc="dist between samp points (mm)", - default_value=4) - ftol = traits.Float(mandatory=True, position=6, argstr="%s", - desc="cost function tolerance", default_value=0.01) - useInTrans = traits.Float(position=7, argstr="%s", + default_value=4, usedefault=True) + ftol = traits.Float(mandatory=False, position=6, argstr="%s", + desc="cost function tolerance", default_value=0.01, usedefault=True) + useInTrans = traits.Int(mandatory=False, position=7, argstr="%s", desc="to initialize with existing xfm set as 1", default_value=1) From 19f49044d2f1a9b714470bf9bbdb8f515440a503 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Tue, 27 Feb 2018 14:24:56 -0800 Subject: [PATCH 04/53] fixed interface specs for Rigid and Affine --- nipype/interfaces/dtitk/registration.py | 36 +++++++++++++------------ 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index c112191f3e..de32bd6242 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -23,22 +23,23 @@ class RigidInputSpec(CommandLineInputSpec): moving_file = File(desc="diffusion tensor image path", exists=True, mandatory=True, position=1, argstr="%s", copyfile=False) similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', - mandatory=False, position=2, argstr="%s", + mandatory=True, position=2, argstr="%s", desc="similarity metric", usedefault=True) - samplingX = traits.Float(mandatory=False, position=3, argstr="%s", + samplingX = traits.Float(mandatory=True, position=3, argstr="%s", desc="dist between samp points (mm)", default_value=4, usedefault=True) - samplingY = traits.Float(mandatory=False, position=4, argstr="%s", + samplingY = traits.Float(mandatory=True, position=4, argstr="%s", desc="dist between samp points (mm)", default_value=4, usedefault=True) - samplingZ = traits.Float(mandatory=False, position=5, argstrr="%s", + samplingZ = traits.Float(mandatory=True, position=5, argstr="%s", desc="dist between samp points (mm)", default_value=4, usedefault=True) - ftol = traits.Float(mandatory=False, position=6, argstr="%s", - desc="cost function tolerance", default_value=0.01, usedefault=True) - useInTrans = traits.Int(mandatory=False, position=7, argstr="%s", - desc="to initialize with existing xfm set as 1", - default_value=1) + ftol = traits.Float(mandatory=True, position=6, argstr="%s", + desc="cost function tolerance", default_value=0.01, + usedefault=True) + useInTrans = traits.Int(position=7, argstr="%s", + desc="to initialize with existing xfm set as 1", + default_value=1) class RigidOutputSpec(TraitedSpec): @@ -85,21 +86,22 @@ class AffineInputSpec(CommandLineInputSpec): mandatory=True, position=1, argstr="%s", copyfile=False) similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', mandatory=True, position=2, argstr="%s", - desc="similarity metric") + desc="similarity metric", usedefault=True) samplingX = traits.Float(mandatory=True, position=3, argstr="%s", desc="dist between samp points (mm)", - default_value=4) + default_value=4, usedefault=True) samplingY = traits.Float(mandatory=True, position=4, argstr="%s", desc="dist between samp points (mm)", - default_value=4) + default_value=4, usedefault=True) samplingZ = traits.Float(mandatory=True, position=5, argstr="%s", desc="dist between samp points (mm)", - default_value=4) + default_value=4, usedefault=True) ftol = traits.Float(mandatory=True, position=6, argstr="%s", - desc="cost function tolerance", default_value=0.01) - useInTrans = traits.Float(position=7, argstr="%s", - desc="to initialize with existing xfm set as 1", - default_value=1) + desc="cost function tolerance", default_value=0.01, + usedefault=True) + useInTrans = traits.Int(position=7, argstr="%s", + desc="to initialize with existing xfm set as 1", + default_value=1) class AffineOutputSpec(TraitedSpec): From 01d9666e711ece130474804c580aeb1407661e0e Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Thu, 22 Mar 2018 13:13:00 -0700 Subject: [PATCH 05/53] incorporating changes to mandatory flag and specifying type of inputs --- nipype/interfaces/dtitk/registration.py | 47 +++++++++++++------------ nipype/interfaces/dtitk/utils.py | 23 ++++++------ 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index de32bd6242..8cb7de5114 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -145,16 +145,19 @@ class DiffeoInputSpec(CommandLineInputSpec): exists=True, position=0, argstr="%s") moving_file = File(desc="moving diffusion tensor image", exists=True, position=1, argstr="%s", copyfile=False) - mask = File(desc="mask", exists=True, position=2, argstr="%s") - legacy = traits.Float(desc="legacy parameter; always set to 1", - exists=True, mandatory=True, - position=3, default_value=1, argstr="%s") - n_iters = traits.Float(desc="number of iterations", - exists=True, mandatory=True, - position=4, default_value=6, argstr="%s") + mask_file = File(desc="mask", exists=True, position=2, argstr="%s") + legacy = traits.Int(desc="legacy parameter; always set to 1", + exists=True, mandatory=True, + position=3, default_value=1, argstr="%s", + usedefault=True) + n_iters = traits.Int(desc="number of iterations", + exists=True, mandatory=True, + position=4, default_value=6, argstr="%s", + usedefault=True) ftol = traits.Float(desc="iteration for the optimization to stop", exists=True, mandatory=True, - position=5, default_value=0.002, argstr="%s") + position=5, default_value=0.002, argstr="%s", + usedefault=True) class DiffeoOutputSpec(TraitedSpec): @@ -193,16 +196,16 @@ def _list_outputs(self): class ComposeXfmInputSpec(CommandLineInputSpec): in_df = File(desc='diffeomorphic file.df.nii.gz', exists=True, - position=1, argstr="-df %s", copyfile=False) + position=1, argstr="-df %s", copyfile=False) in_aff = File(desc='affine file.aff', exists=True, - position=0, argstr="-aff %s") + position=0, argstr="-aff %s") out_file = traits.Str(desc='output_path', exists=True, position=2, argstr="-out %s", name_source="in_df", name_template="%s_comboaff.nii.gz") class ComposeXfmOutputSpec(TraitedSpec): - out_file = File(desc='cheese', exists=True) + out_file = File(exists=True) class ComposeXfmTask(CommandLineDtitk): @@ -231,11 +234,11 @@ def _list_outputs(self): class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): in_tensor = File(desc='moving tensor', exists=True, - position=0, argstr="-in %s") + position=0, argstr="-in %s") in_xfm = File(desc='transform to apply', exists=True, position=1, argstr="-trans %s") in_target = File(desc='', exists=True, position=2, - argstr="-target %s") + argstr="-target %s") out_file = traits.Str(desc='', exists=True, position=3, argstr="-out %s", name_source="in_tensor", name_template="%s_diffeoxfmd.nii.gz") @@ -266,18 +269,18 @@ class diffeoSymTensor3DVolTask(CommandLineDtitk): class affSymTensor3DVolInputSpec(CommandLineInputSpec): in_tensor = File(desc='moving tensor', exists=True, - position=0, argstr="-in %s") + position=0, argstr="-in %s") in_xfm = File(desc='transform to apply', exists=True, - position=1, argstr="-trans %s") + position=1, argstr="-trans %s") in_target = File(desc='', exists=True, position=2, - argstr="-target %s") + argstr="-target %s") out_file = traits.Str(desc='', exists=True, position=3, argstr="-out %s", name_source="in_tensor", name_template="%s_affxfmd.nii.gz") class affSymTensor3DVolOutputSpec(TraitedSpec): - out_file = File(desc='cheese', exists=True) + out_file = File(exists=True) class affSymTensor3DVolTask(CommandLineDtitk): @@ -300,9 +303,9 @@ class affSymTensor3DVolTask(CommandLineDtitk): class affScalarVolInputSpec(CommandLineInputSpec): in_volume = File(desc='moving volume', exists=True, - position=0, argstr="-in %s") + position=0, argstr="-in %s") in_xfm = File(desc='transform to apply', exists=True, - position=1, argstr="-trans %s") + position=1, argstr="-trans %s") in_target = File(desc='', position=2, argstr="-target %s") out_file = traits.Str(desc='', position=3, argstr="-out %s", name_source="in_volume", @@ -344,11 +347,11 @@ class diffeoScalarVolInputSpec(CommandLineInputSpec): in_vsize = File(desc='', exists=True, position=4, argstr="-vsize %s") in_flip = File(desc='', exists=True, position=5, - argstr="-flip %s") + argstr="-flip %s") in_type = File(desc='', exists=True, position=6, - argstr="-type %s") + argstr="-type %s") in_interp = File(desc='0 trilin, 1 NN', exists=True, - position=7, argstr="-interp %s") + position=7, argstr="-interp %s") class diffeoScalarVolOutputSpec(TraitedSpec): diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index 15b8077c4e..925d4b388d 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -21,7 +21,8 @@ class TVAdjustOriginInputSpec(CommandLineInputSpec): in_file = File(desc="image to resample", exists=True, mandatory=True, position=0, argstr="-in %s") out_file = traits.Str(desc='output path', position=1, argstr="-out %s", - namesource=['in_file'], name_template='%s_originzero') + namesource=['in_file'], + name_template='%s_originzero') origin = traits.Str(desc='xyz voxel size', position=4, argstr='-origin %s') @@ -59,7 +60,7 @@ class TVAdjustVoxSpInputSpec(CommandLineInputSpec): target = traits.Str(desc='target volume', mandaotry=True, position=2, argstr="-target %s") vsize = traits.Str(desc='resampled voxel size', mandatory=True, - position=3, argstr="-vsize %s") + position=3, argstr="-vsize %s") class TVAdjustVoxSpOutputSpec(TraitedSpec): @@ -87,11 +88,11 @@ class TVAdjustVoxSpTask(CommandLineDtitk): class SVAdjustVoxSpInputSpec(CommandLineInputSpec): in_file = File(desc="image to resample", exists=True, - mandatory=True, position=0, argstr="-in %s") + mandatory=True, position=0, argstr="-in %s") in_target = File(desc='target volume', mandatory=True, - position=2, argstr="-target %s") + position=2, argstr="-target %s") in_voxsz = traits.Str(desc='resampled voxel size', mandatory=True, - position=3, argstr="-vsize %s") + position=3, argstr="-vsize %s") out_file = traits.Str(desc='output path', position=1, argstr="-out %s", name_source="in_file", name_template='%s_reslice', keep_extension=True) @@ -122,11 +123,11 @@ class SVAdjustVoxSpTask(CommandLineDtitk): class TVResampleInputSpec(CommandLineInputSpec): in_file = File(desc="image to resample", exists=True, - mandatory=True, position=0, argstr="-in %s") + mandatory=True, position=0, argstr="-in %s") in_arraysz = traits.Str(desc='resampled array size', exists=True, - position=1, argstr="-size %s") + position=1, argstr="-size %s") in_voxsz = traits.Str(desc='resampled voxel size', exists=True, - position=2, argstr="-vsize %s") + position=2, argstr="-vsize %s") out_file = traits.Str(desc='output path', position=3, argstr="-out %s", name_source="in_file", name_template="%s_resampled", keep_extesnion=True) @@ -181,9 +182,9 @@ class SVResampleTask(CommandLineDtitk): class TVtoolInputSpec(CommandLineInputSpec): in_file = File(desc="image to resample", exists=True, - position=0, argstr="-in %s") + position=0, argstr="-in %s") in_flag = traits.Enum('fa', 'tr', 'ad', 'rd', 'pd', 'rgb', exists=True, - position=1, argstr="-%s", desc='') + position=1, argstr="-%s", desc='') class TVtoolOutputSpec(TraitedSpec): @@ -228,7 +229,7 @@ def _gen_filename(self, name): class BinThreshInputSpec(CommandLineInputSpec): in_file = File(desc='', exists=True, position=0, - argstr="%s") + argstr="%s") out_file = traits.Str(desc='', position=1, argstr="%s", keep_extension=True, name_source='in_file', name_template='%s_bin') From a913e6f166645b3586a2d34f9d75c23d051a17f2 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Thu, 22 Mar 2018 15:36:54 -0700 Subject: [PATCH 06/53] fixed TVAdjustVoxelspace; removed AdjustOrigin because it's redundant --- nipype/interfaces/dtitk/__init__.py | 2 +- nipype/interfaces/dtitk/utils.py | 52 ++++++----------------------- 2 files changed, 12 insertions(+), 42 deletions(-) diff --git a/nipype/interfaces/dtitk/__init__.py b/nipype/interfaces/dtitk/__init__.py index e3f3cb7aab..1b77a112b9 100644 --- a/nipype/interfaces/dtitk/__init__.py +++ b/nipype/interfaces/dtitk/__init__.py @@ -10,6 +10,6 @@ ComposeXfmTask, diffeoSymTensor3DVolTask, affSymTensor3DVolTask, affScalarVolTask, diffeoScalarVolTask) -from .utils import (TVAdjustOriginTask, TVAdjustVoxSpTask, +from .utils import (TVAdjustVoxSpTask, SVAdjustVoxSpTask, TVResampleTask, SVResampleTask, TVtoolTask, BinThreshTask) diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index 925d4b388d..3e46f47954 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -17,50 +17,20 @@ from .base import CommandLineDtitk -class TVAdjustOriginInputSpec(CommandLineInputSpec): - in_file = File(desc="image to resample", exists=True, mandatory=True, - position=0, argstr="-in %s") - out_file = traits.Str(desc='output path', position=1, argstr="-out %s", - namesource=['in_file'], - name_template='%s_originzero') - origin = traits.Str(desc='xyz voxel size', - position=4, argstr='-origin %s') - - -class TVAdjustOriginOutputSpec(TraitedSpec): - out_file = File(exists=True) - - -class TVAdjustOriginTask(CommandLineDtitk): - """ - Moves the origin of a tensor volume to zero - - Example - ------- - - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.TVAdjustOriginTask() - >>> node.inputs.in_file = 'diffusion.nii' - >>> node.run() # doctest: +SKIP - """ - - input_spec = TVAdjustOriginInputSpec - output_spec = TVAdjustOriginOutputSpec - _cmd = 'TVAdjustVoxelspace' - - class TVAdjustVoxSpInputSpec(CommandLineInputSpec): - in_file = File(desc="image to resample", exists=True, mandatory=True, + in_file = File(desc="tensor to resample", exists=True, mandatory=True, position=0, argstr="-in %s") out_file = traits.Str(genfile=True, desc='output path', position=1, argstr="-out %s", name_source='in_file', - name_template='%s_reslice', keep_extension=True) - origin = traits.Str(desc='xyz voxel size', mandatory=True, - position=4, argstr='-origin %s') - target = traits.Str(desc='target volume', mandaotry=True, - position=2, argstr="-target %s") - vsize = traits.Str(desc='resampled voxel size', mandatory=True, - position=3, argstr="-vsize %s") + name_template='%s_avs', keep_extension=True) + target = traits.File(desc='target volume', + position=2, argstr="-target %s") + vsize = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='resampled voxel size', + position=3, argstr="-vsize %f %f %f") + origin = traits.Tuple((0, 0, 0), + desc='xyz voxel size', position=4, + argstr='-origin %f %f %f', usedefault=True) class TVAdjustVoxSpOutputSpec(TraitedSpec): @@ -130,7 +100,7 @@ class TVResampleInputSpec(CommandLineInputSpec): position=2, argstr="-vsize %s") out_file = traits.Str(desc='output path', position=3, argstr="-out %s", name_source="in_file", name_template="%s_resampled", - keep_extesnion=True) + keep_extension=True) class TVResampleOutputSpec(TraitedSpec): From 1ef2ca626e5e566594ac6e7ed39925dd39739fc3 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Thu, 22 Mar 2018 16:02:49 -0700 Subject: [PATCH 07/53] TVResample fixed --- nipype/interfaces/dtitk/utils.py | 80 ++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index 3e46f47954..14a2735fbf 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -23,13 +23,13 @@ class TVAdjustVoxSpInputSpec(CommandLineInputSpec): out_file = traits.Str(genfile=True, desc='output path', position=1, argstr="-out %s", name_source='in_file', name_template='%s_avs', keep_extension=True) - target = traits.File(desc='target volume', - position=2, argstr="-target %s") + target_file = traits.File(desc='target volume to match', + position=2, argstr="-target %s") vsize = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), - desc='resampled voxel size', + desc='xyz voxel size (superseded by target)', position=3, argstr="-vsize %f %f %f") origin = traits.Tuple((0, 0, 0), - desc='xyz voxel size', position=4, + desc='xyz origin (superseded by target)', position=4, argstr='-origin %f %f %f', usedefault=True) @@ -54,6 +54,46 @@ class TVAdjustVoxSpTask(CommandLineDtitk): _cmd = 'TVAdjustVoxelspace' +class TVResampleInputSpec(CommandLineInputSpec): + in_file = File(desc="image to resample", exists=True, + mandatory=True, position=0, argstr="-in %s") + out_file = traits.Str(desc='output path', position=1, + name_source="in_file", name_template="%s_resampled", + keep_extension=True, argstr="-out %s") + target_file = File(desc='specs read from the target volume', position=2, + argstr="-target %s") + align = traits.Str('center', position=3, argstr="-align %s") + interp = traits.Enum('LEI', 'EI', position=4) + arraysz = traits.Tuple((128, 128, 64), desc='resampled array size', + position=5, argstr="-size %s") + voxsz = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='resampled voxel size (superseded by target)', + exists=True, position=6, argstr="-vsize %f %f %f") + origin = traits.Tuple((0, 0, 0), + desc='xyz origin (superseded by target)', position=4, + argstr='-origin %f %f %f') + + +class TVResampleOutputSpec(TraitedSpec): + out_file = File(exists=True) + + +class TVResampleTask(CommandLineDtitk): + """ + Resamples a tensor volume + + Example + ------- + + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.TVResampleTask() + >>> node.inputs.in_file = 'diffusion.nii.gz' + >>> node.run() # doctest: +SKIP + """ + input_spec = TVResampleInputSpec + output_spec = TVResampleOutputSpec + _cmd = 'TVResample' + # TODO not using these yet... need to be tested class SVAdjustVoxSpInputSpec(CommandLineInputSpec): @@ -91,38 +131,6 @@ class SVAdjustVoxSpTask(CommandLineDtitk): _cmd = 'SVAdjustVoxelspace' -class TVResampleInputSpec(CommandLineInputSpec): - in_file = File(desc="image to resample", exists=True, - mandatory=True, position=0, argstr="-in %s") - in_arraysz = traits.Str(desc='resampled array size', exists=True, - position=1, argstr="-size %s") - in_voxsz = traits.Str(desc='resampled voxel size', exists=True, - position=2, argstr="-vsize %s") - out_file = traits.Str(desc='output path', position=3, argstr="-out %s", - name_source="in_file", name_template="%s_resampled", - keep_extension=True) - - -class TVResampleOutputSpec(TraitedSpec): - out_file = File(exists=True) - - -class TVResampleTask(CommandLineDtitk): - """ - Resamples a tensor volume - - Example - ------- - - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.TVResampleTask() - >>> node.inputs.in_file = 'diffusion.nii.gz' - >>> node.run() # doctest: +SKIP - """ - input_spec = TVResampleInputSpec - output_spec = TVResampleOutputSpec - _cmd = 'TVResample' - class SVResampleInputSpec(TVResampleInputSpec): pass From 50a9f1cdaa13a8ed96c603d93df70e9a0f7e2d68 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Fri, 23 Mar 2018 15:33:05 -0700 Subject: [PATCH 08/53] more modifications to get all interfaces working/standardized (not done yet) --- nipype/interfaces/dtitk/registration.py | 2 +- nipype/interfaces/dtitk/utils.py | 31 ++++++++----------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 8cb7de5114..6b7ff7f0d8 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -245,7 +245,7 @@ class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): class diffeoSymTensor3DVolOutputSpec(TraitedSpec): - out_file = File(desc='cheese', exists=True) + out_file = File(exists=True) class diffeoSymTensor3DVolTask(CommandLineDtitk): diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index 14a2735fbf..d8f39de1d6 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -64,8 +64,9 @@ class TVResampleInputSpec(CommandLineInputSpec): argstr="-target %s") align = traits.Str('center', position=3, argstr="-align %s") interp = traits.Enum('LEI', 'EI', position=4) - arraysz = traits.Tuple((128, 128, 64), desc='resampled array size', - position=5, argstr="-size %s") + arraysz = traits.Tuple((128, 128, 64), + desc='resampled array size', position=5, + argstr="-size %f %f %f") voxsz = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), desc='resampled voxel size (superseded by target)', exists=True, position=6, argstr="-vsize %f %f %f") @@ -161,8 +162,14 @@ class SVResampleTask(CommandLineDtitk): class TVtoolInputSpec(CommandLineInputSpec): in_file = File(desc="image to resample", exists=True, position=0, argstr="-in %s") + + '''Note: there are a lot more options here; not putting all of them in''' in_flag = traits.Enum('fa', 'tr', 'ad', 'rd', 'pd', 'rgb', exists=True, - position=1, argstr="-%s", desc='') + position=2, argstr="-%s", desc='') + out_file = traits.Str(exists=True, position=1, + argstr="-out %s", name_source=["in_file", "in_flag"], + name_template="%s_tvt_%s.nii.gz") + class TVtoolOutputSpec(TraitedSpec): @@ -186,24 +193,6 @@ class TVtoolTask(CommandLineDtitk): output_spec = TVtoolOutputSpec _cmd = 'TVtool' - def _list_outputs(self): - _suffix = self.inputs.in_flag - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - if not isdefined(self.inputs.out_file): - outputs["out_file"] = self._gen_fname(self.inputs.in_file, - suffix=_suffix, - ext='.' + '.'.join( - self.inputs.in_file. - split(".")[1:])) - outputs["out_file"] = os.path.abspath(outputs["out_file"]) - return outputs - - def _gen_filename(self, name): - if name == "out_file": - return self._list_outputs()["out_file"] - return None - class BinThreshInputSpec(CommandLineInputSpec): in_file = File(desc='', exists=True, position=0, From 6bb86e49c82575eb460e68281602a9212f74eb83 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Sun, 25 Mar 2018 13:44:47 -0700 Subject: [PATCH 09/53] added cmdline to doctest, fixed ComposeXfm interface --- nipype/interfaces/dtitk/registration.py | 30 +++++++++++++++---------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 6b7ff7f0d8..29ac6eae90 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -15,6 +15,7 @@ import os from .base import CommandLineDtitk +#TODO: add cmdline expectation to all tests class RigidInputSpec(CommandLineInputSpec): fixed_file = File(desc="fixed diffusion tensor image", @@ -46,6 +47,7 @@ class RigidOutputSpec(TraitedSpec): out_file = File(exists=True) out_file_xfm = File(exists=True) +# TODO: try true/false so we can make useInTrans = False for rigid class RigidTask(CommandLineDtitk): """Performs rigid registration between two tensor volumes @@ -63,6 +65,8 @@ class RigidTask(CommandLineDtitk): >>> node.inputs.samplingZ = 4 >>> node.inputs.ftol = 0.01 >>> node.inputs.useInTrans = 1 + >>> node.cmdline # doctest: +ELLIPSIS + 'dti_rigid_reg diffusion.nii.gz diffusion2.nii.gz EDS 4 4 4 0.01 1' >>> node.run() # doctest: +SKIP """ input_spec = RigidInputSpec @@ -125,6 +129,8 @@ class AffineTask(CommandLineDtitk): >>> node.inputs.samplingZ = 4 >>> node.inputs.ftol = 0.01 >>> node.inputs.useInTrans = 1 + >>> node.cmdline # doctest: +ELLIPSIS + 'dti_affine_reg diffusion.nii.gz diffusion2.nii.gz EDS 4 4 4 0.01 1' >>> node.run() # doctest: +SKIP """ input_spec = AffineInputSpec @@ -179,6 +185,8 @@ class DiffeoTask(CommandLineDtitk): >>> node.inputs.legacy = 1 >>> node.inputs.n_iters = 6 >>> node.inputs.ftol = 0.002 + >>> node.cmdline # doctest: +ELLIPSIS + dti_diffeomorphic_reg diffusion.nii.gz diffusion2.nii.gz mask.nii.gz 1 6 0.002 >>> node.run() # doctest: +SKIP """ input_spec = DiffeoInputSpec @@ -195,13 +203,13 @@ def _list_outputs(self): class ComposeXfmInputSpec(CommandLineInputSpec): - in_df = File(desc='diffeomorphic file.df.nii.gz', exists=True, - position=1, argstr="-df %s", copyfile=False) - in_aff = File(desc='affine file.aff', exists=True, - position=0, argstr="-aff %s") + in_df = File(desc='diffeomorphic warp diffeo_xfm.df.nii.gz', exists=True, + position=0, argstr="-df %s", copyfile=False, mandatory=True) + in_aff = File(desc='affine_xfm.aff', exists=True, + position=1, argstr="-aff %s", mandatory=True) out_file = traits.Str(desc='output_path', exists=True, position=2, argstr="-out %s", name_source="in_df", - name_template="%s_comboaff.nii.gz") + name_template="%s_aff.df.nii.gz") class ComposeXfmOutputSpec(TraitedSpec): @@ -217,20 +225,18 @@ class ComposeXfmTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.ComposeXfmTask() - >>> node.inputs.in_df = 'ants_Warp.nii.gz' - >>> node.inputs.in_aff= 'ants_Affine.txt' + >>> node.inputs.in_df = 'myxfm.df.nii.gz' + >>> node.inputs.in_aff= 'myxfm.aff' + >>> node.cmdline # doctest: +ELLIPSIS + 'dfRightComposeAffine -df myxfm.df.nii.gz -aff myxfm.aff -out myxfm.df_aff.df.nii.gz' >>> node.run() # doctest: +SKIP """ input_spec = ComposeXfmInputSpec output_spec = ComposeXfmOutputSpec _cmd = 'dfRightComposeAffine' - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.in_df.replace('.df.nii.gz', - '_combo.df.nii.gz') - return outputs +# TODO: these haven't been used yet; need to be tested class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): in_tensor = File(desc='moving tensor', exists=True, From 197b7937cf11988c711b088db940f9419a99d1ac Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Sun, 25 Mar 2018 15:04:33 -0700 Subject: [PATCH 10/53] Fixed TVtool --- nipype/interfaces/dtitk/registration.py | 2 +- nipype/interfaces/dtitk/utils.py | 82 ++++++++++++++----------- 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 29ac6eae90..21f72482c8 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -236,7 +236,7 @@ class ComposeXfmTask(CommandLineDtitk): _cmd = 'dfRightComposeAffine' -# TODO: these haven't been used yet; need to be tested +# TODO: these haven't been used yet; need to be tested (ALL BELOW) class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): in_tensor = File(desc='moving tensor', exists=True, diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index d8f39de1d6..87a6cd9ef7 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -95,6 +95,53 @@ class TVResampleTask(CommandLineDtitk): output_spec = TVResampleOutputSpec _cmd = 'TVResample' + +class TVtoolInputSpec(CommandLineInputSpec): + in_file = File(desc="image to resample", exists=True, + position=0, argstr="-in %s", mandatory=True) + # out_file = traits.Str(exists=True, position=1, + # argstr="-out %s", name_source="in_file", + # name_template="%s_tvt.nii.gz" + '''NOTE: there are a lot more options here; not putting all of them in''' + in_flag = traits.Enum('fa', 'tr', 'ad', 'rd', 'pd', 'rgb', exists=True, + position=2, argstr="-%s", desc='') + out_file = traits.Str(exists=True, position=1, + argstr="-out %s", genfile=True) + + +class TVtoolOutputSpec(TraitedSpec): + out_file = File() + + +class TVtoolTask(CommandLineDtitk): + """ + Calculates a tensor metric volume from a tensor volume + + Example + ------- + + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.TVtoolTask() + >>> node.inputs.in_file = 'diffusion.nii' + >>> node.inputs.in_flag = 'fa' + >>> node.run() # doctest: +SKIP + """ + input_spec = TVtoolInputSpec + output_spec = TVtoolOutputSpec + _cmd = 'TVtool' + + def _list_outputs(self): + outputs = self._outputs().get() + if not isdefined(self.inputs.out_file): + outputs['out_file'] = self._gen_filename('out_file') + else: + outputs['out_file'] = self.inputs.out_file + self.inputs.in_flag+'.nii.gz' + return outputs + + def _gen_filename(self, name): + basename = os.path.basename(self.inputs.in_file).split('.')[0] + return basename + '_'+self.inputs.in_flag+'.nii.gz' + # TODO not using these yet... need to be tested class SVAdjustVoxSpInputSpec(CommandLineInputSpec): @@ -159,41 +206,6 @@ class SVResampleTask(CommandLineDtitk): _cmd = 'SVResample' -class TVtoolInputSpec(CommandLineInputSpec): - in_file = File(desc="image to resample", exists=True, - position=0, argstr="-in %s") - - '''Note: there are a lot more options here; not putting all of them in''' - in_flag = traits.Enum('fa', 'tr', 'ad', 'rd', 'pd', 'rgb', exists=True, - position=2, argstr="-%s", desc='') - out_file = traits.Str(exists=True, position=1, - argstr="-out %s", name_source=["in_file", "in_flag"], - name_template="%s_tvt_%s.nii.gz") - - - -class TVtoolOutputSpec(TraitedSpec): - out_file = File(exists=True) - - -class TVtoolTask(CommandLineDtitk): - """ - Calculates a tensor metric volume from a tensor volume - - Example - ------- - - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.TVtoolTask() - >>> node.inputs.in_file = 'diffusion.nii' - >>> node.inputs.in_flag = 'fa' - >>> node.run() # doctest: +SKIP - """ - input_spec = TVtoolInputSpec - output_spec = TVtoolOutputSpec - _cmd = 'TVtool' - - class BinThreshInputSpec(CommandLineInputSpec): in_file = File(desc='', exists=True, position=0, argstr="%s") From e670fe16ec11d84ffd612d5d67858ccac387d344 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Sun, 25 Mar 2018 15:28:30 -0700 Subject: [PATCH 11/53] Incorporated recommendations from @effigies. Fixed TVResample interface --- nipype/interfaces/dtitk/utils.py | 47 ++++++++++++++++---------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index 87a6cd9ef7..d0dc831796 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -25,12 +25,12 @@ class TVAdjustVoxSpInputSpec(CommandLineInputSpec): name_template='%s_avs', keep_extension=True) target_file = traits.File(desc='target volume to match', position=2, argstr="-target %s") - vsize = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), - desc='xyz voxel size (superseded by target)', - position=3, argstr="-vsize %f %f %f") + voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='xyz voxel size (superseded by target)', + position=3, argstr="-vsize %g %g %g") origin = traits.Tuple((0, 0, 0), desc='xyz origin (superseded by target)', position=4, - argstr='-origin %f %f %f', usedefault=True) + argstr='-origin %g %g %g', usedefault=True) class TVAdjustVoxSpOutputSpec(TraitedSpec): @@ -56,23 +56,26 @@ class TVAdjustVoxSpTask(CommandLineDtitk): class TVResampleInputSpec(CommandLineInputSpec): in_file = File(desc="image to resample", exists=True, - mandatory=True, position=0, argstr="-in %s") - out_file = traits.Str(desc='output path', position=1, + mandatory=True, argstr="-in %s") + out_file = traits.Str(desc='output path', name_source="in_file", name_template="%s_resampled", keep_extension=True, argstr="-out %s") - target_file = File(desc='specs read from the target volume', position=2, - argstr="-target %s") - align = traits.Str('center', position=3, argstr="-align %s") - interp = traits.Enum('LEI', 'EI', position=4) - arraysz = traits.Tuple((128, 128, 64), - desc='resampled array size', position=5, - argstr="-size %f %f %f") - voxsz = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), - desc='resampled voxel size (superseded by target)', - exists=True, position=6, argstr="-vsize %f %f %f") - origin = traits.Tuple((0, 0, 0), - desc='xyz origin (superseded by target)', position=4, - argstr='-origin %f %f %f') + target_file = File(desc='specs read from the target volume', + argstr="-target %s", + xor=['array_size', 'voxel_size', 'origin']) + align = traits.Enum('center', 'origin', argstr="-align %s", + desc='how to align output volume to input volume') + interpolation = traits.Enum('LEI', 'EI', argstr="-interp %s", + desc='Log Euclidean Euclidean Interpolation') + array_size = traits.Tuple((traits.Int(), traits.Int(), traits.Int()), + desc='resampled array size', xor=['target_file'], + argstr="-size %d %d %d") + voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='resampled voxel size', xor=['target_file'], + argstr="-vsize %g %g %g") + origin = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='xyz origin', xor=['target_file'], + argstr='-origin %g %g %g') class TVResampleOutputSpec(TraitedSpec): @@ -99,9 +102,6 @@ class TVResampleTask(CommandLineDtitk): class TVtoolInputSpec(CommandLineInputSpec): in_file = File(desc="image to resample", exists=True, position=0, argstr="-in %s", mandatory=True) - # out_file = traits.Str(exists=True, position=1, - # argstr="-out %s", name_source="in_file", - # name_template="%s_tvt.nii.gz" '''NOTE: there are a lot more options here; not putting all of them in''' in_flag = traits.Enum('fa', 'tr', 'ad', 'rd', 'pd', 'rgb', exists=True, position=2, argstr="-%s", desc='') @@ -135,7 +135,7 @@ def _list_outputs(self): if not isdefined(self.inputs.out_file): outputs['out_file'] = self._gen_filename('out_file') else: - outputs['out_file'] = self.inputs.out_file + self.inputs.in_flag+'.nii.gz' + outputs['out_file'] = self.inputs.out_file return outputs def _gen_filename(self, name): @@ -144,6 +144,7 @@ def _gen_filename(self, name): # TODO not using these yet... need to be tested + class SVAdjustVoxSpInputSpec(CommandLineInputSpec): in_file = File(desc="image to resample", exists=True, mandatory=True, position=0, argstr="-in %s") From b1581ab019971ce2125b06f6d0711989de123d7c Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Sun, 25 Mar 2018 16:15:36 -0700 Subject: [PATCH 12/53] BinThresh fixed; xor added to TVAdjustVoxelSpace --- nipype/interfaces/dtitk/registration.py | 3 +- nipype/interfaces/dtitk/utils.py | 110 +++++++++++++----------- 2 files changed, 64 insertions(+), 49 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 21f72482c8..d71c108dbd 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -15,7 +15,8 @@ import os from .base import CommandLineDtitk -#TODO: add cmdline expectation to all tests +# TODO: add cmdline expectation to all tests + class RigidInputSpec(CommandLineInputSpec): fixed_file = File(desc="fixed diffusion tensor image", diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index d0dc831796..b5c052c35c 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -19,18 +19,20 @@ class TVAdjustVoxSpInputSpec(CommandLineInputSpec): in_file = File(desc="tensor to resample", exists=True, mandatory=True, - position=0, argstr="-in %s") - out_file = traits.Str(genfile=True, desc='output path', position=1, + argstr="-in %s") + out_file = traits.Str(genfile=True, desc='output path', argstr="-out %s", name_source='in_file', name_template='%s_avs', keep_extension=True) target_file = traits.File(desc='target volume to match', - position=2, argstr="-target %s") + argstr="-target %s", + xor=['voxel_size', 'origin']) voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), desc='xyz voxel size (superseded by target)', - position=3, argstr="-vsize %g %g %g") + argstr="-vsize %g %g %g", xor=['target_file']) origin = traits.Tuple((0, 0, 0), - desc='xyz origin (superseded by target)', position=4, - argstr='-origin %g %g %g', usedefault=True) + desc='xyz origin (superseded by target)', + argstr='-origin %g %g %g', usedefault=True, + xor=['target_file']) class TVAdjustVoxSpOutputSpec(TraitedSpec): @@ -47,6 +49,9 @@ class TVAdjustVoxSpTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.TVAdjustVoxSpTask() >>> node.inputs.in_file = 'diffusion.nii' + >>> node.inputs.target_file = 'diffusion2.nii' + >>> node.cmdline # doctest: +ELLIPSIS + 'TVAdjustVoxelspace -in diffusion.nii -out diffusion_avs.nii -target 'diffusion2.nii'' >>> node.run() # doctest: +SKIP """ input_spec = TVAdjustVoxSpInputSpec @@ -92,6 +97,9 @@ class TVResampleTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.TVResampleTask() >>> node.inputs.in_file = 'diffusion.nii.gz' + >>> node.inputs.target_file = 'diffusion.nii.gz' + >>> node.cmdline # doctest: +ELLIPSIS + 'TVResample -in diffusion.nii -out diffusion_resampled.nii -target 'diffusion2.nii'' >>> node.run() # doctest: +SKIP """ input_spec = TVResampleInputSpec @@ -100,12 +108,12 @@ class TVResampleTask(CommandLineDtitk): class TVtoolInputSpec(CommandLineInputSpec): - in_file = File(desc="image to resample", exists=True, - position=0, argstr="-in %s", mandatory=True) + in_file = File(desc="image to resample", exists=True, argstr="-in %s", + mandatory=True) '''NOTE: there are a lot more options here; not putting all of them in''' in_flag = traits.Enum('fa', 'tr', 'ad', 'rd', 'pd', 'rgb', exists=True, - position=2, argstr="-%s", desc='') - out_file = traits.Str(exists=True, position=1, + argstr="-%s", desc='') + out_file = traits.Str(exists=True, argstr="-out %s", genfile=True) @@ -124,6 +132,8 @@ class TVtoolTask(CommandLineDtitk): >>> node = dtitk.TVtoolTask() >>> node.inputs.in_file = 'diffusion.nii' >>> node.inputs.in_flag = 'fa' + >>> node.cmdline # doctest: +ELLIPSIS + 'TVtool -in diffusion.nii -fa -out diffusion_fa.nii.gz' >>> node.run() # doctest: +SKIP """ input_spec = TVtoolInputSpec @@ -142,15 +152,55 @@ def _gen_filename(self, name): basename = os.path.basename(self.inputs.in_file).split('.')[0] return basename + '_'+self.inputs.in_flag+'.nii.gz' + +class BinThreshInputSpec(CommandLineInputSpec): + in_file = File(desc='Image to threshold/binarize', exists=True, + position=0, argstr="%s") + out_file = traits.Str(desc='', position=1, argstr="%s", + keep_extension=True, name_source='in_file', + name_template='%s_thrbin') + lower_bound = traits.Float(0.01, position=2, argstr="%g") + upper_bound = traits.Float(100, position=3, argstr="%g") + inside_value = traits.Float(1, position=4, argstr="%g", usedefault=True) + outside_value = traits.Float(0, position=5, argstr="%g", usedefault=True) + + +class BinThreshOutputSpec(TraitedSpec): + out_file = File(exists=True) + + +class BinThreshTask(CommandLineDtitk): + """ + Binarizes an image based on parameters + + Example + ------- + + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.BinThreshTask() + >>> node.inputs.in_file = 'diffusion.nii' + >>> node.inputs.lower_bound = 0 + >>> node.inputs.upper_bound = 100 + >>> node.inputs.inside_value = 1 + >>> node.inputs.outside_value = 0 + >>> node.cmdline + 'BinaryThresholdImageFilter diffusion.nii diffusion_bin.nii 0.0 100.0 1.0 0.0' + >>> node.run() # doctest: +SKIP + """ + + input_spec = BinThreshInputSpec + output_spec = BinThreshOutputSpec + _cmd = 'BinaryThresholdImageFilter' + # TODO not using these yet... need to be tested class SVAdjustVoxSpInputSpec(CommandLineInputSpec): in_file = File(desc="image to resample", exists=True, mandatory=True, position=0, argstr="-in %s") - in_target = File(desc='target volume', mandatory=True, + target_file = File(desc='target volume', mandatory=True, position=2, argstr="-target %s") - in_voxsz = traits.Str(desc='resampled voxel size', mandatory=True, + voxel_size = traits.Str(desc='resampled voxel size', mandatory=True, position=3, argstr="-vsize %s") out_file = traits.Str(desc='output path', position=1, argstr="-out %s", name_source="in_file", name_template='%s_reslice', @@ -205,39 +255,3 @@ class SVResampleTask(CommandLineDtitk): input_spec = SVResampleInputSpec output_spec = SVResampleOutputSpec _cmd = 'SVResample' - - -class BinThreshInputSpec(CommandLineInputSpec): - in_file = File(desc='', exists=True, position=0, - argstr="%s") - out_file = traits.Str(desc='', position=1, argstr="%s", - keep_extension=True, name_source='in_file', - name_template='%s_bin') - in_numbers = traits.List(traits.Float, minlen=4, maxlen=4, - desc='LB UB inside_value outside_value', - position=2, argstr="%s") - - -class BinThreshOutputSpec(TraitedSpec): - out_file = File(exists=True) - - -class BinThreshTask(CommandLineDtitk): - """ - Binarizes an image based on parameters - - Example - ------- - - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.BinThreshTask() - >>> node.inputs.in_file = 'diffusion.nii' - >>> node.inputs.in_numbers = [0, 100, 1, 0] - >>> node.cmdline - 'BinaryThresholdImageFilter diffusion.nii diffusion_bin.nii 0.0 100.0 1.0 0.0' - >>> node.run() # doctest: +SKIP - """ - - input_spec = BinThreshInputSpec - output_spec = BinThreshOutputSpec - _cmd = 'BinaryThresholdImageFilter' From db590d513f9877e91db971cc51a2ac16a0d13d53 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Sun, 25 Mar 2018 16:55:36 -0700 Subject: [PATCH 13/53] compressed sampling to tuple input, switched use of previously calculated xfm to a boolean instead of integer --- nipype/interfaces/dtitk/registration.py | 53 ++++++++----------------- nipype/interfaces/dtitk/utils.py | 16 ++++---- 2 files changed, 26 insertions(+), 43 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index d71c108dbd..791985c4c1 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -15,8 +15,6 @@ import os from .base import CommandLineDtitk -# TODO: add cmdline expectation to all tests - class RigidInputSpec(CommandLineInputSpec): fixed_file = File(desc="fixed diffusion tensor image", @@ -27,21 +25,14 @@ class RigidInputSpec(CommandLineInputSpec): similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', mandatory=True, position=2, argstr="%s", desc="similarity metric", usedefault=True) - samplingX = traits.Float(mandatory=True, position=3, argstr="%s", - desc="dist between samp points (mm)", - default_value=4, usedefault=True) - samplingY = traits.Float(mandatory=True, position=4, argstr="%s", - desc="dist between samp points (mm)", - default_value=4, usedefault=True) - samplingZ = traits.Float(mandatory=True, position=5, argstr="%s", - desc="dist between samp points (mm)", - default_value=4, usedefault=True) - ftol = traits.Float(mandatory=True, position=6, argstr="%s", + samplingXYZ = traits.Tuple((4, 4, 4), mandatory=True, position=3, + argstr="%g %g %g", usedefault=True, + desc="dist between samp points (mm) (x,y,z)") + ftol = traits.Float(mandatory=True, position=4, argstr="%g", desc="cost function tolerance", default_value=0.01, usedefault=True) - useInTrans = traits.Int(position=7, argstr="%s", - desc="to initialize with existing xfm set as 1", - default_value=1) + useInTrans = traits.Bool(position=5, argstr="1", + desc="to initialize with existing xfm set as 1") class RigidOutputSpec(TraitedSpec): @@ -61,11 +52,9 @@ class RigidTask(CommandLineDtitk): >>> node.inputs.fixed_file = 'diffusion.nii.gz' >>> node.inputs.moving_file = 'diffusion2.nii.gz' >>> node.inputs.similarity_metric = 'EDS' - >>> node.inputs.samplingX = 4 - >>> node.inputs.samplingY = 4 - >>> node.inputs.samplingZ = 4 + >>> node.inputs.samplingXYZ = (4,4,4) >>> node.inputs.ftol = 0.01 - >>> node.inputs.useInTrans = 1 + >>> node.inputs.useInTrans = True >>> node.cmdline # doctest: +ELLIPSIS 'dti_rigid_reg diffusion.nii.gz diffusion2.nii.gz EDS 4 4 4 0.01 1' >>> node.run() # doctest: +SKIP @@ -92,21 +81,15 @@ class AffineInputSpec(CommandLineInputSpec): similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', mandatory=True, position=2, argstr="%s", desc="similarity metric", usedefault=True) - samplingX = traits.Float(mandatory=True, position=3, argstr="%s", - desc="dist between samp points (mm)", - default_value=4, usedefault=True) - samplingY = traits.Float(mandatory=True, position=4, argstr="%s", - desc="dist between samp points (mm)", - default_value=4, usedefault=True) - samplingZ = traits.Float(mandatory=True, position=5, argstr="%s", - desc="dist between samp points (mm)", - default_value=4, usedefault=True) - ftol = traits.Float(mandatory=True, position=6, argstr="%s", + samplingXYZ = traits.Tuple((4, 4, 4), mandatory=True, position=3, + argstr="%g %g %g", usedefault=True, + desc="dist between samp points (mm) (x,y,z)") + ftol = traits.Float(mandatory=True, position=4, argstr="%s", desc="cost function tolerance", default_value=0.01, usedefault=True) - useInTrans = traits.Int(position=7, argstr="%s", - desc="to initialize with existing xfm set as 1", - default_value=1) + useInTrans = traits.Bool(position=5, argstr="1", + desc="to initialize with existing xfm set as 1", + default_value=True, usedefault=True) class AffineOutputSpec(TraitedSpec): @@ -125,11 +108,9 @@ class AffineTask(CommandLineDtitk): >>> node.inputs.fixed_file = 'diffusion.nii.gz' >>> node.inputs.moving_file = 'diffusion2.nii.gz' >>> node.inputs.similarity_metric = 'EDS' - >>> node.inputs.samplingX = 4 - >>> node.inputs.samplingY = 4 - >>> node.inputs.samplingZ = 4 + >>> node.inputs.samplingXYZ = (4,4,4) >>> node.inputs.ftol = 0.01 - >>> node.inputs.useInTrans = 1 + >>> node.inputs.useInTrans = True >>> node.cmdline # doctest: +ELLIPSIS 'dti_affine_reg diffusion.nii.gz diffusion2.nii.gz EDS 4 4 4 0.01 1' >>> node.run() # doctest: +SKIP diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index b5c052c35c..c52dda0df8 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -155,14 +155,16 @@ def _gen_filename(self, name): class BinThreshInputSpec(CommandLineInputSpec): in_file = File(desc='Image to threshold/binarize', exists=True, - position=0, argstr="%s") + position=0, argstr="%s", mandatory=True) out_file = traits.Str(desc='', position=1, argstr="%s", keep_extension=True, name_source='in_file', name_template='%s_thrbin') - lower_bound = traits.Float(0.01, position=2, argstr="%g") - upper_bound = traits.Float(100, position=3, argstr="%g") - inside_value = traits.Float(1, position=4, argstr="%g", usedefault=True) - outside_value = traits.Float(0, position=5, argstr="%g", usedefault=True) + lower_bound = traits.Float(0.01, position=2, argstr="%g", mandatory=True) + upper_bound = traits.Float(100, position=3, argstr="%g", mandatory=True) + inside_value = traits.Float(1, position=4, argstr="%g", usedefault=True, + mandatory=True) + outside_value = traits.Float(0, position=5, argstr="%g", usedefault=True, + mandatory=True) class BinThreshOutputSpec(TraitedSpec): @@ -199,9 +201,9 @@ class SVAdjustVoxSpInputSpec(CommandLineInputSpec): in_file = File(desc="image to resample", exists=True, mandatory=True, position=0, argstr="-in %s") target_file = File(desc='target volume', mandatory=True, - position=2, argstr="-target %s") + position=2, argstr="-target %s") voxel_size = traits.Str(desc='resampled voxel size', mandatory=True, - position=3, argstr="-vsize %s") + position=3, argstr="-vsize %s") out_file = traits.Str(desc='output path', position=1, argstr="-out %s", name_source="in_file", name_template='%s_reslice', keep_extension=True) From f474554923e2a43e23befa701e580bf05deb2044 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Sun, 25 Mar 2018 18:08:04 -0700 Subject: [PATCH 14/53] affSymTensor3DVol interface fixed --- nipype/interfaces/dtitk/registration.py | 158 +++++++++++++----------- 1 file changed, 86 insertions(+), 72 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 791985c4c1..89aa230a53 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -39,7 +39,6 @@ class RigidOutputSpec(TraitedSpec): out_file = File(exists=True) out_file_xfm = File(exists=True) -# TODO: try true/false so we can make useInTrans = False for rigid class RigidTask(CommandLineDtitk): """Performs rigid registration between two tensor volumes @@ -49,14 +48,14 @@ class RigidTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.RigidTask() - >>> node.inputs.fixed_file = 'diffusion.nii.gz' - >>> node.inputs.moving_file = 'diffusion2.nii.gz' + >>> node.inputs.fixed_file = 'ten1.nii.gz' + >>> node.inputs.moving_file = 'ten2.nii.gz' >>> node.inputs.similarity_metric = 'EDS' >>> node.inputs.samplingXYZ = (4,4,4) >>> node.inputs.ftol = 0.01 >>> node.inputs.useInTrans = True >>> node.cmdline # doctest: +ELLIPSIS - 'dti_rigid_reg diffusion.nii.gz diffusion2.nii.gz EDS 4 4 4 0.01 1' + 'dti_rigid_reg ten1.nii.gz ten2.nii.gz EDS 4 4 4 0.01 1' >>> node.run() # doctest: +SKIP """ input_spec = RigidInputSpec @@ -105,14 +104,14 @@ class AffineTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.AffineTask() - >>> node.inputs.fixed_file = 'diffusion.nii.gz' - >>> node.inputs.moving_file = 'diffusion2.nii.gz' + >>> node.inputs.fixed_file = 'ten1.nii.gz' + >>> node.inputs.moving_file = 'ten2.nii.gz' >>> node.inputs.similarity_metric = 'EDS' >>> node.inputs.samplingXYZ = (4,4,4) >>> node.inputs.ftol = 0.01 >>> node.inputs.useInTrans = True >>> node.cmdline # doctest: +ELLIPSIS - 'dti_affine_reg diffusion.nii.gz diffusion2.nii.gz EDS 4 4 4 0.01 1' + 'dti_affine_reg ten1.nii.gz ten2.nii.gz EDS 4 4 4 0.01 1' >>> node.run() # doctest: +SKIP """ input_spec = AffineInputSpec @@ -161,14 +160,14 @@ class DiffeoTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.DiffeoTask() - >>> node.inputs.fixed_file = 'diffusion.nii.gz' - >>> node.inputs.moving_file = 'diffusion2.nii.gz' + >>> node.inputs.fixed_file = 'ten1.nii.gz' + >>> node.inputs.moving_file = 'ten2.nii.gz' >>> node.inputs.mask = 'mask.nii.gz' >>> node.inputs.legacy = 1 >>> node.inputs.n_iters = 6 >>> node.inputs.ftol = 0.002 >>> node.cmdline # doctest: +ELLIPSIS - dti_diffeomorphic_reg diffusion.nii.gz diffusion2.nii.gz mask.nii.gz 1 6 0.002 + dti_diffeomorphic_reg ten1.nii.gz ten2.nii.gz mask.nii.gz 1 6 0.002 >>> node.run() # doctest: +SKIP """ input_spec = DiffeoInputSpec @@ -186,11 +185,11 @@ def _list_outputs(self): class ComposeXfmInputSpec(CommandLineInputSpec): in_df = File(desc='diffeomorphic warp diffeo_xfm.df.nii.gz', exists=True, - position=0, argstr="-df %s", copyfile=False, mandatory=True) + argstr="-df %s", copyfile=False, mandatory=True) in_aff = File(desc='affine_xfm.aff', exists=True, - position=1, argstr="-aff %s", mandatory=True) + argstr="-aff %s", mandatory=True) out_file = traits.Str(desc='output_path', exists=True, - position=2, argstr="-out %s", name_source="in_df", + argstr="-out %s", name_source="in_df", name_template="%s_aff.df.nii.gz") @@ -218,86 +217,101 @@ class ComposeXfmTask(CommandLineDtitk): _cmd = 'dfRightComposeAffine' -# TODO: these haven't been used yet; need to be tested (ALL BELOW) - -class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): - in_tensor = File(desc='moving tensor', exists=True, - position=0, argstr="-in %s") - in_xfm = File(desc='transform to apply', exists=True, - position=1, argstr="-trans %s") - in_target = File(desc='', exists=True, position=2, - argstr="-target %s") - out_file = traits.Str(desc='', exists=True, position=3, - argstr="-out %s", name_source="in_tensor", - name_template="%s_diffeoxfmd.nii.gz") +class affSymTensor3DVolInputSpec(CommandLineInputSpec): + in_file = File(desc='moving tensor', exists=True, + argstr="-in %s", mandatory=True) + out_file = traits.Str(desc='', exists=True, + argstr="-out %s", name_source="in_file", + name_template="%s_affxfmd", keep_extension=True) + transform = File(exists=True, argstr="-trans %s", + xor=['target', 'translation', 'euler', 'deformation'], desc='transform to apply: specify an input transformation file; parameters input will be ignored',) + target = File(exists=True, argstr="-target %s", xor=['transform'], + desc='output volume specification read from the target volume if specified') + interpolation = traits.Enum('LEI', 'EI', usedefault=True, + argstr="-interp %s", + desc='Log Euclidean Euclidean Interpolation') + reorient = traits.Enum('PPD', 'NO', 'FS', argstr='-reorient %s', + usedefault=True) + translation = traits.Tuple((0, 0, 0), desc='translation (x,y,z) in mm', + argstr='-translation %g %g %g', + xor=['transform']) + euler = traits.Tuple((0, 0, 0), desc='(theta, phi, psi) in degrees', + xor=['transform'], argstr='-euler %g %g %g') + deformation = traits.Tuple((1, 1, 1, 0, 0, 0), desc='(xx,yy,zz,xy,yz,xz)', + xor=['transform'], + argstr='-deformation %g %g %g %g %g %g') -class diffeoSymTensor3DVolOutputSpec(TraitedSpec): +class affSymTensor3DVolOutputSpec(TraitedSpec): out_file = File(exists=True) -class diffeoSymTensor3DVolTask(CommandLineDtitk): +class affSymTensor3DVolTask(CommandLineDtitk): """ - Applies diffeomorphic transform to a tensor volume + Applies affine transform to a tensor volume Example ------- >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.diffeoSymTensor3DVolTask() - >>> node.inputs.in_tensor = 'diffusion.nii' - >>> node.inputs.in_xfm = 'ants_Warp.nii.gz' + >>> node = dtitk.affSymTensor3DVolTask() + >>> node.inputs.in_file = 'ten.nii' + >>> node.inputs.transform = 'aff.txt' + >>> node.cmdline # doctest: +ELLIPSIS + 'affineSymTensor3DVolume -in ten.nii -interp LEI -out Ptensor_affxfmd.nii.gz -reorient PPD -trans aff.aff' >>> node.run() # doctest: +SKIP """ + input_spec = affSymTensor3DVolInputSpec + output_spec = affSymTensor3DVolOutputSpec + _cmd = 'affineSymTensor3DVolume' - input_spec = diffeoSymTensor3DVolInputSpec - output_spec = diffeoSymTensor3DVolOutputSpec - _cmd = 'deformationSymTensor3DVolume' - +# TODO: these haven't been used yet; need to be tested (ALL BELOW) -class affSymTensor3DVolInputSpec(CommandLineInputSpec): +class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): in_tensor = File(desc='moving tensor', exists=True, - position=0, argstr="-in %s") + argstr="-in %s") in_xfm = File(desc='transform to apply', exists=True, - position=1, argstr="-trans %s") - in_target = File(desc='', exists=True, position=2, + argstr="-trans %s") + in_target = File(desc='', exists=True, argstr="-target %s") - out_file = traits.Str(desc='', exists=True, position=3, + out_file = traits.Str(desc='', exists=True, argstr="-out %s", name_source="in_tensor", - name_template="%s_affxfmd.nii.gz") + name_template="%s_diffeoxfmd.nii.gz") -class affSymTensor3DVolOutputSpec(TraitedSpec): +class diffeoSymTensor3DVolOutputSpec(TraitedSpec): out_file = File(exists=True) -class affSymTensor3DVolTask(CommandLineDtitk): +class diffeoSymTensor3DVolTask(CommandLineDtitk): """ - Applies affine transform to a tensor volume + Applies diffeomorphic transform to a tensor volume Example ------- >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.affSymTensor3DVolTask() - >>> node.inputs.in_tensor = 'diffusion.nii' - >>> node.inputs.in_xfm = 'ants_Affine.txt' + >>> node = dtitk.diffeoSymTensor3DVolTask() + >>> node.inputs.in_tensor = 'ten.nii' + >>> node.inputs.in_xfm = 'myxfm.df.nii.gz' + >>> node.cmdline # doctest: +ELLIPSIS + >>> node.run() # doctest: +SKIP """ - input_spec = affSymTensor3DVolInputSpec - output_spec = affSymTensor3DVolOutputSpec - _cmd = 'affineSymTensor3DVolume' + + input_spec = diffeoSymTensor3DVolInputSpec + output_spec = diffeoSymTensor3DVolOutputSpec + _cmd = 'deformationSymTensor3DVolume' class affScalarVolInputSpec(CommandLineInputSpec): in_volume = File(desc='moving volume', exists=True, - position=0, argstr="-in %s") + position=0, argstr="-in %s", mandatory=True) in_xfm = File(desc='transform to apply', exists=True, position=1, argstr="-trans %s") - in_target = File(desc='', position=2, argstr="-target %s") - out_file = traits.Str(desc='', position=3, - argstr="-out %s", name_source="in_volume", - name_template="%s_affxfmd.nii.gz") + in_target = File(desc='', argstr="-target %s") + out_file = traits.Str(desc='', argstr="-out %s", name_source="in_volume", + name_template="%s_affxfmd", keep_extension=True) class affScalarVolOutputSpec(TraitedSpec): @@ -315,6 +329,8 @@ class affScalarVolTask(CommandLineDtitk): >>> node = dtitk.affScalarVolTask() >>> node.inputs.in_volume = 'fa.nii.gz' >>> node.inputs.in_xfm = 'ants_Affine.txt' + >>> node.cmdline # doctest: +ELLIPSIS + >>> node.run() # doctest: +SKIP """ input_spec = affScalarVolInputSpec @@ -323,23 +339,19 @@ class affScalarVolTask(CommandLineDtitk): class diffeoScalarVolInputSpec(CommandLineInputSpec): - in_volume = File(desc='moving volume', exists=True, - position=0, argstr="-in %s") - in_xfm = File(desc='transform to apply', exists=True, - position=2, argstr="-trans %s") - in_target = File(desc='', exists=True, position=3, - argstr="-target %s") - out_file = traits.Str(desc='', position=1, argstr="-out %s", - name_source="in_volume", - name_template="%s_diffeoxfmd.nii.gz") - in_vsize = File(desc='', exists=True, position=4, - argstr="-vsize %s") - in_flip = File(desc='', exists=True, position=5, - argstr="-flip %s") - in_type = File(desc='', exists=True, position=6, - argstr="-type %s") - in_interp = File(desc='0 trilin, 1 NN', exists=True, - position=7, argstr="-interp %s") + in_volume = File(desc='moving volume', exists=True, argstr="-in %s", + mandatory=True) + in_xfm = File(desc='transform to apply', exists=True, argstr="-trans %s", + mandatory=True) + in_target = File(desc='', exists=True, argstr="-target %s", mandatory=True) + out_file = traits.Str(desc='', argstr="-out %s", name_source="in_volume", + name_template="%s_diffeoxfmd", keep_extension=True) + voxel_size = File(desc='', exists=True, argstr="-vsize %g") + flip = File(desc='', exists=True, argstr="-flip %s") + resampling_type = traits.Enum(1, 0, desc='1=backward(def), 0=forward', + exists=True, argstr="-type %s") + interp = traits.Enum(0, 1, desc='0=trilinear(def), 1=nearest neighbor', + exists=True, argstr="-interp %s", usedefault=True) class diffeoScalarVolOutputSpec(TraitedSpec): @@ -357,6 +369,8 @@ class diffeoScalarVolTask(CommandLineDtitk): >>> node = dtitk.diffeoScalarVolTask() >>> node.inputs.in_volume = 'fa.nii.gz' >>> node.inputs.in_xfm = 'ants_Warp.nii.gz' + >>> node.cmdline # doctest: +ELLIPSIS + >>> node.run() # doctest: +SKIP """ From 32e4f0217e46b1725656ddf4eff5795cc2bef0db Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Mon, 26 Mar 2018 10:31:50 -0700 Subject: [PATCH 15/53] Made use of affine not default per @effigies suggestion. --- nipype/interfaces/dtitk/registration.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 89aa230a53..3465fad890 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -88,7 +88,7 @@ class AffineInputSpec(CommandLineInputSpec): usedefault=True) useInTrans = traits.Bool(position=5, argstr="1", desc="to initialize with existing xfm set as 1", - default_value=True, usedefault=True) + default_value=True) class AffineOutputSpec(TraitedSpec): @@ -267,6 +267,7 @@ class affSymTensor3DVolTask(CommandLineDtitk): # TODO: these haven't been used yet; need to be tested (ALL BELOW) + class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): in_tensor = File(desc='moving tensor', exists=True, argstr="-in %s") From de50d4ecc40632fab442ffcb958385a813b3d7ea Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Mon, 26 Mar 2018 10:32:05 -0700 Subject: [PATCH 16/53] SVAdjustVoxelspace interface fixed --- nipype/interfaces/dtitk/utils.py | 84 +++++++++++++++++--------------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index c52dda0df8..281165c729 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -31,7 +31,7 @@ class TVAdjustVoxSpInputSpec(CommandLineInputSpec): argstr="-vsize %g %g %g", xor=['target_file']) origin = traits.Tuple((0, 0, 0), desc='xyz origin (superseded by target)', - argstr='-origin %g %g %g', usedefault=True, + argstr='-origin %g %g %g', xor=['target_file']) @@ -48,10 +48,10 @@ class TVAdjustVoxSpTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.TVAdjustVoxSpTask() - >>> node.inputs.in_file = 'diffusion.nii' - >>> node.inputs.target_file = 'diffusion2.nii' + >>> node.inputs.in_file = 'diff1.nii' + >>> node.inputs.target_file = 'diff2.nii' >>> node.cmdline # doctest: +ELLIPSIS - 'TVAdjustVoxelspace -in diffusion.nii -out diffusion_avs.nii -target 'diffusion2.nii'' + 'TVAdjustVoxelspace -in diff1.nii -out diff1_avs.nii -target 'diff2.nii'' >>> node.run() # doctest: +SKIP """ input_spec = TVAdjustVoxSpInputSpec @@ -59,6 +59,47 @@ class TVAdjustVoxSpTask(CommandLineDtitk): _cmd = 'TVAdjustVoxelspace' +class SVAdjustVoxSpInputSpec(CommandLineInputSpec): + in_file = File(desc="image to resample", exists=True, + mandatory=True, argstr="-in %s") + out_file = traits.Str(desc='output path', argstr="-out %s", + name_source="in_file", name_template='%s_avs', + keep_extension=True) + target_file = File(desc='target volume to match', + argstr="-target %s", xor=['voxel_size', 'origin']) + voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='xyz voxel size (superseded by target)', + argstr="-vsize %g %g %g", xor=['target_file']) + origin = traits.Tuple((0, 0, 0), + desc='xyz origin (superseded by target)', + argstr='-origin %g %g %g', + xor=['target_file']) + + +class SVAdjustVoxSpOutputSpec(TraitedSpec): + out_file = File(exists=True) + + +class SVAdjustVoxSpTask(CommandLineDtitk): + """ + Adjusts the voxel space of a scalar volume + + Example + ------- + + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.SVAdjustVoxSpTask() + >>> node.inputs.in_file = 'vol1.nii' + >>> node.inputs.target_file = 'vol2.nii' + >>> node.cmdline # doctest: +ELLIPSIS + 'TVAdjustVoxelspace -in vol1.nii -out vol1_avs.nii -target 'vol2.nii'' + >>> node.run() # doctest: +SKIP + """ + input_spec = SVAdjustVoxSpInputSpec + output_spec = SVAdjustVoxSpOutputSpec + _cmd = 'SVAdjustVoxelspace' + + class TVResampleInputSpec(CommandLineInputSpec): in_file = File(desc="image to resample", exists=True, mandatory=True, argstr="-in %s") @@ -197,41 +238,6 @@ class BinThreshTask(CommandLineDtitk): # TODO not using these yet... need to be tested -class SVAdjustVoxSpInputSpec(CommandLineInputSpec): - in_file = File(desc="image to resample", exists=True, - mandatory=True, position=0, argstr="-in %s") - target_file = File(desc='target volume', mandatory=True, - position=2, argstr="-target %s") - voxel_size = traits.Str(desc='resampled voxel size', mandatory=True, - position=3, argstr="-vsize %s") - out_file = traits.Str(desc='output path', position=1, argstr="-out %s", - name_source="in_file", name_template='%s_reslice', - keep_extension=True) - origin = traits.Str(desc='xyz voxel size', mandatory=True, - position=4, argstr='-origin %s') - - -class SVAdjustVoxSpOutputSpec(TraitedSpec): - out_file = File(exists=True) - - -class SVAdjustVoxSpTask(CommandLineDtitk): - """ - Adjusts the voxel space of a scalar volume - - Example - ------- - - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.SVAdjustVoxSpTask() - >>> node.inputs.in_file = 'diffusion.nii.gz' - >>> node.run() # doctest: +SKIP - """ - input_spec = SVAdjustVoxSpInputSpec - output_spec = SVAdjustVoxSpOutputSpec - _cmd = 'SVAdjustVoxelspace' - - class SVResampleInputSpec(TVResampleInputSpec): pass From cb2b5373b338b274d09889ab770973b3be5e5c5c Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Mon, 26 Mar 2018 10:42:01 -0700 Subject: [PATCH 17/53] SVResample interface fixed --- nipype/interfaces/dtitk/utils.py | 54 +++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index 281165c729..750c57fabe 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -101,7 +101,7 @@ class SVAdjustVoxSpTask(CommandLineDtitk): class TVResampleInputSpec(CommandLineInputSpec): - in_file = File(desc="image to resample", exists=True, + in_file = File(desc="tensor to resample", exists=True, mandatory=True, argstr="-in %s") out_file = traits.Str(desc='output path', name_source="in_file", name_template="%s_resampled", @@ -137,10 +137,10 @@ class TVResampleTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.TVResampleTask() - >>> node.inputs.in_file = 'diffusion.nii.gz' - >>> node.inputs.target_file = 'diffusion.nii.gz' + >>> node.inputs.in_file = 'ten1.nii.gz' + >>> node.inputs.target_file = 'ten2.nii.gz' >>> node.cmdline # doctest: +ELLIPSIS - 'TVResample -in diffusion.nii -out diffusion_resampled.nii -target 'diffusion2.nii'' + 'TVResample -in ten1.nii -out ten1_resampled.nii -target 'ten2.nii'' >>> node.run() # doctest: +SKIP """ input_spec = TVResampleInputSpec @@ -148,6 +148,52 @@ class TVResampleTask(CommandLineDtitk): _cmd = 'TVResample' +class SVResampleInputSpec(CommandLineInputSpec): + in_file = File(desc="image to resample", exists=True, + mandatory=True, argstr="-in %s") + out_file = traits.Str(desc='output path', + name_source="in_file", name_template="%s_resampled", + keep_extension=True, argstr="-out %s") + target_file = File(desc='specs read from the target volume', + argstr="-target %s", + xor=['array_size', 'voxel_size', 'origin']) + align = traits.Enum('center', 'origin', argstr="-align %s", + desc='how to align output volume to input volume') + array_size = traits.Tuple((traits.Int(), traits.Int(), traits.Int()), + desc='resampled array size', xor=['target_file'], + argstr="-size %d %d %d") + voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='resampled voxel size', xor=['target_file'], + argstr="-vsize %g %g %g") + origin = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='xyz origin', xor=['target_file'], + argstr='-origin %g %g %g') + + +class SVResampleOutputSpec(TraitedSpec): + out_file = File(exists=True) + + +class SVResampleTask(CommandLineDtitk): + """ + Resamples a non-tensor volume + + Example + ------- + + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.TVResampleTask() + >>> node.inputs.in_file = 'vol1.nii.gz' + >>> node.inputs.target_file = 'vol2.nii.gz' + >>> node.cmdline # doctest: +ELLIPSIS + 'SVResample -in vol1.nii -out vol1_resampled.nii -target 'vol2.nii'' + >>> node.run() # doctest: +SKIP + """ + input_spec = SVResampleInputSpec + output_spec = SVResampleOutputSpec + _cmd = 'SVResample' + + class TVtoolInputSpec(CommandLineInputSpec): in_file = File(desc="image to resample", exists=True, argstr="-in %s", mandatory=True) From aeb2c55abbca0673f63b3f3c7ee42140c8a6cf23 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Mon, 26 Mar 2018 10:45:16 -0700 Subject: [PATCH 18/53] removed old SVResample --- nipype/interfaces/dtitk/utils.py | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index 750c57fabe..f9cec50b8a 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -280,32 +280,3 @@ class BinThreshTask(CommandLineDtitk): input_spec = BinThreshInputSpec output_spec = BinThreshOutputSpec _cmd = 'BinaryThresholdImageFilter' - -# TODO not using these yet... need to be tested - - - -class SVResampleInputSpec(TVResampleInputSpec): - pass - - -class SVResampleOutputSpec(TVResampleOutputSpec): - pass - - -class SVResampleTask(CommandLineDtitk): - """ - Resamples a scalar volume - - Example - ------- - - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.SVResampleTask() - >>> node.inputs.in_file = 'diffusion.nii' - >>> node.inputs.in_file = 'diffusion.nii' - >>> node.run() # doctest: +SKIP - """ - input_spec = SVResampleInputSpec - output_spec = SVResampleOutputSpec - _cmd = 'SVResample' From 5049458ba0fd135f389242aab5d600ba18dd279a Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Mon, 26 Mar 2018 11:26:14 -0700 Subject: [PATCH 19/53] minor wording --- nipype/interfaces/dtitk/utils.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index f9cec50b8a..ced749a491 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -18,8 +18,8 @@ class TVAdjustVoxSpInputSpec(CommandLineInputSpec): - in_file = File(desc="tensor to resample", exists=True, mandatory=True, - argstr="-in %s") + in_file = File(desc="tensor volume to modify", exists=True, + mandatory=True, argstr="-in %s") out_file = traits.Str(genfile=True, desc='output path', argstr="-out %s", name_source='in_file', name_template='%s_avs', keep_extension=True) @@ -60,7 +60,7 @@ class TVAdjustVoxSpTask(CommandLineDtitk): class SVAdjustVoxSpInputSpec(CommandLineInputSpec): - in_file = File(desc="image to resample", exists=True, + in_file = File(desc="scalar volume to modify", exists=True, mandatory=True, argstr="-in %s") out_file = traits.Str(desc='output path', argstr="-out %s", name_source="in_file", name_template='%s_avs', @@ -101,7 +101,7 @@ class SVAdjustVoxSpTask(CommandLineDtitk): class TVResampleInputSpec(CommandLineInputSpec): - in_file = File(desc="tensor to resample", exists=True, + in_file = File(desc="tensor volume to resample", exists=True, mandatory=True, argstr="-in %s") out_file = traits.Str(desc='output path', name_source="in_file", name_template="%s_resampled", @@ -176,7 +176,7 @@ class SVResampleOutputSpec(TraitedSpec): class SVResampleTask(CommandLineDtitk): """ - Resamples a non-tensor volume + Resamples a scalar volume Example ------- @@ -195,8 +195,8 @@ class SVResampleTask(CommandLineDtitk): class TVtoolInputSpec(CommandLineInputSpec): - in_file = File(desc="image to resample", exists=True, argstr="-in %s", - mandatory=True) + in_file = File(desc="scalar volume to resample", exists=True, + argstr="-in %s", mandatory=True) '''NOTE: there are a lot more options here; not putting all of them in''' in_flag = traits.Enum('fa', 'tr', 'ad', 'rd', 'pd', 'rgb', exists=True, argstr="-%s", desc='') @@ -240,6 +240,9 @@ def _gen_filename(self, name): return basename + '_'+self.inputs.in_flag+'.nii.gz' +'''Note: SVTool not implemented at this time''' + + class BinThreshInputSpec(CommandLineInputSpec): in_file = File(desc='Image to threshold/binarize', exists=True, position=0, argstr="%s", mandatory=True) @@ -260,7 +263,7 @@ class BinThreshOutputSpec(TraitedSpec): class BinThreshTask(CommandLineDtitk): """ - Binarizes an image based on parameters + Binarizes an image Example ------- From 98e181ada3adccda54675c27df2e0a8b4aef2567 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Mon, 26 Mar 2018 11:26:28 -0700 Subject: [PATCH 20/53] affSymTensor3DVol interface fixed --- nipype/interfaces/dtitk/registration.py | 91 ++++++++++++++----------- 1 file changed, 53 insertions(+), 38 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 3465fad890..62c0931bdb 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -218,18 +218,18 @@ class ComposeXfmTask(CommandLineDtitk): class affSymTensor3DVolInputSpec(CommandLineInputSpec): - in_file = File(desc='moving tensor', exists=True, + in_file = File(desc='moving tensor volume', exists=True, argstr="-in %s", mandatory=True) - out_file = traits.Str(desc='', exists=True, + out_file = traits.Str(desc='output filename', exists=True, argstr="-out %s", name_source="in_file", name_template="%s_affxfmd", keep_extension=True) transform = File(exists=True, argstr="-trans %s", xor=['target', 'translation', 'euler', 'deformation'], desc='transform to apply: specify an input transformation file; parameters input will be ignored',) - target = File(exists=True, argstr="-target %s", xor=['transform'], - desc='output volume specification read from the target volume if specified') interpolation = traits.Enum('LEI', 'EI', usedefault=True, argstr="-interp %s", desc='Log Euclidean Euclidean Interpolation') + target = File(exists=True, argstr="-target %s", xor=['transform'], + desc='output volume specification read from the target volume if specified') reorient = traits.Enum('PPD', 'NO', 'FS', argstr='-reorient %s', usedefault=True) translation = traits.Tuple((0, 0, 0), desc='translation (x,y,z) in mm', @@ -265,6 +265,55 @@ class affSymTensor3DVolTask(CommandLineDtitk): output_spec = affSymTensor3DVolOutputSpec _cmd = 'affineSymTensor3DVolume' + +class affScalarVolInputSpec(CommandLineInputSpec): + in_file = File(desc='moving scalar volume', exists=True, + argstr="-in %s", mandatory=True) + out_file = traits.Str(desc='output filename', exists=True, + argstr="-out %s", name_source="in_file", + name_template="%s_affxfmd", keep_extension=True) + transform = File(exists=True, argstr="-trans %s", + xor=['target', 'translation', 'euler', 'deformation'], desc='transform to apply: specify an input transformation file; parameters input will be ignored',) + interpolation = traits.Enum(0, 1, usedefault=True, + argstr="-interp %s", + desc='0=trilinear (def); 1=nearest neighbor') + target = File(exists=True, argstr="-target %s", xor=['transform'], + desc='output volume specification read from the target volume if specified') + translation = traits.Tuple((0, 0, 0), desc='translation (x,y,z) in mm', + argstr='-translation %g %g %g', + xor=['transform']) + euler = traits.Tuple((0, 0, 0), desc='(theta, phi, psi) in degrees', + xor=['transform'], argstr='-euler %g %g %g') + deformation = traits.Tuple((1, 1, 1, 0, 0, 0), desc='(xx,yy,zz,xy,yz,xz)', + xor=['transform'], + argstr='-deformation %g %g %g %g %g %g') + + + +class affScalarVolOutputSpec(TraitedSpec): + out_file = File(desc='moved volume', exists=True) + + +class affScalarVolTask(CommandLineDtitk): + """ + Applies affine transform to a scalar volume + + Example + ------- + + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.affScalarVolTask() + >>> node.inputs.in_volume = 'myvol.nii' + >>> node.inputs.in_xfm = 'myxfm.aff' + >>> node.cmdline # doctest: +ELLIPSIS + affineScalarVolume -in myvol.nii -interp 0 -out myvol_affxfmd.nii -trans myxfm.aff + >>> node.run() # doctest: +SKIP + """ + input_spec = affScalarVolInputSpec + output_spec = affScalarVolOutputSpec + _cmd = 'affineScalarVolume' + + # TODO: these haven't been used yet; need to be tested (ALL BELOW) @@ -305,40 +354,6 @@ class diffeoSymTensor3DVolTask(CommandLineDtitk): _cmd = 'deformationSymTensor3DVolume' -class affScalarVolInputSpec(CommandLineInputSpec): - in_volume = File(desc='moving volume', exists=True, - position=0, argstr="-in %s", mandatory=True) - in_xfm = File(desc='transform to apply', exists=True, - position=1, argstr="-trans %s") - in_target = File(desc='', argstr="-target %s") - out_file = traits.Str(desc='', argstr="-out %s", name_source="in_volume", - name_template="%s_affxfmd", keep_extension=True) - - -class affScalarVolOutputSpec(TraitedSpec): - out_file = File(desc='moved volume', exists=True) - - -class affScalarVolTask(CommandLineDtitk): - """ - Applies affine transform to a scalar volume - - Example - ------- - - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.affScalarVolTask() - >>> node.inputs.in_volume = 'fa.nii.gz' - >>> node.inputs.in_xfm = 'ants_Affine.txt' - >>> node.cmdline # doctest: +ELLIPSIS - - >>> node.run() # doctest: +SKIP - """ - input_spec = affScalarVolInputSpec - output_spec = affScalarVolOutputSpec - _cmd = 'affineScalarVolume' - - class diffeoScalarVolInputSpec(CommandLineInputSpec): in_volume = File(desc='moving volume', exists=True, argstr="-in %s", mandatory=True) From f601c687eaf778980a6175079e6b23d02127c0b6 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Mon, 26 Mar 2018 12:02:11 -0700 Subject: [PATCH 21/53] diffeoSymTensor3DVol fixed --- nipype/interfaces/dtitk/registration.py | 61 +++++++++++++++---------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 62c0931bdb..ddde668cf8 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -167,7 +167,7 @@ class DiffeoTask(CommandLineDtitk): >>> node.inputs.n_iters = 6 >>> node.inputs.ftol = 0.002 >>> node.cmdline # doctest: +ELLIPSIS - dti_diffeomorphic_reg ten1.nii.gz ten2.nii.gz mask.nii.gz 1 6 0.002 + 'dti_diffeomorphic_reg ten1.nii.gz ten2.nii.gz mask.nii.gz 1 6 0.002' >>> node.run() # doctest: +SKIP """ input_spec = DiffeoInputSpec @@ -227,11 +227,11 @@ class affSymTensor3DVolInputSpec(CommandLineInputSpec): xor=['target', 'translation', 'euler', 'deformation'], desc='transform to apply: specify an input transformation file; parameters input will be ignored',) interpolation = traits.Enum('LEI', 'EI', usedefault=True, argstr="-interp %s", - desc='Log Euclidean Euclidean Interpolation') - target = File(exists=True, argstr="-target %s", xor=['transform'], - desc='output volume specification read from the target volume if specified') + desc='Log Euclidean/Euclidean Interpolation') reorient = traits.Enum('PPD', 'NO', 'FS', argstr='-reorient %s', usedefault=True) + target = File(exists=True, argstr="-target %s", xor=['transform'], + desc='output volume specification read from the target volume if specified') translation = traits.Tuple((0, 0, 0), desc='translation (x,y,z) in mm', argstr='-translation %g %g %g', xor=['transform']) @@ -306,7 +306,7 @@ class affScalarVolTask(CommandLineDtitk): >>> node.inputs.in_volume = 'myvol.nii' >>> node.inputs.in_xfm = 'myxfm.aff' >>> node.cmdline # doctest: +ELLIPSIS - affineScalarVolume -in myvol.nii -interp 0 -out myvol_affxfmd.nii -trans myxfm.aff + 'affineScalarVolume -in myvol.nii -interp 0 -out myvol_affxfmd.nii -trans myxfm.aff' >>> node.run() # doctest: +SKIP """ input_spec = affScalarVolInputSpec @@ -314,19 +314,29 @@ class affScalarVolTask(CommandLineDtitk): _cmd = 'affineScalarVolume' -# TODO: these haven't been used yet; need to be tested (ALL BELOW) - - class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): - in_tensor = File(desc='moving tensor', exists=True, - argstr="-in %s") - in_xfm = File(desc='transform to apply', exists=True, - argstr="-trans %s") - in_target = File(desc='', exists=True, - argstr="-target %s") - out_file = traits.Str(desc='', exists=True, - argstr="-out %s", name_source="in_tensor", - name_template="%s_diffeoxfmd.nii.gz") + in_file = File(desc='moving tensor volume', exists=True, + argstr="-in %s", mandatory=True) + out_file = traits.Str(desc='output filename', exists=True, + argstr="-out %s", name_source="in_file", + name_template="%s_diffeoxfmd", keep_extension=True) + transform = File(exists=True, argstr="-trans %s", + xor=['target', 'voxel_size'], desc='transform to apply: specify an input transformation file; parameters input will be ignored',) + df = traits.Str('FD', argstr="-df %s", usedefault=True) + interpolation = traits.Enum('LEI', 'EI', usedefault=True, + argstr="-interp %s", + desc='Log Euclidean/Euclidean Interpolation') + reorient = traits.Enum('PPD','FS', argstr='-reorient %s', + usedefault=True) + target = File(exists=True, argstr="-target %s", xor=['transform'], + desc='output volume specification read from the target volume if specified') + voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='xyz voxel size (superseded by target)', + argstr="-vsize %g %g %g", xor=['target_file']) + flip = traits.Tuple((0, 0, 0), exists=True, argstr="-flip %s") + resampling_type = traits.Enum(1, 0, desc='1=backward(def), 0=forward', + exists=True, argstr="-type %s") + class diffeoSymTensor3DVolOutputSpec(TraitedSpec): @@ -343,9 +353,9 @@ class diffeoSymTensor3DVolTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.diffeoSymTensor3DVolTask() >>> node.inputs.in_tensor = 'ten.nii' - >>> node.inputs.in_xfm = 'myxfm.df.nii.gz' + >>> node.inputs.in_xfm = 'myxfm.df.nii' >>> node.cmdline # doctest: +ELLIPSIS - + 'deformationSymTensor3DVolume -df FD -in ten.nii.gz -interp LEI -out ten_diffeoxfmd.nii.gz -reorient PPD -trans myxfm.df.nii' >>> node.run() # doctest: +SKIP """ @@ -354,15 +364,20 @@ class diffeoSymTensor3DVolTask(CommandLineDtitk): _cmd = 'deformationSymTensor3DVolume' +# TODO: these haven't been used yet; need to be tested (ALL BELOW) + + class diffeoScalarVolInputSpec(CommandLineInputSpec): - in_volume = File(desc='moving volume', exists=True, argstr="-in %s", + in_file = File(desc='moving volume', exists=True, argstr="-in %s", mandatory=True) in_xfm = File(desc='transform to apply', exists=True, argstr="-trans %s", mandatory=True) - in_target = File(desc='', exists=True, argstr="-target %s", mandatory=True) - out_file = traits.Str(desc='', argstr="-out %s", name_source="in_volume", + target_file = File(desc='', exists=True, argstr="-target %s", mandatory=True) + out_file = traits.Str(desc='', argstr="-out %s", name_source="in_file", name_template="%s_diffeoxfmd", keep_extension=True) - voxel_size = File(desc='', exists=True, argstr="-vsize %g") + voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='xyz voxel size (superseded by target)', + argstr="-vsize %g %g %g", xor=['target_file']) flip = File(desc='', exists=True, argstr="-flip %s") resampling_type = traits.Enum(1, 0, desc='1=backward(def), 0=forward', exists=True, argstr="-type %s") From 49d01388924241cfbb443ed95f34178bf3ce82d2 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Mon, 26 Mar 2018 12:20:14 -0700 Subject: [PATCH 22/53] diffeoScalarVol interface fixed --- nipype/interfaces/dtitk/registration.py | 33 ++++++++++++------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index ddde668cf8..e7bb2b000f 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -321,18 +321,18 @@ class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): argstr="-out %s", name_source="in_file", name_template="%s_diffeoxfmd", keep_extension=True) transform = File(exists=True, argstr="-trans %s", - xor=['target', 'voxel_size'], desc='transform to apply: specify an input transformation file; parameters input will be ignored',) + mandatory=True, desc='transform to apply') df = traits.Str('FD', argstr="-df %s", usedefault=True) interpolation = traits.Enum('LEI', 'EI', usedefault=True, argstr="-interp %s", desc='Log Euclidean/Euclidean Interpolation') reorient = traits.Enum('PPD','FS', argstr='-reorient %s', usedefault=True) - target = File(exists=True, argstr="-target %s", xor=['transform'], + target = File(exists=True, argstr="-target %s", xor=['voxel_size'], desc='output volume specification read from the target volume if specified') voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), desc='xyz voxel size (superseded by target)', - argstr="-vsize %g %g %g", xor=['target_file']) + argstr="-vsize %g %g %g", xor=['target']) flip = traits.Tuple((0, 0, 0), exists=True, argstr="-flip %s") resampling_type = traits.Enum(1, 0, desc='1=backward(def), 0=forward', exists=True, argstr="-type %s") @@ -364,21 +364,20 @@ class diffeoSymTensor3DVolTask(CommandLineDtitk): _cmd = 'deformationSymTensor3DVolume' -# TODO: these haven't been used yet; need to be tested (ALL BELOW) - - class diffeoScalarVolInputSpec(CommandLineInputSpec): - in_file = File(desc='moving volume', exists=True, argstr="-in %s", - mandatory=True) - in_xfm = File(desc='transform to apply', exists=True, argstr="-trans %s", - mandatory=True) - target_file = File(desc='', exists=True, argstr="-target %s", mandatory=True) - out_file = traits.Str(desc='', argstr="-out %s", name_source="in_file", + in_file = File(desc='moving scalar volume', exists=True, + argstr="-in %s", mandatory=True) + out_file = traits.Str(desc='output filename', exists=True, + argstr="-out %s", name_source="in_file", name_template="%s_diffeoxfmd", keep_extension=True) + transform = transform = File(exists=True, argstr="-trans %s", + mandatory=True, desc='transform to apply') + target = File(exists=True, argstr="-target %s", xor=['voxel_size'], + desc='output volume specification read from the target volume if specified') voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), desc='xyz voxel size (superseded by target)', - argstr="-vsize %g %g %g", xor=['target_file']) - flip = File(desc='', exists=True, argstr="-flip %s") + argstr="-vsize %g %g %g", xor=['target']) + flip = traits.Tuple((0, 0, 0), exists=True, argstr="-flip %s") resampling_type = traits.Enum(1, 0, desc='1=backward(def), 0=forward', exists=True, argstr="-type %s") interp = traits.Enum(0, 1, desc='0=trilinear(def), 1=nearest neighbor', @@ -398,10 +397,10 @@ class diffeoScalarVolTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.diffeoScalarVolTask() - >>> node.inputs.in_volume = 'fa.nii.gz' - >>> node.inputs.in_xfm = 'ants_Warp.nii.gz' + >>> node.inputs.in_volume = 'sv.nii' + >>> node.inputs.in_xfm = 'myxfm.df.nii' >>> node.cmdline # doctest: +ELLIPSIS - + 'deformationScalarVolume -in sv.nii -interp 0 -out sv_diffeoxfmd.nii -trans myxfm.df.nii.gz' >>> node.run() # doctest: +SKIP """ From 605f3b5a54c93d81f26d50b0ab951e28d529d502 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Mon, 26 Mar 2018 13:20:44 -0700 Subject: [PATCH 23/53] From @effigies: prefatory lines no longer necessary. Tests are now run in that directory through another mechanism. --- nipype/interfaces/dtitk/registration.py | 5 ----- nipype/interfaces/dtitk/utils.py | 5 ----- 2 files changed, 10 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index e7bb2b000f..9bafb8181b 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -3,11 +3,6 @@ # vi: set ft=python sts=4 ts=4 sw=4 et: """DTITK registration interfaces - Change directory to provide relative paths for doctests - >>> import os - >>> filepath = os.path.dirname( os.path.realpath( __file__ ) ) - >>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data')) - >>> os.chdir(datadir) """ from ..base import TraitedSpec, CommandLineInputSpec, traits, isdefined, File diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index ced749a491..2903a80e14 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -3,11 +3,6 @@ # vi: set ft=python sts=4 ts=4 sw=4 et: """DTITK utility interfaces - Change directory to provide relative paths for doctests - >>> import os - >>> filepath = os.path.dirname( os.path.realpath( __file__ ) ) - >>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data')) - >>> os.chdir(datadir) """ __author__ = 'kjordan' From ea6afb8a160324c924607704bd5d2082c4f877d5 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Mon, 26 Mar 2018 17:13:10 -0700 Subject: [PATCH 24/53] fix test bugs --- nipype/interfaces/dtitk/registration.py | 109 ++++++++++++++---------- nipype/interfaces/dtitk/utils.py | 63 ++++++++------ 2 files changed, 101 insertions(+), 71 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 9bafb8181b..0b49124f9d 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -3,6 +3,17 @@ # vi: set ft=python sts=4 ts=4 sw=4 et: """DTITK registration interfaces +DTI-TK developed by Gary Hui Zhang, gary.zhang@ucl.ac.uk +For additional help, visit http://dti-tk.sf.net + +The high-dimensional tensor-based DTI registration algorithm + +Zhang, H., Avants, B.B, Yushkevich, P.A., Woo, J.H., Wang, S., McCluskey, L.H., Elman, L.B., Melhem, E.R., Gee, J.C., High-dimensional spatial normalization of diffusion tensor images improves the detection of white matter differences in amyotrophic lateral sclerosis, IEEE Transactions on Medical Imaging, 26(11):1585-1597, November 2007. PMID: 18041273. + +The original piecewise-affine tensor-based DTI registration algorithm at the core of DTI-TK + +Zhang, H., Yushkevich, P.A., Alexander, D.C., Gee, J.C., Deformable registration of diffusion tensor MR images with explicit orientation optimization, Medical Image Analysis, 10(5):764-785, October 2006. PMID: 16899392. + """ from ..base import TraitedSpec, CommandLineInputSpec, traits, isdefined, File @@ -10,6 +21,7 @@ import os from .base import CommandLineDtitk +__docformat__ = 'restructuredtext' class RigidInputSpec(CommandLineInputSpec): fixed_file = File(desc="fixed diffusion tensor image", @@ -43,14 +55,14 @@ class RigidTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.RigidTask() - >>> node.inputs.fixed_file = 'ten1.nii.gz' - >>> node.inputs.moving_file = 'ten2.nii.gz' + >>> node.inputs.fixed_file = 'im1.nii' + >>> node.inputs.moving_file = 'im2.nii' >>> node.inputs.similarity_metric = 'EDS' >>> node.inputs.samplingXYZ = (4,4,4) >>> node.inputs.ftol = 0.01 >>> node.inputs.useInTrans = True - >>> node.cmdline # doctest: +ELLIPSIS - 'dti_rigid_reg ten1.nii.gz ten2.nii.gz EDS 4 4 4 0.01 1' + >>> node.cmdline + 'dti_rigid_reg im1.nii im2.nii EDS 4 4 4 0.01 1' >>> node.run() # doctest: +SKIP """ input_spec = RigidInputSpec @@ -59,10 +71,11 @@ class RigidTask(CommandLineDtitk): def _list_outputs(self): outputs = self.output_spec().get() - outputs['out_file_xfm'] = self.inputs.moving_file.replace('.nii.gz', - '.aff') - outputs['out_file'] = self.inputs.moving_file.replace('.nii.gz', - '_aff.nii.gz') + splitlist = os.path.basename(self.inputs.moving_file).split('.') + basename = splitlist[0] + termination = '.'+'.'.join(splitlist[1:]) + outputs['out_file_xfm'] = basename+'.aff' + outputs['out_file'] = basename+'_aff'+termination return outputs @@ -99,14 +112,14 @@ class AffineTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.AffineTask() - >>> node.inputs.fixed_file = 'ten1.nii.gz' - >>> node.inputs.moving_file = 'ten2.nii.gz' + >>> node.inputs.fixed_file = 'im1.nii' + >>> node.inputs.moving_file = 'im2.nii' >>> node.inputs.similarity_metric = 'EDS' >>> node.inputs.samplingXYZ = (4,4,4) >>> node.inputs.ftol = 0.01 >>> node.inputs.useInTrans = True - >>> node.cmdline # doctest: +ELLIPSIS - 'dti_affine_reg ten1.nii.gz ten2.nii.gz EDS 4 4 4 0.01 1' + >>> node.cmdline + 'dti_affine_reg im1.nii im2.nii EDS 4 4 4 0.01 1' >>> node.run() # doctest: +SKIP """ input_spec = AffineInputSpec @@ -115,10 +128,11 @@ class AffineTask(CommandLineDtitk): def _list_outputs(self): outputs = self.output_spec().get() - outputs['out_file_xfm'] = self.inputs.moving_file.replace('.nii.gz', - '.aff') - outputs['out_file'] = self.inputs.moving_file.replace('.nii.gz', - '_aff.nii.gz') + splitlist = os.path.basename(self.inputs.moving_file).split('.') + basename = splitlist[0] + termination = '.'+'.'.join(splitlist[1:]) + outputs['out_file_xfm'] = basename+'.aff' + outputs['out_file'] = basename+'_aff'+termination return outputs @@ -155,14 +169,14 @@ class DiffeoTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.DiffeoTask() - >>> node.inputs.fixed_file = 'ten1.nii.gz' - >>> node.inputs.moving_file = 'ten2.nii.gz' - >>> node.inputs.mask = 'mask.nii.gz' + >>> node.inputs.fixed_file = 'im1.nii' + >>> node.inputs.moving_file = 'im2.nii' + >>> node.inputs.mask_file = 'mask.nii' >>> node.inputs.legacy = 1 >>> node.inputs.n_iters = 6 >>> node.inputs.ftol = 0.002 - >>> node.cmdline # doctest: +ELLIPSIS - 'dti_diffeomorphic_reg ten1.nii.gz ten2.nii.gz mask.nii.gz 1 6 0.002' + >>> node.cmdline + 'dti_diffeomorphic_reg im1.nii im2.nii mask.nii 1 6 0.002' >>> node.run() # doctest: +SKIP """ input_spec = DiffeoInputSpec @@ -171,21 +185,22 @@ class DiffeoTask(CommandLineDtitk): def _list_outputs(self): outputs = self.output_spec().get() - outputs['out_file_xfm'] = self.inputs.moving_file.replace( - '.nii.gz', '_diffeo.df.nii.gz') - outputs['out_file'] = self.inputs.moving_file.replace( - '.nii.gz', '_diffeo.nii.gz') + splitlist = os.path.basename(self.inputs.moving_file).split('.') + basename = splitlist[0] + termination = '.'+'.'.join(splitlist[1:]) + outputs['out_file_xfm'] = basename+'_diffeo.df'+termination + outputs['out_file'] = basename+'_diffeo'+termination return outputs class ComposeXfmInputSpec(CommandLineInputSpec): - in_df = File(desc='diffeomorphic warp diffeo_xfm.df.nii.gz', exists=True, + in_df = File(desc='diffeomorphic warp file', exists=True, argstr="-df %s", copyfile=False, mandatory=True) in_aff = File(desc='affine_xfm.aff', exists=True, argstr="-aff %s", mandatory=True) out_file = traits.Str(desc='output_path', exists=True, argstr="-out %s", name_source="in_df", - name_template="%s_aff.df.nii.gz") + name_template="%s_aff.df", keep_extension=True) class ComposeXfmOutputSpec(TraitedSpec): @@ -201,10 +216,10 @@ class ComposeXfmTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.ComposeXfmTask() - >>> node.inputs.in_df = 'myxfm.df.nii.gz' - >>> node.inputs.in_aff= 'myxfm.aff' - >>> node.cmdline # doctest: +ELLIPSIS - 'dfRightComposeAffine -df myxfm.df.nii.gz -aff myxfm.aff -out myxfm.df_aff.df.nii.gz' + >>> node.inputs.in_df = 'im1.nii' + >>> node.inputs.in_aff= 'im2.nii' + >>> node.cmdline + 'dfRightComposeAffine -aff im2.nii -df im1.nii -out im1_aff.df' >>> node.run() # doctest: +SKIP """ input_spec = ComposeXfmInputSpec @@ -250,10 +265,10 @@ class affSymTensor3DVolTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.affSymTensor3DVolTask() - >>> node.inputs.in_file = 'ten.nii' - >>> node.inputs.transform = 'aff.txt' - >>> node.cmdline # doctest: +ELLIPSIS - 'affineSymTensor3DVolume -in ten.nii -interp LEI -out Ptensor_affxfmd.nii.gz -reorient PPD -trans aff.aff' + >>> node.inputs.in_file = 'im1.nii' + >>> node.inputs.transform = 'im2.nii' + >>> node.cmdline + 'affineSymTensor3DVolume -in im1.nii -interp LEI -out im1_affxfmd.nii -reorient PPD -trans im2.nii' >>> node.run() # doctest: +SKIP """ input_spec = affSymTensor3DVolInputSpec @@ -298,10 +313,10 @@ class affScalarVolTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.affScalarVolTask() - >>> node.inputs.in_volume = 'myvol.nii' - >>> node.inputs.in_xfm = 'myxfm.aff' - >>> node.cmdline # doctest: +ELLIPSIS - 'affineScalarVolume -in myvol.nii -interp 0 -out myvol_affxfmd.nii -trans myxfm.aff' + >>> node.inputs.in_file = 'im1.nii' + >>> node.inputs.transform = 'im2.nii' + >>> node.cmdline + 'affineScalarVolume -in im1.nii -interp 0 -out im1_affxfmd.nii -trans im2.nii' >>> node.run() # doctest: +SKIP """ input_spec = affScalarVolInputSpec @@ -347,10 +362,10 @@ class diffeoSymTensor3DVolTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.diffeoSymTensor3DVolTask() - >>> node.inputs.in_tensor = 'ten.nii' - >>> node.inputs.in_xfm = 'myxfm.df.nii' - >>> node.cmdline # doctest: +ELLIPSIS - 'deformationSymTensor3DVolume -df FD -in ten.nii.gz -interp LEI -out ten_diffeoxfmd.nii.gz -reorient PPD -trans myxfm.df.nii' + >>> node.inputs.in_file = 'im1.nii' + >>> node.inputs.transform = 'im2.nii' + >>> node.cmdline + 'deformationSymTensor3DVolume -df FD -in im1.nii -interp LEI -out im1_diffeoxfmd.nii -reorient PPD -trans im2.nii' >>> node.run() # doctest: +SKIP """ @@ -392,10 +407,10 @@ class diffeoScalarVolTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.diffeoScalarVolTask() - >>> node.inputs.in_volume = 'sv.nii' - >>> node.inputs.in_xfm = 'myxfm.df.nii' - >>> node.cmdline # doctest: +ELLIPSIS - 'deformationScalarVolume -in sv.nii -interp 0 -out sv_diffeoxfmd.nii -trans myxfm.df.nii.gz' + >>> node.inputs.in_file = 'im1.nii' + >>> node.inputs.transform = 'im2.nii' + >>> node.cmdline + 'deformationScalarVolume -in im1.nii -interp 0 -out im1_diffeoxfmd.nii -trans im2.nii' >>> node.run() # doctest: +SKIP """ diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index 2903a80e14..f0aa5a9fbf 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -3,6 +3,17 @@ # vi: set ft=python sts=4 ts=4 sw=4 et: """DTITK utility interfaces +DTI-TK developed by Gary Hui Zhang, gary.zhang@ucl.ac.uk +For additional help, visit http://dti-tk.sf.net + +The high-dimensional tensor-based DTI registration algorithm + +Zhang, H., Avants, B.B, Yushkevich, P.A., Woo, J.H., Wang, S., McCluskey, L.H., Elman, L.B., Melhem, E.R., Gee, J.C., High-dimensional spatial normalization of diffusion tensor images improves the detection of white matter differences in amyotrophic lateral sclerosis, IEEE Transactions on Medical Imaging, 26(11):1585-1597, November 2007. PMID: 18041273. + +The original piecewise-affine tensor-based DTI registration algorithm at the core of DTI-TK + +Zhang, H., Yushkevich, P.A., Alexander, D.C., Gee, J.C., Deformable registration of diffusion tensor MR images with explicit orientation optimization, Medical Image Analysis, 10(5):764-785, October 2006. PMID: 16899392. + """ __author__ = 'kjordan' @@ -11,6 +22,7 @@ import os from .base import CommandLineDtitk +__docformat__ = 'restructuredtext' class TVAdjustVoxSpInputSpec(CommandLineInputSpec): in_file = File(desc="tensor volume to modify", exists=True, @@ -43,10 +55,10 @@ class TVAdjustVoxSpTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.TVAdjustVoxSpTask() - >>> node.inputs.in_file = 'diff1.nii' - >>> node.inputs.target_file = 'diff2.nii' - >>> node.cmdline # doctest: +ELLIPSIS - 'TVAdjustVoxelspace -in diff1.nii -out diff1_avs.nii -target 'diff2.nii'' + >>> node.inputs.in_file = 'im1.nii' + >>> node.inputs.target_file = 'im2.nii' + >>> node.cmdline + 'TVAdjustVoxelspace -in im1.nii -out im1_avs.nii -target im2.nii' >>> node.run() # doctest: +SKIP """ input_spec = TVAdjustVoxSpInputSpec @@ -84,10 +96,10 @@ class SVAdjustVoxSpTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.SVAdjustVoxSpTask() - >>> node.inputs.in_file = 'vol1.nii' - >>> node.inputs.target_file = 'vol2.nii' - >>> node.cmdline # doctest: +ELLIPSIS - 'TVAdjustVoxelspace -in vol1.nii -out vol1_avs.nii -target 'vol2.nii'' + >>> node.inputs.in_file = 'im1.nii' + >>> node.inputs.target_file = 'im2.nii' + >>> node.cmdline + 'SVAdjustVoxelspace -in im1.nii -out im1_avs.nii -target im2.nii' >>> node.run() # doctest: +SKIP """ input_spec = SVAdjustVoxSpInputSpec @@ -132,10 +144,10 @@ class TVResampleTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.TVResampleTask() - >>> node.inputs.in_file = 'ten1.nii.gz' - >>> node.inputs.target_file = 'ten2.nii.gz' - >>> node.cmdline # doctest: +ELLIPSIS - 'TVResample -in ten1.nii -out ten1_resampled.nii -target 'ten2.nii'' + >>> node.inputs.in_file = 'im1.nii' + >>> node.inputs.target_file = 'im2.nii' + >>> node.cmdline + 'TVResample -in im1.nii -out im1_resampled.nii -target im2.nii' >>> node.run() # doctest: +SKIP """ input_spec = TVResampleInputSpec @@ -169,6 +181,7 @@ class SVResampleOutputSpec(TraitedSpec): out_file = File(exists=True) + class SVResampleTask(CommandLineDtitk): """ Resamples a scalar volume @@ -177,11 +190,11 @@ class SVResampleTask(CommandLineDtitk): ------- >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.TVResampleTask() - >>> node.inputs.in_file = 'vol1.nii.gz' - >>> node.inputs.target_file = 'vol2.nii.gz' - >>> node.cmdline # doctest: +ELLIPSIS - 'SVResample -in vol1.nii -out vol1_resampled.nii -target 'vol2.nii'' + >>> node = dtitk.SVResampleTask() + >>> node.inputs.in_file = 'im1.nii' + >>> node.inputs.target_file = 'im2.nii' + >>> node.cmdline + 'SVResample -in im1.nii -out im1_resampled.nii -target im2.nii' >>> node.run() # doctest: +SKIP """ input_spec = SVResampleInputSpec @@ -212,10 +225,10 @@ class TVtoolTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.TVtoolTask() - >>> node.inputs.in_file = 'diffusion.nii' + >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.in_flag = 'fa' - >>> node.cmdline # doctest: +ELLIPSIS - 'TVtool -in diffusion.nii -fa -out diffusion_fa.nii.gz' + >>> node.cmdline + 'TVtool -in im1.nii -fa -out im1_fa.nii' >>> node.run() # doctest: +SKIP """ input_spec = TVtoolInputSpec @@ -231,8 +244,10 @@ def _list_outputs(self): return outputs def _gen_filename(self, name): - basename = os.path.basename(self.inputs.in_file).split('.')[0] - return basename + '_'+self.inputs.in_flag+'.nii.gz' + splitlist = os.path.basename(self.inputs.in_file).split('.') + basename = splitlist[0] + termination = '.' + '.'.join(splitlist[1:]) + return basename + '_'+self.inputs.in_flag + termination '''Note: SVTool not implemented at this time''' @@ -265,13 +280,13 @@ class BinThreshTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.BinThreshTask() - >>> node.inputs.in_file = 'diffusion.nii' + >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.lower_bound = 0 >>> node.inputs.upper_bound = 100 >>> node.inputs.inside_value = 1 >>> node.inputs.outside_value = 0 >>> node.cmdline - 'BinaryThresholdImageFilter diffusion.nii diffusion_bin.nii 0.0 100.0 1.0 0.0' + 'BinaryThresholdImageFilter im1.nii im1_thrbin.nii 0 100 1 0' >>> node.run() # doctest: +SKIP """ From 2acb24197db30d5e2f82a07ac07c14e620ef7725 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Mon, 26 Mar 2018 17:14:38 -0700 Subject: [PATCH 25/53] add tests --- .../dtitk/tests/test_auto_AffineTask.py | 28 ++--- .../dtitk/tests/test_auto_BinThreshTask.py | 32 +++-- .../dtitk/tests/test_auto_ComposeXfmTask.py | 14 +-- .../dtitk/tests/test_auto_DiffeoTask.py | 12 +- .../dtitk/tests/test_auto_RigidTask.py | 30 ++--- .../tests/test_auto_SVAdjustVoxSpTask.py | 34 ++---- .../dtitk/tests/test_auto_SVResampleTask.py | 35 +++--- .../tests/test_auto_TVAdjustOriginTask.py | 50 -------- .../tests/test_auto_TVAdjustVoxSpTask.py | 27 ++--- .../dtitk/tests/test_auto_TVResampleTask.py | 36 +++--- .../dtitk/tests/test_auto_TVtoolTask.py | 11 +- .../dtitk/tests/test_auto_affScalarVolTask.py | 46 +++++--- .../tests/test_auto_affSymTensor3DVolTask.py | 51 +++++--- .../tests/test_auto_diffeoScalarVolTask.py | 64 +++++----- .../test_auto_diffeoSymTensor3DVolTask.py | 55 ++++++--- nipype/interfaces/tests/test_auto_Dcm2nii.py | 110 ------------------ 16 files changed, 242 insertions(+), 393 deletions(-) delete mode 100644 nipype/interfaces/dtitk/tests/test_auto_TVAdjustOriginTask.py delete mode 100644 nipype/interfaces/tests/test_auto_Dcm2nii.py diff --git a/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py b/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py index cff7d1c0d1..52e22e7915 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py @@ -12,14 +12,14 @@ def test_AffineTask_inputs(): ), fixed_file=dict( argstr='%s', - exists=True, mandatory=True, position=0, ), ftol=dict( argstr='%s', mandatory=True, - position=6, + position=4, + usedefault=True, ), ignore_exception=dict( deprecated='1.0.0', @@ -28,39 +28,29 @@ def test_AffineTask_inputs(): ), moving_file=dict( argstr='%s', - exists=True, + copyfile=False, mandatory=True, position=1, ), - samplingX=dict( - argstr='%s', + samplingXYZ=dict( + argstr='%g %g %g', mandatory=True, position=3, - ), - samplingY=dict( - argstr='%s', - mandatory=True, - position=4, - ), - samplingZ=dict( - argstr='%s', - mandatory=True, - position=5, + usedefault=True, ), similarity_metric=dict( argstr='%s', - exists=True, mandatory=True, position=2, + usedefault=True, ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), useInTrans=dict( - argstr='%s', - mandatory=False, - position=7, + argstr='1', + position=5, ), ) inputs = AffineTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_BinThreshTask.py b/nipype/interfaces/dtitk/tests/test_auto_BinThreshTask.py index 028a820bae..1f49ddce43 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_BinThreshTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_BinThreshTask.py @@ -17,26 +17,42 @@ def test_BinThreshTask_inputs(): ), in_file=dict( argstr='%s', - exists=True, - mandatory=False, + mandatory=True, position=0, ), - in_numbers=dict( - argstr='%s', - exists=True, - mandatory=False, + inside_value=dict( + argstr='%g', + mandatory=True, + position=4, + usedefault=True, + ), + lower_bound=dict( + argstr='%g', + mandatory=True, position=2, ), out_file=dict( argstr='%s', - exists=True, - mandatory=False, + keep_extension=True, + name_source='in_file', + name_template='%s_thrbin', position=1, ), + outside_value=dict( + argstr='%g', + mandatory=True, + position=5, + usedefault=True, + ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), + upper_bound=dict( + argstr='%g', + mandatory=True, + position=3, + ), ) inputs = BinThreshTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py b/nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py index ec5d2153ea..bc6f5c4aab 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py @@ -17,23 +17,19 @@ def test_ComposeXfmTask_inputs(): ), in_aff=dict( argstr='-aff %s', - exists=True, - mandatory=False, - position=0, + mandatory=True, ), in_df=dict( argstr='-df %s', - exists=True, - mandatory=False, - position=1, + copyfile=False, + mandatory=True, ), out_file=dict( argstr='-out %s', exists=True, - mandatory=False, + keep_extension=True, name_source='in_df', - name_template='%s_comboaff.nii.gz', - position=2, + name_template='%s_aff.df', ), terminal_output=dict( deprecated='1.0.0', diff --git a/nipype/interfaces/dtitk/tests/test_auto_DiffeoTask.py b/nipype/interfaces/dtitk/tests/test_auto_DiffeoTask.py index a0bc0a580b..544cc51e89 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_DiffeoTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_DiffeoTask.py @@ -12,8 +12,6 @@ def test_DiffeoTask_inputs(): ), fixed_file=dict( argstr='%s', - exists=True, - mandatory=False, position=0, ), ftol=dict( @@ -21,6 +19,7 @@ def test_DiffeoTask_inputs(): exists=True, mandatory=True, position=5, + usedefault=True, ), ignore_exception=dict( deprecated='1.0.0', @@ -32,17 +31,15 @@ def test_DiffeoTask_inputs(): exists=True, mandatory=True, position=3, + usedefault=True, ), - mask=dict( + mask_file=dict( argstr='%s', - exists=True, - mandatory=False, position=2, ), moving_file=dict( argstr='%s', - exists=True, - mandatory=False, + copyfile=False, position=1, ), n_iters=dict( @@ -50,6 +47,7 @@ def test_DiffeoTask_inputs(): exists=True, mandatory=True, position=4, + usedefault=True, ), terminal_output=dict( deprecated='1.0.0', diff --git a/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py b/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py index fbe65d92f2..e6c978c0fd 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py @@ -12,14 +12,14 @@ def test_RigidTask_inputs(): ), fixed_file=dict( argstr='%s', - exists=True, mandatory=True, position=0, ), ftol=dict( - argstr='%s', + argstr='%g', mandatory=True, - position=6, + position=4, + usedefault=True, ), ignore_exception=dict( deprecated='1.0.0', @@ -28,39 +28,29 @@ def test_RigidTask_inputs(): ), moving_file=dict( argstr='%s', - exists=True, + copyfile=False, mandatory=True, position=1, ), - samplingX=dict( - argstr='%s', + samplingXYZ=dict( + argstr='%g %g %g', mandatory=True, position=3, - ), - samplingY=dict( - argstr='%s', - mandatory=True, - position=4, - ), - samplingZ=dict( - argstr='%s', - mandatory=True, - position=5, + usedefault=True, ), similarity_metric=dict( argstr='%s', - exists=True, mandatory=True, position=2, + usedefault=True, ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), useInTrans=dict( - argstr='%s', - mandatory=False, - position=7, + argstr='1', + position=5, ), ) inputs = RigidTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSpTask.py b/nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSpTask.py index d60b203ffa..88f328d80b 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSpTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSpTask.py @@ -17,40 +17,30 @@ def test_SVAdjustVoxSpTask_inputs(): ), in_file=dict( argstr='-in %s', - exists=True, mandatory=True, - position=0, - ), - in_target=dict( - argstr='-target %s', - exists=True, - mandatory=False, - position=2, - ), - in_voxsz=dict( - argstr='-vsize %s', - exists=True, - mandatory=False, - position=3, ), origin=dict( - argstr='-origin %s', - exists=True, - mandatory=False, - position=4, + argstr='-origin %g %g %g', + xor=['target_file'], ), out_file=dict( argstr='-out %s', - exists=True, - mandatory=False, + keep_extension=True, name_source='in_file', - name_template='%s_origmvd.nii.gz', - position=1, + name_template='%s_avs', + ), + target_file=dict( + argstr='-target %s', + xor=['voxel_size', 'origin'], ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target_file'], + ), ) inputs = SVAdjustVoxSpTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_SVResampleTask.py b/nipype/interfaces/dtitk/tests/test_auto_SVResampleTask.py index 64f4cadb60..8058c94435 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_SVResampleTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_SVResampleTask.py @@ -5,7 +5,12 @@ def test_SVResampleTask_inputs(): input_map = dict( + align=dict(argstr='-align %s', ), args=dict(argstr='%s', ), + array_size=dict( + argstr='-size %d %d %d', + xor=['target_file'], + ), environ=dict( nohash=True, usedefault=True, @@ -15,36 +20,32 @@ def test_SVResampleTask_inputs(): nohash=True, usedefault=True, ), - in_arraysz=dict( - argstr='-size %s', - exists=True, - mandatory=False, - position=1, - ), in_file=dict( argstr='-in %s', - exists=True, mandatory=True, - position=0, ), - in_voxsz=dict( - argstr='-vsize %s', - exists=True, - mandatory=False, - position=2, + origin=dict( + argstr='-origin %g %g %g', + xor=['target_file'], ), out_file=dict( argstr='-out %s', - exists=True, - mandatory=False, + keep_extension=True, name_source='in_file', - name_template='%s_resampled.nii.gz', - position=3, + name_template='%s_resampled', + ), + target_file=dict( + argstr='-target %s', + xor=['array_size', 'voxel_size', 'origin'], ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target_file'], + ), ) inputs = SVResampleTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVAdjustOriginTask.py b/nipype/interfaces/dtitk/tests/test_auto_TVAdjustOriginTask.py deleted file mode 100644 index bad6039007..0000000000 --- a/nipype/interfaces/dtitk/tests/test_auto_TVAdjustOriginTask.py +++ /dev/null @@ -1,50 +0,0 @@ -# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT -from __future__ import unicode_literals -from ..utils import TVAdjustOriginTask - - -def test_TVAdjustOriginTask_inputs(): - input_map = dict( - args=dict(argstr='%s', ), - environ=dict( - nohash=True, - usedefault=True, - ), - ignore_exception=dict( - deprecated='1.0.0', - nohash=True, - usedefault=True, - ), - in_file=dict( - argstr='-in %s', - mandatory=True, - position=0, - ), - origin=dict( - argstr='-origin %s', - exists=True, - mandatory=False, - position=4, - ), - out_file=dict( - argstr='-out %s', - genfile=True, - position=1, - ), - terminal_output=dict( - deprecated='1.0.0', - nohash=True, - ), - ) - inputs = TVAdjustOriginTask.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_TVAdjustOriginTask_outputs(): - output_map = dict(out_file=dict(exists=True, ), ) - outputs = TVAdjustOriginTask.output_spec() - - for key, metadata in list(output_map.items()): - for metakey, value in list(metadata.items()): - assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSpTask.py b/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSpTask.py index 2da57d8862..b506137add 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSpTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSpTask.py @@ -18,34 +18,29 @@ def test_TVAdjustVoxSpTask_inputs(): in_file=dict( argstr='-in %s', mandatory=True, - position=0, ), origin=dict( - argstr='-origin %s', - exists=True, - mandatory=False, - position=4, + argstr='-origin %g %g %g', + xor=['target_file'], ), out_file=dict( argstr='-out %s', genfile=True, - position=1, + keep_extension=True, + name_source='in_file', + name_template='%s_avs', ), - target=dict( + target_file=dict( argstr='-target %s', - exists=True, - mandatory=False, - position=2, + xor=['voxel_size', 'origin'], ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), - vsize=dict( - argstr='-vsize %s', - exists=True, - mandatory=False, - position=3, + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target_file'], ), ) inputs = TVAdjustVoxSpTask.input_spec() @@ -54,7 +49,7 @@ def test_TVAdjustVoxSpTask_inputs(): for metakey, value in list(metadata.items()): assert getattr(inputs.traits()[key], metakey) == value def test_TVAdjustVoxSpTask_outputs(): - output_map = dict(out_file=dict(exists=True, ), ) + output_map = dict(out_file=dict(), ) outputs = TVAdjustVoxSpTask.output_spec() for key, metadata in list(output_map.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVResampleTask.py b/nipype/interfaces/dtitk/tests/test_auto_TVResampleTask.py index 044e8f67d2..43ae1cd842 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_TVResampleTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_TVResampleTask.py @@ -5,7 +5,12 @@ def test_TVResampleTask_inputs(): input_map = dict( + align=dict(argstr='-align %s', ), args=dict(argstr='%s', ), + array_size=dict( + argstr='-size %d %d %d', + xor=['target_file'], + ), environ=dict( nohash=True, usedefault=True, @@ -15,36 +20,33 @@ def test_TVResampleTask_inputs(): nohash=True, usedefault=True, ), - in_arraysz=dict( - argstr='-size %s', - exists=True, - mandatory=False, - position=1, - ), in_file=dict( argstr='-in %s', - exists=True, mandatory=True, - position=0, ), - in_voxsz=dict( - argstr='-vsize %s', - exists=True, - mandatory=False, - position=2, + interpolation=dict(argstr='-interp %s', ), + origin=dict( + argstr='-origin %g %g %g', + xor=['target_file'], ), out_file=dict( argstr='-out %s', - exists=True, - mandatory=False, + keep_extension=True, name_source='in_file', - name_template='%s_resampled.nii.gz', - position=3, + name_template='%s_resampled', + ), + target_file=dict( + argstr='-target %s', + xor=['array_size', 'voxel_size', 'origin'], ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target_file'], + ), ) inputs = TVResampleTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVtoolTask.py b/nipype/interfaces/dtitk/tests/test_auto_TVtoolTask.py index 8fb0ce055a..dece129a37 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_TVtoolTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_TVtoolTask.py @@ -17,15 +17,16 @@ def test_TVtoolTask_inputs(): ), in_file=dict( argstr='-in %s', - exists=True, - mandatory=False, - position=0, + mandatory=True, ), in_flag=dict( argstr='-%s', exists=True, - mandatory=False, - position=1, + ), + out_file=dict( + argstr='-out %s', + exists=True, + genfile=True, ), terminal_output=dict( deprecated='1.0.0', diff --git a/nipype/interfaces/dtitk/tests/test_auto_affScalarVolTask.py b/nipype/interfaces/dtitk/tests/test_auto_affScalarVolTask.py index 02d22b1820..7723e71ba7 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_affScalarVolTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_affScalarVolTask.py @@ -6,42 +6,54 @@ def test_affScalarVolTask_inputs(): input_map = dict( args=dict(argstr='%s', ), + deformation=dict( + argstr='-deformation %g %g %g %g %g %g', + xor=['transform'], + ), environ=dict( nohash=True, usedefault=True, ), + euler=dict( + argstr='-euler %g %g %g', + xor=['transform'], + ), ignore_exception=dict( deprecated='1.0.0', nohash=True, usedefault=True, ), - in_target=dict( - argstr='-target %s', - position=2, - ), - in_volume=dict( + in_file=dict( argstr='-in %s', - exists=True, - mandatory=False, - position=0, + mandatory=True, ), - in_xfm=dict( - argstr='-trans %s', - exists=True, - mandatory=False, - position=1, + interpolation=dict( + argstr='-interp %s', + usedefault=True, ), out_file=dict( argstr='-out %s', - mandatory=False, - name_source='in_volume', - name_template='%s_affxfmd.nii.gz', - position=3, + exists=True, + keep_extension=True, + name_source='in_file', + name_template='%s_affxfmd', + ), + target=dict( + argstr='-target %s', + xor=['transform'], ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), + transform=dict( + argstr='-trans %s', + xor=['target', 'translation', 'euler', 'deformation'], + ), + translation=dict( + argstr='-translation %g %g %g', + xor=['transform'], + ), ) inputs = affScalarVolTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVolTask.py b/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVolTask.py index 40198fa9e7..51bb260b48 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVolTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVolTask.py @@ -6,45 +6,58 @@ def test_affSymTensor3DVolTask_inputs(): input_map = dict( args=dict(argstr='%s', ), + deformation=dict( + argstr='-deformation %g %g %g %g %g %g', + xor=['transform'], + ), environ=dict( nohash=True, usedefault=True, ), + euler=dict( + argstr='-euler %g %g %g', + xor=['transform'], + ), ignore_exception=dict( deprecated='1.0.0', nohash=True, usedefault=True, ), - in_target=dict( - argstr='-target %s', - exists=True, - mandatory=False, - position=2, - ), - in_tensor=dict( + in_file=dict( argstr='-in %s', - exists=True, - mandatory=False, - position=0, + mandatory=True, ), - in_xfm=dict( - argstr='-trans %s', - exists=True, - mandatory=False, - position=1, + interpolation=dict( + argstr='-interp %s', + usedefault=True, ), out_file=dict( argstr='-out %s', exists=True, - mandatory=False, - name_source='in_tensor', - name_template='%s_affxfmd.nii.gz', - position=3, + keep_extension=True, + name_source='in_file', + name_template='%s_affxfmd', + ), + reorient=dict( + argstr='-reorient %s', + usedefault=True, + ), + target=dict( + argstr='-target %s', + xor=['transform'], ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), + transform=dict( + argstr='-trans %s', + xor=['target', 'translation', 'euler', 'deformation'], + ), + translation=dict( + argstr='-translation %g %g %g', + xor=['transform'], + ), ) inputs = affSymTensor3DVolTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVolTask.py b/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVolTask.py index 5b02f34984..09435c4415 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVolTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVolTask.py @@ -10,63 +10,51 @@ def test_diffeoScalarVolTask_inputs(): nohash=True, usedefault=True, ), + flip=dict( + argstr='-flip %s', + exists=True, + ), ignore_exception=dict( deprecated='1.0.0', nohash=True, usedefault=True, ), - in_flip=dict( - argstr='-flip %s', - exists=True, - mandatory=False, - position=5, + in_file=dict( + argstr='-in %s', + mandatory=True, ), - in_interp=dict( + interp=dict( argstr='-interp %s', exists=True, - mandatory=False, - position=7, + usedefault=True, ), - in_target=dict( - argstr='-target %s', + out_file=dict( + argstr='-out %s', exists=True, - mandatory=False, - position=3, + keep_extension=True, + name_source='in_file', + name_template='%s_diffeoxfmd', ), - in_type=dict( + resampling_type=dict( argstr='-type %s', exists=True, - mandatory=False, - position=6, - ), - in_volume=dict( - argstr='-in %s', - exists=True, - mandatory=False, - position=0, - ), - in_vsize=dict( - argstr='-vsize %s', - exists=True, - mandatory=False, - position=4, - ), - in_xfm=dict( - argstr='-trans %s', - exists=True, - mandatory=False, - position=2, ), - out_file=dict( - argstr='-out %s', - name_source='in_volume', - name_template='%s_diffeoxfmd.nii.gz', - position=1, + target=dict( + argstr='-target %s', + xor=['voxel_size'], ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), + transform=dict( + argstr='-trans %s', + mandatory=True, + ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target'], + ), ) inputs = diffeoScalarVolTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVolTask.py b/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVolTask.py index 7f3926c71b..2185ba1f56 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVolTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVolTask.py @@ -6,45 +6,62 @@ def test_diffeoSymTensor3DVolTask_inputs(): input_map = dict( args=dict(argstr='%s', ), + df=dict( + argstr='-df %s', + usedefault=True, + ), environ=dict( nohash=True, usedefault=True, ), + flip=dict( + argstr='-flip %s', + exists=True, + ), ignore_exception=dict( deprecated='1.0.0', nohash=True, usedefault=True, ), - in_target=dict( - argstr='-target %s', - exists=True, - mandatory=False, - position=2, - ), - in_tensor=dict( + in_file=dict( argstr='-in %s', - exists=True, - mandatory=False, - position=0, + mandatory=True, ), - in_xfm=dict( - argstr='-trans %s', - exists=True, - mandatory=False, - position=1, + interpolation=dict( + argstr='-interp %s', + usedefault=True, ), out_file=dict( argstr='-out %s', exists=True, - mandatory=False, - name_source='in_tensor', - name_template='%s_diffeoxfmd.nii.gz', - position=3, + keep_extension=True, + name_source='in_file', + name_template='%s_diffeoxfmd', + ), + reorient=dict( + argstr='-reorient %s', + usedefault=True, + ), + resampling_type=dict( + argstr='-type %s', + exists=True, + ), + target=dict( + argstr='-target %s', + xor=['voxel_size'], ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), + transform=dict( + argstr='-trans %s', + mandatory=True, + ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target'], + ), ) inputs = diffeoSymTensor3DVolTask.input_spec() diff --git a/nipype/interfaces/tests/test_auto_Dcm2nii.py b/nipype/interfaces/tests/test_auto_Dcm2nii.py deleted file mode 100644 index 044a0f918b..0000000000 --- a/nipype/interfaces/tests/test_auto_Dcm2nii.py +++ /dev/null @@ -1,110 +0,0 @@ -# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT -from __future__ import unicode_literals -from ..dcm2nii import Dcm2nii - - -def test_Dcm2nii_inputs(): - input_map = dict( - anonymize=dict( - argstr='-a', - usedefault=True, - ), - args=dict(argstr='%s', ), - collapse_folders=dict( - argstr='-c', - usedefault=True, - ), - config_file=dict( - argstr='-b %s', - genfile=True, - ), - convert_all_pars=dict( - argstr='-v', - usedefault=True, - ), - date_in_filename=dict( - argstr='-d', - usedefault=True, - ), - environ=dict( - nohash=True, - usedefault=True, - ), - events_in_filename=dict( - argstr='-e', - usedefault=True, - ), - gzip_output=dict( - argstr='-g', - usedefault=True, - ), - id_in_filename=dict( - argstr='-i', - usedefault=True, - ), - ignore_exception=dict( - deprecated='1.0.0', - nohash=True, - usedefault=True, - ), - nii_output=dict( - argstr='-n', - usedefault=True, - ), - output_dir=dict( - argstr='-o %s', - genfile=True, - ), - protocol_in_filename=dict( - argstr='-p', - usedefault=True, - ), - reorient=dict(argstr='-r', ), - reorient_and_crop=dict( - argstr='-x', - usedefault=True, - ), - source_dir=dict( - argstr='%s', - mandatory=True, - position=-1, - xor=['source_names'], - ), - source_in_filename=dict( - argstr='-f', - usedefault=True, - ), - source_names=dict( - argstr='%s', - copyfile=False, - mandatory=True, - position=-1, - xor=['source_dir'], - ), - spm_analyze=dict( - argstr='-s', - xor=['nii_output'], - ), - terminal_output=dict( - deprecated='1.0.0', - nohash=True, - ), - ) - inputs = Dcm2nii.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_Dcm2nii_outputs(): - output_map = dict( - bvals=dict(), - bvecs=dict(), - converted_files=dict(), - reoriented_and_cropped_files=dict(), - reoriented_files=dict(), - ) - outputs = Dcm2nii.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 ddfd19d17e4035242ce7e26bc4a1659a3f48455d Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Mon, 26 Mar 2018 20:03:29 -0700 Subject: [PATCH 26/53] added extra tests from other interfaces --- doc/devel/testing_nipype.rst | 12 +++++----- nipype/interfaces/afni/preprocess.py | 24 +++++++++---------- .../afni/tests/test_auto_TProject.py | 5 +--- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/doc/devel/testing_nipype.rst b/doc/devel/testing_nipype.rst index 03d063f2e5..0cce8b4671 100644 --- a/doc/devel/testing_nipype.rst +++ b/doc/devel/testing_nipype.rst @@ -54,7 +54,7 @@ environment variable is not set, some FreeSurfer related tests will fail. If any of the tests failed, please report them on our `bug tracker `_. -On Debian systems with a local copy of MATLAB installed, set the following +On Debian systems with a local copy of MATLAB installed, set the following environment variable before running tests:: export MATLABCMD=$pathtomatlabdir/bin/$platform/MATLAB @@ -74,8 +74,8 @@ A few tests in Nipype make use of some images distributed within the `FSL course `_. This reduced version of the package can be downloaded `here `_. To enable the tests depending on these data, just unpack the targz file and set the :code:`FSL_COURSE_DATA` environment -variable to point to that folder. -Note, that the test execution time can increase significantly with these additional tests. +variable to point to that folder. +Note, that the test execution time can increase significantly with these additional tests. Xfailed tests @@ -87,14 +87,14 @@ Some tests are expect to fail until the code will be changed or for other reason Testing Nipype using Docker --------------------------- -Nipype is tested inside Docker containers and users can use nipype images to test local versions. +Nipype is tested inside Docker containers and users can use nipype images to test local versions. First, install the `Docker Engine `_. Nipype has one base docker image called nipype/nipype:base, that contains several useful tools (FreeSurfer, AFNI, FSL, ANTs, etc.), and additional test images for specific Python versions: py27 for Python 2.7 and py36 for Python 3.6. Users can pull the nipype image for Python 3.6 as follows:: - + docker pull nipype/nipype:py36 In order to test a local version of nipype you can run test within container as follows:: @@ -105,5 +105,5 @@ In order to test a local version of nipype you can run test within container as Additional comments ------------------- -If the project is tested both on your local OS and within a Docker container, you might have to remove all +If the project is tested both on your local OS and within a Docker container, you might have to remove all ``__pycache__`` directories before switching between your OS and a container. diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index bb4ee8a342..595605e38b 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -2423,19 +2423,19 @@ class TProjectInputSpec(AFNICommandInputSpec): exists=True) censortr = traits.List( traits.Str(), - desc="""list of strings that specify time indexes + desc="""list of strings that specify time indexes to be removed from the analysis. Each string is - of one of the following forms: - 37 => remove global time index #37 - 2:37 => remove time index #37 in run #2 - 37..47 => remove global time indexes #37-47 - 37-47 => same as above - 2:37..47 => remove time indexes #37-47 in run #2 - *:0-2 => remove time indexes #0-2 in all runs - +Time indexes within each run start at 0. - +Run indexes start at 1 (just be to confusing). - +N.B.: 2:37,47 means index #37 in run #2 and - global time index 47; it does NOT mean + of one of the following forms: + 37 => remove global time index #37 + 2:37 => remove time index #37 in run #2 + 37..47 => remove global time indexes #37-47 + 37-47 => same as above + 2:37..47 => remove time indexes #37-47 in run #2 + *:0-2 => remove time indexes #0-2 in all runs + +Time indexes within each run start at 0. + +Run indexes start at 1 (just be to confusing). + +N.B.: 2:37,47 means index #37 in run #2 and + global time index 47; it does NOT mean index #37 in run #2 AND index #47 in run #2.""", argstr="-CENSORTR %s") cenmode = traits.Enum( diff --git a/nipype/interfaces/afni/tests/test_auto_TProject.py b/nipype/interfaces/afni/tests/test_auto_TProject.py index 25a47142b9..ffca499ea5 100644 --- a/nipype/interfaces/afni/tests/test_auto_TProject.py +++ b/nipype/interfaces/afni/tests/test_auto_TProject.py @@ -32,10 +32,7 @@ def test_TProject_inputs(): mandatory=True, position=1, ), - mask=dict( - argstr='-mask %s', - exist=True, - ), + mask=dict(argstr='-mask %s', ), noblock=dict(argstr='-noblock', ), norm=dict(argstr='-norm', ), num_threads=dict( From 37fb6f9d705d1a1f5325dcd68ff095a0742d0313 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Wed, 28 Mar 2018 16:25:20 -0700 Subject: [PATCH 27/53] renamed interfaces; regenerated auto tests --- ...st_auto_RigidTask.py => test_auto_Affine.py} | 10 +++++----- ..._BinThreshTask.py => test_auto_BinThresh.py} | 10 +++++----- ...omposeXfmTask.py => test_auto_ComposeXfm.py} | 11 +++++------ ...t_auto_DiffeoTask.py => test_auto_Diffeo.py} | 17 ++++++++--------- ...st_auto_AffineTask.py => test_auto_Rigid.py} | 12 ++++++------ ...tVoxSpTask.py => test_auto_SVAdjustVoxSp.py} | 10 +++++----- ...VResampleTask.py => test_auto_SVResample.py} | 10 +++++----- ...tVoxSpTask.py => test_auto_TVAdjustVoxSp.py} | 10 +++++----- ...VResampleTask.py => test_auto_TVResample.py} | 10 +++++----- ...t_auto_TVtoolTask.py => test_auto_TVtool.py} | 11 +++++------ ...alarVolTask.py => test_auto_affScalarVol.py} | 11 +++++------ ...olTask.py => test_auto_affSymTensor3DVol.py} | 11 +++++------ ...rVolTask.py => test_auto_diffeoScalarVol.py} | 17 ++++++++--------- ...ask.py => test_auto_diffeoSymTensor3DVol.py} | 15 +++++++-------- 14 files changed, 79 insertions(+), 86 deletions(-) rename nipype/interfaces/dtitk/tests/{test_auto_RigidTask.py => test_auto_Affine.py} (90%) rename nipype/interfaces/dtitk/tests/{test_auto_BinThreshTask.py => test_auto_BinThresh.py} (90%) rename nipype/interfaces/dtitk/tests/{test_auto_ComposeXfmTask.py => test_auto_ComposeXfm.py} (84%) rename nipype/interfaces/dtitk/tests/{test_auto_DiffeoTask.py => test_auto_Diffeo.py} (85%) rename nipype/interfaces/dtitk/tests/{test_auto_AffineTask.py => test_auto_Rigid.py} (89%) rename nipype/interfaces/dtitk/tests/{test_auto_SVAdjustVoxSpTask.py => test_auto_SVAdjustVoxSp.py} (87%) rename nipype/interfaces/dtitk/tests/{test_auto_SVResampleTask.py => test_auto_SVResample.py} (89%) rename nipype/interfaces/dtitk/tests/{test_auto_TVAdjustVoxSpTask.py => test_auto_TVAdjustVoxSp.py} (87%) rename nipype/interfaces/dtitk/tests/{test_auto_TVResampleTask.py => test_auto_TVResample.py} (89%) rename nipype/interfaces/dtitk/tests/{test_auto_TVtoolTask.py => test_auto_TVtool.py} (85%) rename nipype/interfaces/dtitk/tests/{test_auto_affScalarVolTask.py => test_auto_affScalarVol.py} (88%) rename nipype/interfaces/dtitk/tests/{test_auto_affSymTensor3DVolTask.py => test_auto_affSymTensor3DVol.py} (88%) rename nipype/interfaces/dtitk/tests/{test_auto_diffeoScalarVolTask.py => test_auto_diffeoScalarVol.py} (82%) rename nipype/interfaces/dtitk/tests/{test_auto_diffeoSymTensor3DVolTask.py => test_auto_diffeoSymTensor3DVol.py} (84%) diff --git a/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py b/nipype/interfaces/dtitk/tests/test_auto_Affine.py similarity index 90% rename from nipype/interfaces/dtitk/tests/test_auto_RigidTask.py rename to nipype/interfaces/dtitk/tests/test_auto_Affine.py index e6c978c0fd..d7ca264464 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_Affine.py @@ -1,9 +1,9 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..registration import RigidTask +from ..registration import Affine -def test_RigidTask_inputs(): +def test_Affine_inputs(): input_map = dict( args=dict(argstr='%s', ), environ=dict( @@ -53,17 +53,17 @@ def test_RigidTask_inputs(): position=5, ), ) - inputs = RigidTask.input_spec() + inputs = Affine.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_RigidTask_outputs(): +def test_Affine_outputs(): output_map = dict( out_file=dict(), out_file_xfm=dict(), ) - outputs = RigidTask.output_spec() + outputs = Affine.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_BinThreshTask.py b/nipype/interfaces/dtitk/tests/test_auto_BinThresh.py similarity index 90% rename from nipype/interfaces/dtitk/tests/test_auto_BinThreshTask.py rename to nipype/interfaces/dtitk/tests/test_auto_BinThresh.py index 1f49ddce43..1004dd42cb 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_BinThreshTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_BinThresh.py @@ -1,9 +1,9 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..utils import BinThreshTask +from ..utils import BinThresh -def test_BinThreshTask_inputs(): +def test_BinThresh_inputs(): input_map = dict( args=dict(argstr='%s', ), environ=dict( @@ -54,14 +54,14 @@ def test_BinThreshTask_inputs(): position=3, ), ) - inputs = BinThreshTask.input_spec() + inputs = BinThresh.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_BinThreshTask_outputs(): +def test_BinThresh_outputs(): output_map = dict(out_file=dict(), ) - outputs = BinThreshTask.output_spec() + outputs = BinThresh.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py b/nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py similarity index 84% rename from nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py rename to nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py index bc6f5c4aab..19c7525733 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py @@ -1,9 +1,9 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..registration import ComposeXfmTask +from ..registration import ComposeXfm -def test_ComposeXfmTask_inputs(): +def test_ComposeXfm_inputs(): input_map = dict( args=dict(argstr='%s', ), environ=dict( @@ -26,7 +26,6 @@ def test_ComposeXfmTask_inputs(): ), out_file=dict( argstr='-out %s', - exists=True, keep_extension=True, name_source='in_df', name_template='%s_aff.df', @@ -36,14 +35,14 @@ def test_ComposeXfmTask_inputs(): nohash=True, ), ) - inputs = ComposeXfmTask.input_spec() + inputs = ComposeXfm.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_ComposeXfmTask_outputs(): +def test_ComposeXfm_outputs(): output_map = dict(out_file=dict(), ) - outputs = ComposeXfmTask.output_spec() + outputs = ComposeXfm.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_DiffeoTask.py b/nipype/interfaces/dtitk/tests/test_auto_Diffeo.py similarity index 85% rename from nipype/interfaces/dtitk/tests/test_auto_DiffeoTask.py rename to nipype/interfaces/dtitk/tests/test_auto_Diffeo.py index 544cc51e89..d14424d5f0 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_DiffeoTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_Diffeo.py @@ -1,9 +1,9 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..registration import DiffeoTask +from ..registration import Diffeo -def test_DiffeoTask_inputs(): +def test_Diffeo_inputs(): input_map = dict( args=dict(argstr='%s', ), environ=dict( @@ -15,7 +15,7 @@ def test_DiffeoTask_inputs(): position=0, ), ftol=dict( - argstr='%s', + argstr='%g', exists=True, mandatory=True, position=5, @@ -27,8 +27,7 @@ def test_DiffeoTask_inputs(): usedefault=True, ), legacy=dict( - argstr='%s', - exists=True, + argstr='%d', mandatory=True, position=3, usedefault=True, @@ -43,7 +42,7 @@ def test_DiffeoTask_inputs(): position=1, ), n_iters=dict( - argstr='%s', + argstr='%d', exists=True, mandatory=True, position=4, @@ -54,17 +53,17 @@ def test_DiffeoTask_inputs(): nohash=True, ), ) - inputs = DiffeoTask.input_spec() + inputs = Diffeo.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_DiffeoTask_outputs(): +def test_Diffeo_outputs(): output_map = dict( out_file=dict(), out_file_xfm=dict(), ) - outputs = DiffeoTask.output_spec() + outputs = Diffeo.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py b/nipype/interfaces/dtitk/tests/test_auto_Rigid.py similarity index 89% rename from nipype/interfaces/dtitk/tests/test_auto_AffineTask.py rename to nipype/interfaces/dtitk/tests/test_auto_Rigid.py index 52e22e7915..0d5fdee8ee 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_Rigid.py @@ -1,9 +1,9 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..registration import AffineTask +from ..registration import Rigid -def test_AffineTask_inputs(): +def test_Rigid_inputs(): input_map = dict( args=dict(argstr='%s', ), environ=dict( @@ -16,7 +16,7 @@ def test_AffineTask_inputs(): position=0, ), ftol=dict( - argstr='%s', + argstr='%g', mandatory=True, position=4, usedefault=True, @@ -53,17 +53,17 @@ def test_AffineTask_inputs(): position=5, ), ) - inputs = AffineTask.input_spec() + inputs = Rigid.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_AffineTask_outputs(): +def test_Rigid_outputs(): output_map = dict( out_file=dict(), out_file_xfm=dict(), ) - outputs = AffineTask.output_spec() + outputs = Rigid.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSpTask.py b/nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSp.py similarity index 87% rename from nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSpTask.py rename to nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSp.py index 88f328d80b..3fefd1044d 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSpTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSp.py @@ -1,9 +1,9 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..utils import SVAdjustVoxSpTask +from ..utils import SVAdjustVoxSp -def test_SVAdjustVoxSpTask_inputs(): +def test_SVAdjustVoxSp_inputs(): input_map = dict( args=dict(argstr='%s', ), environ=dict( @@ -42,14 +42,14 @@ def test_SVAdjustVoxSpTask_inputs(): xor=['target_file'], ), ) - inputs = SVAdjustVoxSpTask.input_spec() + inputs = SVAdjustVoxSp.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_SVAdjustVoxSpTask_outputs(): +def test_SVAdjustVoxSp_outputs(): output_map = dict(out_file=dict(), ) - outputs = SVAdjustVoxSpTask.output_spec() + outputs = SVAdjustVoxSp.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_SVResampleTask.py b/nipype/interfaces/dtitk/tests/test_auto_SVResample.py similarity index 89% rename from nipype/interfaces/dtitk/tests/test_auto_SVResampleTask.py rename to nipype/interfaces/dtitk/tests/test_auto_SVResample.py index 8058c94435..e11f4e111e 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_SVResampleTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_SVResample.py @@ -1,9 +1,9 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..utils import SVResampleTask +from ..utils import SVResample -def test_SVResampleTask_inputs(): +def test_SVResample_inputs(): input_map = dict( align=dict(argstr='-align %s', ), args=dict(argstr='%s', ), @@ -47,14 +47,14 @@ def test_SVResampleTask_inputs(): xor=['target_file'], ), ) - inputs = SVResampleTask.input_spec() + inputs = SVResample.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_SVResampleTask_outputs(): +def test_SVResample_outputs(): output_map = dict(out_file=dict(), ) - outputs = SVResampleTask.output_spec() + outputs = SVResample.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSpTask.py b/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSp.py similarity index 87% rename from nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSpTask.py rename to nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSp.py index b506137add..772e35f8e7 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSpTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSp.py @@ -1,9 +1,9 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..utils import TVAdjustVoxSpTask +from ..utils import TVAdjustVoxSp -def test_TVAdjustVoxSpTask_inputs(): +def test_TVAdjustVoxSp_inputs(): input_map = dict( args=dict(argstr='%s', ), environ=dict( @@ -43,14 +43,14 @@ def test_TVAdjustVoxSpTask_inputs(): xor=['target_file'], ), ) - inputs = TVAdjustVoxSpTask.input_spec() + inputs = TVAdjustVoxSp.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_TVAdjustVoxSpTask_outputs(): +def test_TVAdjustVoxSp_outputs(): output_map = dict(out_file=dict(), ) - outputs = TVAdjustVoxSpTask.output_spec() + outputs = TVAdjustVoxSp.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVResampleTask.py b/nipype/interfaces/dtitk/tests/test_auto_TVResample.py similarity index 89% rename from nipype/interfaces/dtitk/tests/test_auto_TVResampleTask.py rename to nipype/interfaces/dtitk/tests/test_auto_TVResample.py index 43ae1cd842..6a1a01a594 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_TVResampleTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_TVResample.py @@ -1,9 +1,9 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..utils import TVResampleTask +from ..utils import TVResample -def test_TVResampleTask_inputs(): +def test_TVResample_inputs(): input_map = dict( align=dict(argstr='-align %s', ), args=dict(argstr='%s', ), @@ -48,14 +48,14 @@ def test_TVResampleTask_inputs(): xor=['target_file'], ), ) - inputs = TVResampleTask.input_spec() + inputs = TVResample.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_TVResampleTask_outputs(): +def test_TVResample_outputs(): output_map = dict(out_file=dict(), ) - outputs = TVResampleTask.output_spec() + outputs = TVResample.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVtoolTask.py b/nipype/interfaces/dtitk/tests/test_auto_TVtool.py similarity index 85% rename from nipype/interfaces/dtitk/tests/test_auto_TVtoolTask.py rename to nipype/interfaces/dtitk/tests/test_auto_TVtool.py index dece129a37..4f3bae6836 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_TVtoolTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_TVtool.py @@ -1,9 +1,9 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..utils import TVtoolTask +from ..utils import TVtool -def test_TVtoolTask_inputs(): +def test_TVtool_inputs(): input_map = dict( args=dict(argstr='%s', ), environ=dict( @@ -25,7 +25,6 @@ def test_TVtoolTask_inputs(): ), out_file=dict( argstr='-out %s', - exists=True, genfile=True, ), terminal_output=dict( @@ -33,14 +32,14 @@ def test_TVtoolTask_inputs(): nohash=True, ), ) - inputs = TVtoolTask.input_spec() + inputs = TVtool.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_TVtoolTask_outputs(): +def test_TVtool_outputs(): output_map = dict(out_file=dict(), ) - outputs = TVtoolTask.output_spec() + outputs = TVtool.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_affScalarVolTask.py b/nipype/interfaces/dtitk/tests/test_auto_affScalarVol.py similarity index 88% rename from nipype/interfaces/dtitk/tests/test_auto_affScalarVolTask.py rename to nipype/interfaces/dtitk/tests/test_auto_affScalarVol.py index 7723e71ba7..d5f229dcc9 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_affScalarVolTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_affScalarVol.py @@ -1,9 +1,9 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..registration import affScalarVolTask +from ..registration import affScalarVol -def test_affScalarVolTask_inputs(): +def test_affScalarVol_inputs(): input_map = dict( args=dict(argstr='%s', ), deformation=dict( @@ -33,7 +33,6 @@ def test_affScalarVolTask_inputs(): ), out_file=dict( argstr='-out %s', - exists=True, keep_extension=True, name_source='in_file', name_template='%s_affxfmd', @@ -55,14 +54,14 @@ def test_affScalarVolTask_inputs(): xor=['transform'], ), ) - inputs = affScalarVolTask.input_spec() + inputs = affScalarVol.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_affScalarVolTask_outputs(): +def test_affScalarVol_outputs(): output_map = dict(out_file=dict(), ) - outputs = affScalarVolTask.output_spec() + outputs = affScalarVol.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVolTask.py b/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVol.py similarity index 88% rename from nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVolTask.py rename to nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVol.py index 51bb260b48..708aabff73 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVolTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVol.py @@ -1,9 +1,9 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..registration import affSymTensor3DVolTask +from ..registration import affSymTensor3DVol -def test_affSymTensor3DVolTask_inputs(): +def test_affSymTensor3DVol_inputs(): input_map = dict( args=dict(argstr='%s', ), deformation=dict( @@ -33,7 +33,6 @@ def test_affSymTensor3DVolTask_inputs(): ), out_file=dict( argstr='-out %s', - exists=True, keep_extension=True, name_source='in_file', name_template='%s_affxfmd', @@ -59,14 +58,14 @@ def test_affSymTensor3DVolTask_inputs(): xor=['transform'], ), ) - inputs = affSymTensor3DVolTask.input_spec() + inputs = affSymTensor3DVol.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_affSymTensor3DVolTask_outputs(): +def test_affSymTensor3DVol_outputs(): output_map = dict(out_file=dict(), ) - outputs = affSymTensor3DVolTask.output_spec() + outputs = affSymTensor3DVol.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVolTask.py b/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVol.py similarity index 82% rename from nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVolTask.py rename to nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVol.py index 09435c4415..1fb6b423fb 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVolTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVol.py @@ -1,9 +1,9 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..registration import diffeoScalarVolTask +from ..registration import diffeoScalarVol -def test_diffeoScalarVolTask_inputs(): +def test_diffeoScalarVol_inputs(): input_map = dict( args=dict(argstr='%s', ), environ=dict( @@ -11,7 +11,7 @@ def test_diffeoScalarVolTask_inputs(): usedefault=True, ), flip=dict( - argstr='-flip %s', + argstr='-flip %d %d %d', exists=True, ), ignore_exception=dict( @@ -24,19 +24,18 @@ def test_diffeoScalarVolTask_inputs(): mandatory=True, ), interp=dict( - argstr='-interp %s', + argstr='-interp %d', exists=True, usedefault=True, ), out_file=dict( argstr='-out %s', - exists=True, keep_extension=True, name_source='in_file', name_template='%s_diffeoxfmd', ), resampling_type=dict( - argstr='-type %s', + argstr='-type %d', exists=True, ), target=dict( @@ -56,14 +55,14 @@ def test_diffeoScalarVolTask_inputs(): xor=['target'], ), ) - inputs = diffeoScalarVolTask.input_spec() + inputs = diffeoScalarVol.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_diffeoScalarVolTask_outputs(): +def test_diffeoScalarVol_outputs(): output_map = dict(out_file=dict(), ) - outputs = diffeoScalarVolTask.output_spec() + outputs = diffeoScalarVol.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVolTask.py b/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVol.py similarity index 84% rename from nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVolTask.py rename to nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVol.py index 2185ba1f56..b365a113b8 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVolTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVol.py @@ -1,9 +1,9 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..registration import diffeoSymTensor3DVolTask +from ..registration import diffeoSymTensor3DVol -def test_diffeoSymTensor3DVolTask_inputs(): +def test_diffeoSymTensor3DVol_inputs(): input_map = dict( args=dict(argstr='%s', ), df=dict( @@ -15,7 +15,7 @@ def test_diffeoSymTensor3DVolTask_inputs(): usedefault=True, ), flip=dict( - argstr='-flip %s', + argstr='-flip %d %d %d', exists=True, ), ignore_exception=dict( @@ -33,7 +33,6 @@ def test_diffeoSymTensor3DVolTask_inputs(): ), out_file=dict( argstr='-out %s', - exists=True, keep_extension=True, name_source='in_file', name_template='%s_diffeoxfmd', @@ -43,7 +42,7 @@ def test_diffeoSymTensor3DVolTask_inputs(): usedefault=True, ), resampling_type=dict( - argstr='-type %s', + argstr='-type %d', exists=True, ), target=dict( @@ -63,14 +62,14 @@ def test_diffeoSymTensor3DVolTask_inputs(): xor=['target'], ), ) - inputs = diffeoSymTensor3DVolTask.input_spec() + inputs = diffeoSymTensor3DVol.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_diffeoSymTensor3DVolTask_outputs(): +def test_diffeoSymTensor3DVol_outputs(): output_map = dict(out_file=dict(), ) - outputs = diffeoSymTensor3DVolTask.output_spec() + outputs = diffeoSymTensor3DVol.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): From 1bc8a1cac6cc71d482a64a3a1b33699c22b4c16d Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Wed, 28 Mar 2018 16:25:52 -0700 Subject: [PATCH 28/53] renamed interfaces --- nipype/interfaces/dtitk/__init__.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/nipype/interfaces/dtitk/__init__.py b/nipype/interfaces/dtitk/__init__.py index 1b77a112b9..39a1125cb3 100644 --- a/nipype/interfaces/dtitk/__init__.py +++ b/nipype/interfaces/dtitk/__init__.py @@ -6,10 +6,8 @@ """ # from .base import () -from .registration import (RigidTask, AffineTask, DiffeoTask, - ComposeXfmTask, diffeoSymTensor3DVolTask, - affSymTensor3DVolTask, affScalarVolTask, - diffeoScalarVolTask) -from .utils import (TVAdjustVoxSpTask, - SVAdjustVoxSpTask, TVResampleTask, SVResampleTask, - TVtoolTask, BinThreshTask) +from .registration import (Rigid, Affine, Diffeo, + ComposeXfm, diffeoSymTensor3DVol, affSymTensor3DVol, + affScalarVol,diffeoScalarVol) +from .utils import (TVAdjustVoxSp, SVAdjustVoxSp, TVResample, SVResample, + TVtool, BinThresh) From 2fea4fa5f9a76f1a7053ed83eda9e4dcc284a3ab Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Wed, 28 Mar 2018 16:26:10 -0700 Subject: [PATCH 29/53] added new fake files for testing --- nipype/testing/data/im_affine.aff | 0 nipype/testing/data/im_warp.df.nii | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 nipype/testing/data/im_affine.aff create mode 100644 nipype/testing/data/im_warp.df.nii diff --git a/nipype/testing/data/im_affine.aff b/nipype/testing/data/im_affine.aff new file mode 100644 index 0000000000..e69de29bb2 diff --git a/nipype/testing/data/im_warp.df.nii b/nipype/testing/data/im_warp.df.nii new file mode 100644 index 0000000000..e69de29bb2 From 1deaad8920c4a0bc1645c6998c01f9ca058af583 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Wed, 28 Mar 2018 16:26:33 -0700 Subject: [PATCH 30/53] Various modifications based on code review by @effigies --- nipype/interfaces/dtitk/registration.py | 267 +++++++++++------------- nipype/interfaces/dtitk/utils.py | 105 +++++----- 2 files changed, 182 insertions(+), 190 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 0b49124f9d..2f2d5c502b 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -8,26 +8,33 @@ The high-dimensional tensor-based DTI registration algorithm -Zhang, H., Avants, B.B, Yushkevich, P.A., Woo, J.H., Wang, S., McCluskey, L.H., Elman, L.B., Melhem, E.R., Gee, J.C., High-dimensional spatial normalization of diffusion tensor images improves the detection of white matter differences in amyotrophic lateral sclerosis, IEEE Transactions on Medical Imaging, 26(11):1585-1597, November 2007. PMID: 18041273. +Zhang, H., Avants, B.B, Yushkevich, P.A., Woo, J.H., Wang, S., McCluskey, L.H., + Elman, L.B., Melhem, E.R., Gee, J.C., High-dimensional spatial normalization + of diffusion tensor images improves the detection of white matter differences + in amyotrophic lateral sclerosis, IEEE Transactions on Medical Imaging, + 26(11):1585-1597, November 2007. PMID: 18041273. -The original piecewise-affine tensor-based DTI registration algorithm at the core of DTI-TK +The original piecewise-affine tensor-based DTI registration algorithm at the +core of DTI-TK -Zhang, H., Yushkevich, P.A., Alexander, D.C., Gee, J.C., Deformable registration of diffusion tensor MR images with explicit orientation optimization, Medical Image Analysis, 10(5):764-785, October 2006. PMID: 16899392. +Zhang, H., Yushkevich, P.A., Alexander, D.C., Gee, J.C., Deformable + registration of diffusion tensor MR images with explicit orientation + optimization, Medical Image Analysis, 10(5):764-785, October 2006. PMID: + 16899392. """ -from ..base import TraitedSpec, CommandLineInputSpec, traits, isdefined, File +from ..base import TraitedSpec, CommandLineInputSpec, traits, File from ...utils.filemanip import fname_presuffix -import os from .base import CommandLineDtitk __docformat__ = 'restructuredtext' + class RigidInputSpec(CommandLineInputSpec): - fixed_file = File(desc="fixed diffusion tensor image", - exists=True, mandatory=True, - position=0, argstr="%s") - moving_file = File(desc="diffusion tensor image path", exists=True, + fixed_file = File(desc="fixed tensor volume", exists=True, + mandatory=True, position=0, argstr="%s") + moving_file = File(desc="moving tensor volume", exists=True, mandatory=True, position=1, argstr="%s", copyfile=False) similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', mandatory=True, position=2, argstr="%s", @@ -47,14 +54,14 @@ class RigidOutputSpec(TraitedSpec): out_file_xfm = File(exists=True) -class RigidTask(CommandLineDtitk): +class Rigid(CommandLineDtitk): """Performs rigid registration between two tensor volumes Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.RigidTask() + >>> from nipype.interfaces import dtitk + >>> node = dtitk.Rigid() >>> node.inputs.fixed_file = 'im1.nii' >>> node.inputs.moving_file = 'im2.nii' >>> node.inputs.similarity_metric = 'EDS' @@ -71,47 +78,21 @@ class RigidTask(CommandLineDtitk): def _list_outputs(self): outputs = self.output_spec().get() - splitlist = os.path.basename(self.inputs.moving_file).split('.') - basename = splitlist[0] - termination = '.'+'.'.join(splitlist[1:]) - outputs['out_file_xfm'] = basename+'.aff' - outputs['out_file'] = basename+'_aff'+termination + moving = self.inputs.moving_file + outputs['out_file_xfm'] = fname_presuffix(moving, suffix='.aff', + use_ext=False) + outputs['out_file'] = fname_presuffix(moving, suffix='_aff') return outputs -class AffineInputSpec(CommandLineInputSpec): - fixed_file = File(desc="fixed diffusion tensor image", - exists=True, mandatory=True, - position=0, argstr="%s") - moving_file = File(desc="diffusion tensor image path", exists=True, - mandatory=True, position=1, argstr="%s", copyfile=False) - similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', - mandatory=True, position=2, argstr="%s", - desc="similarity metric", usedefault=True) - samplingXYZ = traits.Tuple((4, 4, 4), mandatory=True, position=3, - argstr="%g %g %g", usedefault=True, - desc="dist between samp points (mm) (x,y,z)") - ftol = traits.Float(mandatory=True, position=4, argstr="%s", - desc="cost function tolerance", default_value=0.01, - usedefault=True) - useInTrans = traits.Bool(position=5, argstr="1", - desc="to initialize with existing xfm set as 1", - default_value=True) - - -class AffineOutputSpec(TraitedSpec): - out_file = File(exists=True) - out_file_xfm = File(exists=True) - - -class AffineTask(CommandLineDtitk): +class Affine(Rigid): """Performs affine registration between two tensor volumes Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.AffineTask() + >>> from nipype.interfaces import dtitk + >>> node = dtitk.Affine() >>> node.inputs.fixed_file = 'im1.nii' >>> node.inputs.moving_file = 'im2.nii' >>> node.inputs.similarity_metric = 'EDS' @@ -122,37 +103,23 @@ class AffineTask(CommandLineDtitk): 'dti_affine_reg im1.nii im2.nii EDS 4 4 4 0.01 1' >>> node.run() # doctest: +SKIP """ - input_spec = AffineInputSpec - output_spec = AffineOutputSpec _cmd = 'dti_affine_reg' - def _list_outputs(self): - outputs = self.output_spec().get() - splitlist = os.path.basename(self.inputs.moving_file).split('.') - basename = splitlist[0] - termination = '.'+'.'.join(splitlist[1:]) - outputs['out_file_xfm'] = basename+'.aff' - outputs['out_file'] = basename+'_aff'+termination - return outputs - class DiffeoInputSpec(CommandLineInputSpec): - fixed_file = File(desc="fixed diffusion tensor image", - exists=True, position=0, argstr="%s") - moving_file = File(desc="moving diffusion tensor image", + fixed_file = File(desc="fixed tensor volume", + exists=True, position=0, argstr="%s") + moving_file = File(desc="moving tensor volume", exists=True, position=1, argstr="%s", copyfile=False) mask_file = File(desc="mask", exists=True, position=2, argstr="%s") - legacy = traits.Int(desc="legacy parameter; always set to 1", - exists=True, mandatory=True, - position=3, default_value=1, argstr="%s", - usedefault=True) - n_iters = traits.Int(desc="number of iterations", + legacy = traits.Enum(1, desc="legacy parameter; always set to 1", + usedefault=True, mandatory=True, + position=3, argstr="%d") + n_iters = traits.Int(6, desc="number of iterations", exists=True, mandatory=True, - position=4, default_value=6, argstr="%s", - usedefault=True) - ftol = traits.Float(desc="iteration for the optimization to stop", - exists=True, mandatory=True, - position=5, default_value=0.002, argstr="%s", + position=4, argstr="%d", usedefault=True) + ftol = traits.Float(0.002, desc="iteration for the optimization to stop", + exists=True, mandatory=True, position=5, argstr="%g", usedefault=True) @@ -161,14 +128,14 @@ class DiffeoOutputSpec(TraitedSpec): out_file_xfm = File(exists=True) -class DiffeoTask(CommandLineDtitk): +class Diffeo(CommandLineDtitk): """Performs diffeomorphic registration between two tensor volumes Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.DiffeoTask() + >>> from nipype.interfaces import dtitk + >>> node = dtitk.Diffeo() >>> node.inputs.fixed_file = 'im1.nii' >>> node.inputs.moving_file = 'im2.nii' >>> node.inputs.mask_file = 'mask.nii' @@ -185,41 +152,40 @@ class DiffeoTask(CommandLineDtitk): def _list_outputs(self): outputs = self.output_spec().get() - splitlist = os.path.basename(self.inputs.moving_file).split('.') - basename = splitlist[0] - termination = '.'+'.'.join(splitlist[1:]) - outputs['out_file_xfm'] = basename+'_diffeo.df'+termination - outputs['out_file'] = basename+'_diffeo'+termination + moving = self.inputs.moving_file() + outputs['out_file_xfm'] = fname_presuffix(moving, suffix='_diffeo.df') + outputs['out_file'] = fname_presuffix(moving, suffix='_diffeo') return outputs class ComposeXfmInputSpec(CommandLineInputSpec): in_df = File(desc='diffeomorphic warp file', exists=True, argstr="-df %s", copyfile=False, mandatory=True) - in_aff = File(desc='affine_xfm.aff', exists=True, + in_aff = File(desc='affine transform file', exists=True, argstr="-aff %s", mandatory=True) - out_file = traits.Str(desc='output_path', exists=True, - argstr="-out %s", name_source="in_df", - name_template="%s_aff.df", keep_extension=True) + out_file = traits.File(desc='output path', + argstr="-out %s", name_source="in_df", + name_template="%s_aff.df", keep_extension=True) class ComposeXfmOutputSpec(TraitedSpec): out_file = File(exists=True) -class ComposeXfmTask(CommandLineDtitk): +class ComposeXfm(CommandLineDtitk): """ Combines diffeomorphic and affine transforms Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.ComposeXfmTask() - >>> node.inputs.in_df = 'im1.nii' - >>> node.inputs.in_aff= 'im2.nii' + >>> from nipype.interfaces import dtitk + >>> node = dtitk.ComposeXfm() + >>> node.inputs.in_df = 'im_warp.df.nii' + >>> node.inputs.in_aff= 'im_affine.aff' >>> node.cmdline - 'dfRightComposeAffine -aff im2.nii -df im1.nii -out im1_aff.df' + 'dfRightComposeAffine -aff im_affine.aff -df im_warp.df.nii -out\ + im_warp.df_aff.df' >>> node.run() # doctest: +SKIP """ input_spec = ComposeXfmInputSpec @@ -230,25 +196,33 @@ class ComposeXfmTask(CommandLineDtitk): class affSymTensor3DVolInputSpec(CommandLineInputSpec): in_file = File(desc='moving tensor volume', exists=True, argstr="-in %s", mandatory=True) - out_file = traits.Str(desc='output filename', exists=True, - argstr="-out %s", name_source="in_file", - name_template="%s_affxfmd", keep_extension=True) + out_file = traits.File(desc='output filename', + argstr="-out %s", name_source="in_file", + name_template="%s_affxfmd", keep_extension=True) transform = File(exists=True, argstr="-trans %s", - xor=['target', 'translation', 'euler', 'deformation'], desc='transform to apply: specify an input transformation file; parameters input will be ignored',) + xor=['target', 'translation', 'euler', 'deformation'], + desc='transform to apply: specify an input transformation\ + file; parameters input will be ignored',) interpolation = traits.Enum('LEI', 'EI', usedefault=True, argstr="-interp %s", desc='Log Euclidean/Euclidean Interpolation') reorient = traits.Enum('PPD', 'NO', 'FS', argstr='-reorient %s', - usedefault=True) + usedefault=True, desc='Reorientation strategy: \ + preservation of principal direction, no \ + reorientation, or finite strain') target = File(exists=True, argstr="-target %s", xor=['transform'], - desc='output volume specification read from the target volume if specified') - translation = traits.Tuple((0, 0, 0), desc='translation (x,y,z) in mm', + desc='output volume specification read from the target volume\ + if specified') + translation = traits.Tuple((traits.Float(), traits.Float(), + traits.Float()), + desc='translation (x,y,z) in mm', argstr='-translation %g %g %g', xor=['transform']) - euler = traits.Tuple((0, 0, 0), desc='(theta, phi, psi) in degrees', + euler = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='(theta, phi, psi) in degrees', xor=['transform'], argstr='-euler %g %g %g') - deformation = traits.Tuple((1, 1, 1, 0, 0, 0), desc='(xx,yy,zz,xy,yz,xz)', - xor=['transform'], + deformation = traits.Tuple(traits.Tuple((traits.Float(),) * 6, ...), + desc='(xx,yy,zz,xy,yz,xz)', xor=['transform'], argstr='-deformation %g %g %g %g %g %g') @@ -256,19 +230,20 @@ class affSymTensor3DVolOutputSpec(TraitedSpec): out_file = File(exists=True) -class affSymTensor3DVolTask(CommandLineDtitk): +class affSymTensor3DVol(CommandLineDtitk): """ Applies affine transform to a tensor volume Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.affSymTensor3DVolTask() + >>> from nipype.interfaces import dtitk + >>> node = dtitk.affSymTensor3DVol() >>> node.inputs.in_file = 'im1.nii' - >>> node.inputs.transform = 'im2.nii' + >>> node.inputs.transform = 'im_affine.aff' >>> node.cmdline - 'affineSymTensor3DVolume -in im1.nii -interp LEI -out im1_affxfmd.nii -reorient PPD -trans im2.nii' + 'affineSymTensor3DVolume -in im1.nii -interp LEI -out im1_affxfmd.nii\ + -reorient PPD -trans im_affine.aff' >>> node.run() # doctest: +SKIP """ input_spec = affSymTensor3DVolInputSpec @@ -279,44 +254,47 @@ class affSymTensor3DVolTask(CommandLineDtitk): class affScalarVolInputSpec(CommandLineInputSpec): in_file = File(desc='moving scalar volume', exists=True, argstr="-in %s", mandatory=True) - out_file = traits.Str(desc='output filename', exists=True, - argstr="-out %s", name_source="in_file", - name_template="%s_affxfmd", keep_extension=True) + out_file = traits.File(desc='output filename', + argstr="-out %s", name_source="in_file", + name_template="%s_affxfmd", keep_extension=True) transform = File(exists=True, argstr="-trans %s", - xor=['target', 'translation', 'euler', 'deformation'], desc='transform to apply: specify an input transformation file; parameters input will be ignored',) + xor=['target', 'translation', 'euler', 'deformation'], + desc='transform to apply: specify an input transformation\ + file; parameters input will be ignored',) interpolation = traits.Enum(0, 1, usedefault=True, argstr="-interp %s", desc='0=trilinear (def); 1=nearest neighbor') target = File(exists=True, argstr="-target %s", xor=['transform'], - desc='output volume specification read from the target volume if specified') + desc='output volume specification read from the target volume\ + if specified') translation = traits.Tuple((0, 0, 0), desc='translation (x,y,z) in mm', argstr='-translation %g %g %g', xor=['transform']) euler = traits.Tuple((0, 0, 0), desc='(theta, phi, psi) in degrees', xor=['transform'], argstr='-euler %g %g %g') - deformation = traits.Tuple((1, 1, 1, 0, 0, 0), desc='(xx,yy,zz,xy,yz,xz)', - xor=['transform'], + deformation = traits.Tuple(traits.Tuple((traits.Float(),) * 6, ...), + desc='(xx,yy,zz,xy,yz,xz)', xor=['transform'], argstr='-deformation %g %g %g %g %g %g') - class affScalarVolOutputSpec(TraitedSpec): out_file = File(desc='moved volume', exists=True) -class affScalarVolTask(CommandLineDtitk): +class affScalarVol(CommandLineDtitk): """ Applies affine transform to a scalar volume Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.affScalarVolTask() + >>> from nipype.interfaces import dtitk + >>> node = dtitk.affScalarVol() >>> node.inputs.in_file = 'im1.nii' - >>> node.inputs.transform = 'im2.nii' + >>> node.inputs.transform = 'im_affine.aff' >>> node.cmdline - 'affineScalarVolume -in im1.nii -interp 0 -out im1_affxfmd.nii -trans im2.nii' + 'affineScalarVolume -in im1.nii -interp 0 -out im1_affxfmd.nii -trans\ + im_affine.aff' >>> node.run() # doctest: +SKIP """ input_spec = affScalarVolInputSpec @@ -327,45 +305,49 @@ class affScalarVolTask(CommandLineDtitk): class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): in_file = File(desc='moving tensor volume', exists=True, argstr="-in %s", mandatory=True) - out_file = traits.Str(desc='output filename', exists=True, - argstr="-out %s", name_source="in_file", - name_template="%s_diffeoxfmd", keep_extension=True) + out_file = traits.File(desc='output filename', + argstr="-out %s", name_source="in_file", + name_template="%s_diffeoxfmd", keep_extension=True) transform = File(exists=True, argstr="-trans %s", mandatory=True, desc='transform to apply') df = traits.Str('FD', argstr="-df %s", usedefault=True) interpolation = traits.Enum('LEI', 'EI', usedefault=True, argstr="-interp %s", desc='Log Euclidean/Euclidean Interpolation') - reorient = traits.Enum('PPD','FS', argstr='-reorient %s', - usedefault=True) + reorient = traits.Enum('PPD', 'FS', argstr='-reorient %s', + usedefault=True, desc='Reorientation strategy: \ + preservation of principal direction or finite \ + strain') target = File(exists=True, argstr="-target %s", xor=['voxel_size'], - desc='output volume specification read from the target volume if specified') + desc='output volume specification read from the target volume\ + if specified') voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), desc='xyz voxel size (superseded by target)', argstr="-vsize %g %g %g", xor=['target']) - flip = traits.Tuple((0, 0, 0), exists=True, argstr="-flip %s") + flip = traits.Tuple((traits.Int(), traits.Int(), traits.Int()), + exists=True, argstr="-flip %d %d %d") resampling_type = traits.Enum(1, 0, desc='1=backward(def), 0=forward', - exists=True, argstr="-type %s") - + exists=True, argstr="-type %d") class diffeoSymTensor3DVolOutputSpec(TraitedSpec): out_file = File(exists=True) -class diffeoSymTensor3DVolTask(CommandLineDtitk): +class diffeoSymTensor3DVol(CommandLineDtitk): """ Applies diffeomorphic transform to a tensor volume Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.diffeoSymTensor3DVolTask() + >>> from nipype.interfaces import dtitk + >>> node = dtitk.diffeoSymTensor3DVol() >>> node.inputs.in_file = 'im1.nii' - >>> node.inputs.transform = 'im2.nii' + >>> node.inputs.transform = 'im_warp.df.nii' >>> node.cmdline - 'deformationSymTensor3DVolume -df FD -in im1.nii -interp LEI -out im1_diffeoxfmd.nii -reorient PPD -trans im2.nii' + 'deformationSymTensor3DVolume -df FD -in im1.nii -interp LEI -out\ + im1_diffeoxfmd.nii -reorient PPD -trans im_warp.df.nii' >>> node.run() # doctest: +SKIP """ @@ -377,40 +359,43 @@ class diffeoSymTensor3DVolTask(CommandLineDtitk): class diffeoScalarVolInputSpec(CommandLineInputSpec): in_file = File(desc='moving scalar volume', exists=True, argstr="-in %s", mandatory=True) - out_file = traits.Str(desc='output filename', exists=True, - argstr="-out %s", name_source="in_file", - name_template="%s_diffeoxfmd", keep_extension=True) + out_file = traits.File(desc='output filename', + argstr="-out %s", name_source="in_file", + name_template="%s_diffeoxfmd", keep_extension=True) transform = transform = File(exists=True, argstr="-trans %s", mandatory=True, desc='transform to apply') target = File(exists=True, argstr="-target %s", xor=['voxel_size'], - desc='output volume specification read from the target volume if specified') + desc='output volume specification read from the target volume\ + if specified') voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), desc='xyz voxel size (superseded by target)', argstr="-vsize %g %g %g", xor=['target']) - flip = traits.Tuple((0, 0, 0), exists=True, argstr="-flip %s") + flip = traits.Tuple((traits.Int(), traits.Int(), traits.Int()), + exists=True, argstr="-flip %d %d %d") resampling_type = traits.Enum(1, 0, desc='1=backward(def), 0=forward', - exists=True, argstr="-type %s") + exists=True, argstr="-type %d") interp = traits.Enum(0, 1, desc='0=trilinear(def), 1=nearest neighbor', - exists=True, argstr="-interp %s", usedefault=True) + exists=True, argstr="-interp %d", usedefault=True) class diffeoScalarVolOutputSpec(TraitedSpec): out_file = File(desc='moved volume', exists=True) -class diffeoScalarVolTask(CommandLineDtitk): +class diffeoScalarVol(CommandLineDtitk): """ Applies diffeomorphic transform to a scalar volume Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.diffeoScalarVolTask() + >>> from nipype.interfaces import dtitk + >>> node = dtitk.diffeoScalarVol() >>> node.inputs.in_file = 'im1.nii' - >>> node.inputs.transform = 'im2.nii' + >>> node.inputs.transform = 'im_warp.df.nii' >>> node.cmdline - 'deformationScalarVolume -in im1.nii -interp 0 -out im1_diffeoxfmd.nii -trans im2.nii' + 'deformationScalarVolume -in im1.nii -interp 0 -out im1_diffeoxfmd.nii\ + -trans im_warp.df.nii' >>> node.run() # doctest: +SKIP """ diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index f0aa5a9fbf..63b50b6255 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -8,35 +8,43 @@ The high-dimensional tensor-based DTI registration algorithm -Zhang, H., Avants, B.B, Yushkevich, P.A., Woo, J.H., Wang, S., McCluskey, L.H., Elman, L.B., Melhem, E.R., Gee, J.C., High-dimensional spatial normalization of diffusion tensor images improves the detection of white matter differences in amyotrophic lateral sclerosis, IEEE Transactions on Medical Imaging, 26(11):1585-1597, November 2007. PMID: 18041273. +Zhang, H., Avants, B.B, Yushkevich, P.A., Woo, J.H., Wang, S., McCluskey, L.H., +Elman, L.B., Melhem, E.R., Gee, J.C., High-dimensional spatial normalization of +diffusion tensor images improves the detection of white matter differences in +amyotrophic lateral sclerosis, IEEE Transactions on Medical Imaging, +26(11):1585-1597, November 2007. PMID: 18041273. -The original piecewise-affine tensor-based DTI registration algorithm at the core of DTI-TK +The original piecewise-affine tensor-based DTI registration algorithm at the +core of DTI-TK -Zhang, H., Yushkevich, P.A., Alexander, D.C., Gee, J.C., Deformable registration of diffusion tensor MR images with explicit orientation optimization, Medical Image Analysis, 10(5):764-785, October 2006. PMID: 16899392. +Zhang, H., Yushkevich, P.A., Alexander, D.C., Gee, J.C., Deformable +registration of diffusion tensor MR images with explicit orientation +optimization, Medical Image Analysis, 10(5):764-785, October 2006. PMID: +16899392. """ __author__ = 'kjordan' -from ..base import TraitedSpec, CommandLineInputSpec, File, \ - traits, isdefined -import os +from ..base import TraitedSpec, CommandLineInputSpec, File, traits, isdefined +from ...utils.filemanip import fname_presuffix from .base import CommandLineDtitk __docformat__ = 'restructuredtext' + class TVAdjustVoxSpInputSpec(CommandLineInputSpec): in_file = File(desc="tensor volume to modify", exists=True, mandatory=True, argstr="-in %s") - out_file = traits.Str(genfile=True, desc='output path', - argstr="-out %s", name_source='in_file', - name_template='%s_avs', keep_extension=True) + out_file = traits.File(genfile=True, desc='output path', + argstr="-out %s", name_source='in_file', + name_template='%s_avs', keep_extension=True) target_file = traits.File(desc='target volume to match', argstr="-target %s", xor=['voxel_size', 'origin']) voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), desc='xyz voxel size (superseded by target)', argstr="-vsize %g %g %g", xor=['target_file']) - origin = traits.Tuple((0, 0, 0), + origin = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), desc='xyz origin (superseded by target)', argstr='-origin %g %g %g', xor=['target_file']) @@ -46,15 +54,15 @@ class TVAdjustVoxSpOutputSpec(TraitedSpec): out_file = File(exists=True) -class TVAdjustVoxSpTask(CommandLineDtitk): +class TVAdjustVoxSp(CommandLineDtitk): """ Adjusts the voxel space of a tensor volume Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.TVAdjustVoxSpTask() + >>> from nipype.interfaces import dtitk + >>> node = dtitk.TVAdjustVoxSp() >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.target_file = 'im2.nii' >>> node.cmdline @@ -69,15 +77,15 @@ class TVAdjustVoxSpTask(CommandLineDtitk): class SVAdjustVoxSpInputSpec(CommandLineInputSpec): in_file = File(desc="scalar volume to modify", exists=True, mandatory=True, argstr="-in %s") - out_file = traits.Str(desc='output path', argstr="-out %s", - name_source="in_file", name_template='%s_avs', - keep_extension=True) + out_file = traits.File(desc='output path', argstr="-out %s", + name_source="in_file", name_template='%s_avs', + keep_extension=True) target_file = File(desc='target volume to match', argstr="-target %s", xor=['voxel_size', 'origin']) voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), desc='xyz voxel size (superseded by target)', argstr="-vsize %g %g %g", xor=['target_file']) - origin = traits.Tuple((0, 0, 0), + origin = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), desc='xyz origin (superseded by target)', argstr='-origin %g %g %g', xor=['target_file']) @@ -87,15 +95,15 @@ class SVAdjustVoxSpOutputSpec(TraitedSpec): out_file = File(exists=True) -class SVAdjustVoxSpTask(CommandLineDtitk): +class SVAdjustVoxSp(CommandLineDtitk): """ Adjusts the voxel space of a scalar volume Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.SVAdjustVoxSpTask() + >>> from nipype.interfaces import dtitk + >>> node = dtitk.SVAdjustVoxSp() >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.target_file = 'im2.nii' >>> node.cmdline @@ -110,9 +118,9 @@ class SVAdjustVoxSpTask(CommandLineDtitk): class TVResampleInputSpec(CommandLineInputSpec): in_file = File(desc="tensor volume to resample", exists=True, mandatory=True, argstr="-in %s") - out_file = traits.Str(desc='output path', - name_source="in_file", name_template="%s_resampled", - keep_extension=True, argstr="-out %s") + out_file = traits.File(desc='output path', + name_source="in_file", name_template="%s_resampled", + keep_extension=True, argstr="-out %s") target_file = File(desc='specs read from the target volume', argstr="-target %s", xor=['array_size', 'voxel_size', 'origin']) @@ -135,15 +143,15 @@ class TVResampleOutputSpec(TraitedSpec): out_file = File(exists=True) -class TVResampleTask(CommandLineDtitk): +class TVResample(CommandLineDtitk): """ Resamples a tensor volume Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.TVResampleTask() + >>> from nipype.interfaces import dtitk + >>> node = dtitk.TVResample() >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.target_file = 'im2.nii' >>> node.cmdline @@ -158,9 +166,9 @@ class TVResampleTask(CommandLineDtitk): class SVResampleInputSpec(CommandLineInputSpec): in_file = File(desc="image to resample", exists=True, mandatory=True, argstr="-in %s") - out_file = traits.Str(desc='output path', - name_source="in_file", name_template="%s_resampled", - keep_extension=True, argstr="-out %s") + out_file = traits.File(desc='output path', + name_source="in_file", name_template="%s_resampled", + keep_extension=True, argstr="-out %s") target_file = File(desc='specs read from the target volume', argstr="-target %s", xor=['array_size', 'voxel_size', 'origin']) @@ -181,16 +189,15 @@ class SVResampleOutputSpec(TraitedSpec): out_file = File(exists=True) - -class SVResampleTask(CommandLineDtitk): +class SVResample(CommandLineDtitk): """ Resamples a scalar volume Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.SVResampleTask() + >>> from nipype.interfaces import dtitk + >>> node = dtitk.SVResample() >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.target_file = 'im2.nii' >>> node.cmdline @@ -205,26 +212,26 @@ class SVResampleTask(CommandLineDtitk): class TVtoolInputSpec(CommandLineInputSpec): in_file = File(desc="scalar volume to resample", exists=True, argstr="-in %s", mandatory=True) - '''NOTE: there are a lot more options here; not putting all of them in''' + '''NOTE: there are a lot more options here; not implementing all of them''' in_flag = traits.Enum('fa', 'tr', 'ad', 'rd', 'pd', 'rgb', exists=True, argstr="-%s", desc='') - out_file = traits.Str(exists=True, - argstr="-out %s", genfile=True) + out_file = traits.File(exists=True, + argstr="-out %s", genfile=True) class TVtoolOutputSpec(TraitedSpec): out_file = File() -class TVtoolTask(CommandLineDtitk): +class TVtool(CommandLineDtitk): """ Calculates a tensor metric volume from a tensor volume Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.TVtoolTask() + >>> from nipype.interfaces import dtitk + >>> node = dtitk.TVtool() >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.in_flag = 'fa' >>> node.cmdline @@ -244,10 +251,10 @@ def _list_outputs(self): return outputs def _gen_filename(self, name): - splitlist = os.path.basename(self.inputs.in_file).split('.') - basename = splitlist[0] - termination = '.' + '.'.join(splitlist[1:]) - return basename + '_'+self.inputs.in_flag + termination + tensor_volume = self.inputs.in_file + output_name = fname_presuffix(tensor_volume, + suffix='_'+self.inputs.in_flag) + return output_name '''Note: SVTool not implemented at this time''' @@ -256,9 +263,9 @@ def _gen_filename(self, name): class BinThreshInputSpec(CommandLineInputSpec): in_file = File(desc='Image to threshold/binarize', exists=True, position=0, argstr="%s", mandatory=True) - out_file = traits.Str(desc='', position=1, argstr="%s", - keep_extension=True, name_source='in_file', - name_template='%s_thrbin') + out_file = traits.File(desc='', position=1, argstr="%s", + keep_extension=True, name_source='in_file', + name_template='%s_thrbin') lower_bound = traits.Float(0.01, position=2, argstr="%g", mandatory=True) upper_bound = traits.Float(100, position=3, argstr="%g", mandatory=True) inside_value = traits.Float(1, position=4, argstr="%g", usedefault=True, @@ -271,15 +278,15 @@ class BinThreshOutputSpec(TraitedSpec): out_file = File(exists=True) -class BinThreshTask(CommandLineDtitk): +class BinThresh(CommandLineDtitk): """ Binarizes an image Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.BinThreshTask() + >>> from nipype.interfaces import dtitk + >>> node = dtitk.BinThresh() >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.lower_bound = 0 >>> node.inputs.upper_bound = 100 From def5d6b8efa40087cb9357b9918f91b0fccc4d11 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Wed, 28 Mar 2018 16:50:03 -0700 Subject: [PATCH 31/53] made interfaces more user friendly --- nipype/interfaces/dtitk/registration.py | 67 +++++++++++++++++-------- nipype/interfaces/dtitk/utils.py | 39 +++++++------- 2 files changed, 64 insertions(+), 42 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 2f2d5c502b..2dd48b27d5 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -163,9 +163,9 @@ class ComposeXfmInputSpec(CommandLineInputSpec): argstr="-df %s", copyfile=False, mandatory=True) in_aff = File(desc='affine transform file', exists=True, argstr="-aff %s", mandatory=True) - out_file = traits.File(desc='output path', - argstr="-out %s", name_source="in_df", - name_template="%s_aff.df", keep_extension=True) + out_file = File(desc='output path', + argstr="-out %s", name_source="in_df", + name_template="%s_aff.df", keep_extension=True) class ComposeXfmOutputSpec(TraitedSpec): @@ -196,9 +196,9 @@ class ComposeXfm(CommandLineDtitk): class affSymTensor3DVolInputSpec(CommandLineInputSpec): in_file = File(desc='moving tensor volume', exists=True, argstr="-in %s", mandatory=True) - out_file = traits.File(desc='output filename', - argstr="-out %s", name_source="in_file", - name_template="%s_affxfmd", keep_extension=True) + out_file = File(desc='output filename', + argstr="-out %s", name_source="in_file", + name_template="%s_affxfmd", keep_extension=True) transform = File(exists=True, argstr="-trans %s", xor=['target', 'translation', 'euler', 'deformation'], desc='transform to apply: specify an input transformation\ @@ -254,16 +254,17 @@ class affSymTensor3DVol(CommandLineDtitk): class affScalarVolInputSpec(CommandLineInputSpec): in_file = File(desc='moving scalar volume', exists=True, argstr="-in %s", mandatory=True) - out_file = traits.File(desc='output filename', - argstr="-out %s", name_source="in_file", - name_template="%s_affxfmd", keep_extension=True) + out_file = File(desc='output filename', + argstr="-out %s", name_source="in_file", + name_template="%s_affxfmd", keep_extension=True) transform = File(exists=True, argstr="-trans %s", xor=['target', 'translation', 'euler', 'deformation'], desc='transform to apply: specify an input transformation\ file; parameters input will be ignored',) - interpolation = traits.Enum(0, 1, usedefault=True, - argstr="-interp %s", - desc='0=trilinear (def); 1=nearest neighbor') + interpolation = traits.Enum('trilinear', 'NN', + usedefault=True, argstr="-interp %s", + desc='trilinear or nearest neighbor\ + interpolation') target = File(exists=True, argstr="-target %s", xor=['transform'], desc='output volume specification read from the target volume\ if specified') @@ -301,13 +302,18 @@ class affScalarVol(CommandLineDtitk): output_spec = affScalarVolOutputSpec _cmd = 'affineScalarVolume' + def _format_arg(self, name, spec, value): + if name == 'interpolation': + value = {'trilinear': 0, 'NN': 1}[value] + super(affScalarVol, self)._format_arg(name, spec, value) + class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): in_file = File(desc='moving tensor volume', exists=True, argstr="-in %s", mandatory=True) - out_file = traits.File(desc='output filename', - argstr="-out %s", name_source="in_file", - name_template="%s_diffeoxfmd", keep_extension=True) + out_file = File(desc='output filename', + argstr="-out %s", name_source="in_file", + name_template="%s_diffeoxfmd", keep_extension=True) transform = File(exists=True, argstr="-trans %s", mandatory=True, desc='transform to apply') df = traits.Str('FD', argstr="-df %s", usedefault=True) @@ -326,7 +332,8 @@ class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): argstr="-vsize %g %g %g", xor=['target']) flip = traits.Tuple((traits.Int(), traits.Int(), traits.Int()), exists=True, argstr="-flip %d %d %d") - resampling_type = traits.Enum(1, 0, desc='1=backward(def), 0=forward', + resampling_type = traits.Enum('backward', 'forward', + desc='use backward or forward resampling', exists=True, argstr="-type %d") @@ -355,13 +362,18 @@ class diffeoSymTensor3DVol(CommandLineDtitk): output_spec = diffeoSymTensor3DVolOutputSpec _cmd = 'deformationSymTensor3DVolume' + def _format_arg(self, name, spec, value): + if name == 'resampling_type': + value = {'forward': 0, 'backward': 1}[value] + super(diffeoSymTensor3DVol, self)._format_arg(name, spec, value) + class diffeoScalarVolInputSpec(CommandLineInputSpec): in_file = File(desc='moving scalar volume', exists=True, argstr="-in %s", mandatory=True) - out_file = traits.File(desc='output filename', - argstr="-out %s", name_source="in_file", - name_template="%s_diffeoxfmd", keep_extension=True) + out_file = File(desc='output filename', + argstr="-out %s", name_source="in_file", + name_template="%s_diffeoxfmd", keep_extension=True) transform = transform = File(exists=True, argstr="-trans %s", mandatory=True, desc='transform to apply') target = File(exists=True, argstr="-target %s", xor=['voxel_size'], @@ -372,10 +384,13 @@ class diffeoScalarVolInputSpec(CommandLineInputSpec): argstr="-vsize %g %g %g", xor=['target']) flip = traits.Tuple((traits.Int(), traits.Int(), traits.Int()), exists=True, argstr="-flip %d %d %d") - resampling_type = traits.Enum(1, 0, desc='1=backward(def), 0=forward', + resampling_type = traits.Enum('backward', 'forward', + desc='use backward or forward resampling', exists=True, argstr="-type %d") - interp = traits.Enum(0, 1, desc='0=trilinear(def), 1=nearest neighbor', - exists=True, argstr="-interp %d", usedefault=True) + interpolation = traits.Enum('trilinear', 'NN', + desc='trilinear, or nearest neighbor', + exists=True, argstr="-interp %d", + usedefault=True) class diffeoScalarVolOutputSpec(TraitedSpec): @@ -402,3 +417,11 @@ class diffeoScalarVol(CommandLineDtitk): input_spec = diffeoScalarVolInputSpec output_spec = diffeoScalarVolOutputSpec _cmd = 'deformationScalarVolume' + + def _format_arg(self, name, spec, value): + if name == 'resampling_type': + value = {'forward': 0, 'backward': 1}[value] + super(diffeoScalarVol, self)._format_arg(name, spec, value) + if name == 'interpolation': + value = {'trilinear': 0, 'NN': 1}[value] + super(diffeoScalarVol, self)._format_arg(name, spec, value) diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index 63b50b6255..89f680bc60 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -35,12 +35,12 @@ class TVAdjustVoxSpInputSpec(CommandLineInputSpec): in_file = File(desc="tensor volume to modify", exists=True, mandatory=True, argstr="-in %s") - out_file = traits.File(genfile=True, desc='output path', - argstr="-out %s", name_source='in_file', - name_template='%s_avs', keep_extension=True) - target_file = traits.File(desc='target volume to match', - argstr="-target %s", - xor=['voxel_size', 'origin']) + out_file = File(genfile=True, desc='output path', + argstr="-out %s", name_source='in_file', + name_template='%s_avs', keep_extension=True) + target_file = File(desc='target volume to match', + argstr="-target %s", + xor=['voxel_size', 'origin']) voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), desc='xyz voxel size (superseded by target)', argstr="-vsize %g %g %g", xor=['target_file']) @@ -77,9 +77,9 @@ class TVAdjustVoxSp(CommandLineDtitk): class SVAdjustVoxSpInputSpec(CommandLineInputSpec): in_file = File(desc="scalar volume to modify", exists=True, mandatory=True, argstr="-in %s") - out_file = traits.File(desc='output path', argstr="-out %s", - name_source="in_file", name_template='%s_avs', - keep_extension=True) + out_file = File(desc='output path', argstr="-out %s", + name_source="in_file", name_template='%s_avs', + keep_extension=True) target_file = File(desc='target volume to match', argstr="-target %s", xor=['voxel_size', 'origin']) voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), @@ -118,9 +118,9 @@ class SVAdjustVoxSp(CommandLineDtitk): class TVResampleInputSpec(CommandLineInputSpec): in_file = File(desc="tensor volume to resample", exists=True, mandatory=True, argstr="-in %s") - out_file = traits.File(desc='output path', - name_source="in_file", name_template="%s_resampled", - keep_extension=True, argstr="-out %s") + out_file = File(desc='output path', + name_source="in_file", name_template="%s_resampled", + keep_extension=True, argstr="-out %s") target_file = File(desc='specs read from the target volume', argstr="-target %s", xor=['array_size', 'voxel_size', 'origin']) @@ -166,9 +166,9 @@ class TVResample(CommandLineDtitk): class SVResampleInputSpec(CommandLineInputSpec): in_file = File(desc="image to resample", exists=True, mandatory=True, argstr="-in %s") - out_file = traits.File(desc='output path', - name_source="in_file", name_template="%s_resampled", - keep_extension=True, argstr="-out %s") + out_file = File(desc='output path', + name_source="in_file", name_template="%s_resampled", + keep_extension=True, argstr="-out %s") target_file = File(desc='specs read from the target volume', argstr="-target %s", xor=['array_size', 'voxel_size', 'origin']) @@ -215,8 +215,7 @@ class TVtoolInputSpec(CommandLineInputSpec): '''NOTE: there are a lot more options here; not implementing all of them''' in_flag = traits.Enum('fa', 'tr', 'ad', 'rd', 'pd', 'rgb', exists=True, argstr="-%s", desc='') - out_file = traits.File(exists=True, - argstr="-out %s", genfile=True) + out_file = File(exists=True, argstr="-out %s", genfile=True) class TVtoolOutputSpec(TraitedSpec): @@ -263,9 +262,9 @@ def _gen_filename(self, name): class BinThreshInputSpec(CommandLineInputSpec): in_file = File(desc='Image to threshold/binarize', exists=True, position=0, argstr="%s", mandatory=True) - out_file = traits.File(desc='', position=1, argstr="%s", - keep_extension=True, name_source='in_file', - name_template='%s_thrbin') + out_file = File(desc='', position=1, argstr="%s", + keep_extension=True, name_source='in_file', + name_template='%s_thrbin') lower_bound = traits.Float(0.01, position=2, argstr="%g", mandatory=True) upper_bound = traits.Float(100, position=3, argstr="%g", mandatory=True) inside_value = traits.Float(1, position=4, argstr="%g", usedefault=True, From 5499794305cfca9412b3ece96797e0b4a88ef621 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Wed, 28 Mar 2018 17:04:58 -0700 Subject: [PATCH 32/53] fixed bug --- nipype/interfaces/dtitk/registration.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 2dd48b27d5..e4d8ad008e 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -334,7 +334,7 @@ class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): exists=True, argstr="-flip %d %d %d") resampling_type = traits.Enum('backward', 'forward', desc='use backward or forward resampling', - exists=True, argstr="-type %d") + exists=True, argstr="-type %s") class diffeoSymTensor3DVolOutputSpec(TraitedSpec): @@ -386,10 +386,10 @@ class diffeoScalarVolInputSpec(CommandLineInputSpec): exists=True, argstr="-flip %d %d %d") resampling_type = traits.Enum('backward', 'forward', desc='use backward or forward resampling', - exists=True, argstr="-type %d") + exists=True, argstr="-type %s") interpolation = traits.Enum('trilinear', 'NN', desc='trilinear, or nearest neighbor', - exists=True, argstr="-interp %d", + exists=True, argstr="-interp %s", usedefault=True) From 02449830dacd6d117f682f994b482d6c470fccd7 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Wed, 28 Mar 2018 22:51:17 -0700 Subject: [PATCH 33/53] this works --- nipype/interfaces/dtitk/registration.py | 54 +++++++++++-------- .../dtitk/tests/test_auto_diffeoScalarVol.py | 6 +-- .../tests/test_auto_diffeoSymTensor3DVol.py | 2 +- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index e4d8ad008e..f3dd488ba9 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -184,8 +184,7 @@ class ComposeXfm(CommandLineDtitk): >>> node.inputs.in_df = 'im_warp.df.nii' >>> node.inputs.in_aff= 'im_affine.aff' >>> node.cmdline - 'dfRightComposeAffine -aff im_affine.aff -df im_warp.df.nii -out\ - im_warp.df_aff.df' + 'dfRightComposeAffine -aff im_affine.aff -df im_warp.df.nii -out im_warp.df_aff.df' >>> node.run() # doctest: +SKIP """ input_spec = ComposeXfmInputSpec @@ -242,8 +241,7 @@ class affSymTensor3DVol(CommandLineDtitk): >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_affine.aff' >>> node.cmdline - 'affineSymTensor3DVolume -in im1.nii -interp LEI -out im1_affxfmd.nii\ - -reorient PPD -trans im_affine.aff' + 'affineSymTensor3DVolume -in im1.nii -interp LEI -out im1_affxfmd.nii -reorient PPD -trans im_affine.aff' >>> node.run() # doctest: +SKIP """ input_spec = affSymTensor3DVolInputSpec @@ -261,17 +259,24 @@ class affScalarVolInputSpec(CommandLineInputSpec): xor=['target', 'translation', 'euler', 'deformation'], desc='transform to apply: specify an input transformation\ file; parameters input will be ignored',) - interpolation = traits.Enum('trilinear', 'NN', + '''interpolation = traits.Enum('trilinear', 'NN', + usedefault=True, argstr="-interp %s", + desc='trilinear or nearest neighbor\ + interpolation')''' + interpolation = traits.Enum(0, 1, usedefault=True, argstr="-interp %s", desc='trilinear or nearest neighbor\ interpolation') target = File(exists=True, argstr="-target %s", xor=['transform'], desc='output volume specification read from the target volume\ if specified') - translation = traits.Tuple((0, 0, 0), desc='translation (x,y,z) in mm', + translation = traits.Tuple((traits.Float(), traits.Float(), + traits.Float()), + desc='translation (x,y,z) in mm', argstr='-translation %g %g %g', xor=['transform']) - euler = traits.Tuple((0, 0, 0), desc='(theta, phi, psi) in degrees', + euler = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='(theta, phi, psi) in degrees', xor=['transform'], argstr='-euler %g %g %g') deformation = traits.Tuple(traits.Tuple((traits.Float(),) * 6, ...), desc='(xx,yy,zz,xy,yz,xz)', xor=['transform'], @@ -294,18 +299,17 @@ class affScalarVol(CommandLineDtitk): >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_affine.aff' >>> node.cmdline - 'affineScalarVolume -in im1.nii -interp 0 -out im1_affxfmd.nii -trans\ - im_affine.aff' + 'affineScalarVolume -in im1.nii -interp 0 -out im1_affxfmd.nii -trans im_affine.aff' >>> node.run() # doctest: +SKIP """ input_spec = affScalarVolInputSpec output_spec = affScalarVolOutputSpec _cmd = 'affineScalarVolume' - def _format_arg(self, name, spec, value): + '''def _format_arg(self, name, spec, value): if name == 'interpolation': value = {'trilinear': 0, 'NN': 1}[value] - super(affScalarVol, self)._format_arg(name, spec, value) + super(affScalarVol, self)._format_arg(name, spec, value)''' class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): @@ -332,9 +336,12 @@ class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): argstr="-vsize %g %g %g", xor=['target']) flip = traits.Tuple((traits.Int(), traits.Int(), traits.Int()), exists=True, argstr="-flip %d %d %d") - resampling_type = traits.Enum('backward', 'forward', + resampling_type = traits.Enum(1, 0, desc='use backward or forward resampling', exists=True, argstr="-type %s") + '''resampling_type = traits.Enum('backward', 'forward', + desc='use backward or forward resampling', + exists=True, argstr="-type %s")''' class diffeoSymTensor3DVolOutputSpec(TraitedSpec): @@ -353,8 +360,7 @@ class diffeoSymTensor3DVol(CommandLineDtitk): >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_warp.df.nii' >>> node.cmdline - 'deformationSymTensor3DVolume -df FD -in im1.nii -interp LEI -out\ - im1_diffeoxfmd.nii -reorient PPD -trans im_warp.df.nii' + 'deformationSymTensor3DVolume -df FD -in im1.nii -interp LEI -out im1_diffeoxfmd.nii -reorient PPD -trans im_warp.df.nii' >>> node.run() # doctest: +SKIP """ @@ -362,10 +368,10 @@ class diffeoSymTensor3DVol(CommandLineDtitk): output_spec = diffeoSymTensor3DVolOutputSpec _cmd = 'deformationSymTensor3DVolume' - def _format_arg(self, name, spec, value): + '''def _format_arg(self, name, spec, value): if name == 'resampling_type': value = {'forward': 0, 'backward': 1}[value] - super(diffeoSymTensor3DVol, self)._format_arg(name, spec, value) + super(diffeoSymTensor3DVol, self)._format_arg(name, spec, value)''' class diffeoScalarVolInputSpec(CommandLineInputSpec): @@ -384,10 +390,17 @@ class diffeoScalarVolInputSpec(CommandLineInputSpec): argstr="-vsize %g %g %g", xor=['target']) flip = traits.Tuple((traits.Int(), traits.Int(), traits.Int()), exists=True, argstr="-flip %d %d %d") - resampling_type = traits.Enum('backward', 'forward', + '''resampling_type = traits.Enum('backward', 'forward', desc='use backward or forward resampling', exists=True, argstr="-type %s") interpolation = traits.Enum('trilinear', 'NN', + desc='trilinear, or nearest neighbor', + exists=True, argstr="-interp %s", + usedefault=True)''' + resampling_type = traits.Enum(1, 0, + desc='use backward or forward resampling', + exists=True, argstr="-type %s") + interpolation = traits.Enum(0, 1, desc='trilinear, or nearest neighbor', exists=True, argstr="-interp %s", usedefault=True) @@ -409,8 +422,7 @@ class diffeoScalarVol(CommandLineDtitk): >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_warp.df.nii' >>> node.cmdline - 'deformationScalarVolume -in im1.nii -interp 0 -out im1_diffeoxfmd.nii\ - -trans im_warp.df.nii' + 'deformationScalarVolume -in im1.nii -interp 0 -out im1_diffeoxfmd.nii -trans im_warp.df.nii' >>> node.run() # doctest: +SKIP """ @@ -418,10 +430,10 @@ class diffeoScalarVol(CommandLineDtitk): output_spec = diffeoScalarVolOutputSpec _cmd = 'deformationScalarVolume' - def _format_arg(self, name, spec, value): + '''def _format_arg(self, name, spec, value): if name == 'resampling_type': value = {'forward': 0, 'backward': 1}[value] super(diffeoScalarVol, self)._format_arg(name, spec, value) if name == 'interpolation': value = {'trilinear': 0, 'NN': 1}[value] - super(diffeoScalarVol, self)._format_arg(name, spec, value) + super(diffeoScalarVol, self)._format_arg(name, spec, value)''' diff --git a/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVol.py b/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVol.py index 1fb6b423fb..8d944d74d5 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVol.py +++ b/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVol.py @@ -23,8 +23,8 @@ def test_diffeoScalarVol_inputs(): argstr='-in %s', mandatory=True, ), - interp=dict( - argstr='-interp %d', + interpolation=dict( + argstr='-interp %s', exists=True, usedefault=True, ), @@ -35,7 +35,7 @@ def test_diffeoScalarVol_inputs(): name_template='%s_diffeoxfmd', ), resampling_type=dict( - argstr='-type %d', + argstr='-type %s', exists=True, ), target=dict( diff --git a/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVol.py b/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVol.py index b365a113b8..bcd734e283 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVol.py +++ b/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVol.py @@ -42,7 +42,7 @@ def test_diffeoSymTensor3DVol_inputs(): usedefault=True, ), resampling_type=dict( - argstr='-type %d', + argstr='-type %s', exists=True, ), target=dict( From cfcb91d20a62baa381a82091bed60f2df57d8f32 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Wed, 28 Mar 2018 23:19:16 -0700 Subject: [PATCH 34/53] fixed conversion int label to string --- nipype/interfaces/dtitk/registration.py | 32 +++++++------------------ 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index f3dd488ba9..884c6dfd6b 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -259,11 +259,7 @@ class affScalarVolInputSpec(CommandLineInputSpec): xor=['target', 'translation', 'euler', 'deformation'], desc='transform to apply: specify an input transformation\ file; parameters input will be ignored',) - '''interpolation = traits.Enum('trilinear', 'NN', - usedefault=True, argstr="-interp %s", - desc='trilinear or nearest neighbor\ - interpolation')''' - interpolation = traits.Enum(0, 1, + interpolation = traits.Enum('trilinear', 'NN', usedefault=True, argstr="-interp %s", desc='trilinear or nearest neighbor\ interpolation') @@ -306,10 +302,10 @@ class affScalarVol(CommandLineDtitk): output_spec = affScalarVolOutputSpec _cmd = 'affineScalarVolume' - '''def _format_arg(self, name, spec, value): + def _format_arg(self, name, spec, value): if name == 'interpolation': value = {'trilinear': 0, 'NN': 1}[value] - super(affScalarVol, self)._format_arg(name, spec, value)''' + return super(affScalarVol, self)._format_arg(name, spec, value) class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): @@ -336,12 +332,9 @@ class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): argstr="-vsize %g %g %g", xor=['target']) flip = traits.Tuple((traits.Int(), traits.Int(), traits.Int()), exists=True, argstr="-flip %d %d %d") - resampling_type = traits.Enum(1, 0, + resampling_type = traits.Enum('backward', 'forward', desc='use backward or forward resampling', exists=True, argstr="-type %s") - '''resampling_type = traits.Enum('backward', 'forward', - desc='use backward or forward resampling', - exists=True, argstr="-type %s")''' class diffeoSymTensor3DVolOutputSpec(TraitedSpec): @@ -368,10 +361,10 @@ class diffeoSymTensor3DVol(CommandLineDtitk): output_spec = diffeoSymTensor3DVolOutputSpec _cmd = 'deformationSymTensor3DVolume' - '''def _format_arg(self, name, spec, value): + def _format_arg(self, name, spec, value): if name == 'resampling_type': value = {'forward': 0, 'backward': 1}[value] - super(diffeoSymTensor3DVol, self)._format_arg(name, spec, value)''' + return super(diffeoSymTensor3DVol, self)._format_arg(name, spec, value) class diffeoScalarVolInputSpec(CommandLineInputSpec): @@ -390,17 +383,10 @@ class diffeoScalarVolInputSpec(CommandLineInputSpec): argstr="-vsize %g %g %g", xor=['target']) flip = traits.Tuple((traits.Int(), traits.Int(), traits.Int()), exists=True, argstr="-flip %d %d %d") - '''resampling_type = traits.Enum('backward', 'forward', + resampling_type = traits.Enum('backward', 'forward', desc='use backward or forward resampling', exists=True, argstr="-type %s") interpolation = traits.Enum('trilinear', 'NN', - desc='trilinear, or nearest neighbor', - exists=True, argstr="-interp %s", - usedefault=True)''' - resampling_type = traits.Enum(1, 0, - desc='use backward or forward resampling', - exists=True, argstr="-type %s") - interpolation = traits.Enum(0, 1, desc='trilinear, or nearest neighbor', exists=True, argstr="-interp %s", usedefault=True) @@ -430,10 +416,10 @@ class diffeoScalarVol(CommandLineDtitk): output_spec = diffeoScalarVolOutputSpec _cmd = 'deformationScalarVolume' - '''def _format_arg(self, name, spec, value): + def _format_arg(self, name, spec, value): if name == 'resampling_type': value = {'forward': 0, 'backward': 1}[value] super(diffeoScalarVol, self)._format_arg(name, spec, value) if name == 'interpolation': value = {'trilinear': 0, 'NN': 1}[value] - super(diffeoScalarVol, self)._format_arg(name, spec, value)''' + return super(diffeoScalarVol, self)._format_arg(name, spec, value) From a10da5d00df9006ef5bfaf0c80eee8bd5156c273 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Thu, 29 Mar 2018 00:38:15 -0700 Subject: [PATCH 35/53] temp fix composexfm naming (still a problem) --- nipype/interfaces/dtitk/registration.py | 18 ++++++++++++------ .../dtitk/tests/test_auto_ComposeXfm.py | 3 +-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 884c6dfd6b..86ed72b41e 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -165,7 +165,8 @@ class ComposeXfmInputSpec(CommandLineInputSpec): argstr="-aff %s", mandatory=True) out_file = File(desc='output path', argstr="-out %s", name_source="in_df", - name_template="%s_aff.df", keep_extension=True) + name_template="%s_affdf.nii") + # keep_extension is keeping the .df but not .nii; need to figure out class ComposeXfmOutputSpec(TraitedSpec): @@ -184,7 +185,8 @@ class ComposeXfm(CommandLineDtitk): >>> node.inputs.in_df = 'im_warp.df.nii' >>> node.inputs.in_aff= 'im_affine.aff' >>> node.cmdline - 'dfRightComposeAffine -aff im_affine.aff -df im_warp.df.nii -out im_warp.df_aff.df' + 'dfRightComposeAffine -aff im_affine.aff -df im_warp.df.nii -out\ + im_warp.df_affdf.nii' >>> node.run() # doctest: +SKIP """ input_spec = ComposeXfmInputSpec @@ -241,7 +243,8 @@ class affSymTensor3DVol(CommandLineDtitk): >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_affine.aff' >>> node.cmdline - 'affineSymTensor3DVolume -in im1.nii -interp LEI -out im1_affxfmd.nii -reorient PPD -trans im_affine.aff' + 'affineSymTensor3DVolume -in im1.nii -interp LEI -out im1_affxfmd.nii\ + -reorient PPD -trans im_affine.aff' >>> node.run() # doctest: +SKIP """ input_spec = affSymTensor3DVolInputSpec @@ -295,7 +298,8 @@ class affScalarVol(CommandLineDtitk): >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_affine.aff' >>> node.cmdline - 'affineScalarVolume -in im1.nii -interp 0 -out im1_affxfmd.nii -trans im_affine.aff' + 'affineScalarVolume -in im1.nii -interp 0 -out im1_affxfmd.nii -trans\ + im_affine.aff' >>> node.run() # doctest: +SKIP """ input_spec = affScalarVolInputSpec @@ -353,7 +357,8 @@ class diffeoSymTensor3DVol(CommandLineDtitk): >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_warp.df.nii' >>> node.cmdline - 'deformationSymTensor3DVolume -df FD -in im1.nii -interp LEI -out im1_diffeoxfmd.nii -reorient PPD -trans im_warp.df.nii' + 'deformationSymTensor3DVolume -df FD -in im1.nii -interp LEI -out\ + im1_diffeoxfmd.nii -reorient PPD -trans im_warp.df.nii' >>> node.run() # doctest: +SKIP """ @@ -408,7 +413,8 @@ class diffeoScalarVol(CommandLineDtitk): >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_warp.df.nii' >>> node.cmdline - 'deformationScalarVolume -in im1.nii -interp 0 -out im1_diffeoxfmd.nii -trans im_warp.df.nii' + 'deformationScalarVolume -in im1.nii -interp 0 -out im1_diffeoxfmd.nii\ + -trans im_warp.df.nii' >>> node.run() # doctest: +SKIP """ diff --git a/nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py b/nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py index 19c7525733..7e084ef36b 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py +++ b/nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py @@ -26,9 +26,8 @@ def test_ComposeXfm_inputs(): ), out_file=dict( argstr='-out %s', - keep_extension=True, name_source='in_df', - name_template='%s_aff.df', + name_template='%s_affdf.nii', ), terminal_output=dict( deprecated='1.0.0', From 0839823202003b2976c958d6891ea125488a26b2 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Fri, 30 Mar 2018 13:00:20 -0400 Subject: [PATCH 36/53] fixed syntax, line continuation --- nipype/interfaces/dtitk/registration.py | 62 ++++++++++++------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 86ed72b41e..39934d7211 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -185,8 +185,8 @@ class ComposeXfm(CommandLineDtitk): >>> node.inputs.in_df = 'im_warp.df.nii' >>> node.inputs.in_aff= 'im_affine.aff' >>> node.cmdline - 'dfRightComposeAffine -aff im_affine.aff -df im_warp.df.nii -out\ - im_warp.df_affdf.nii' + 'dfRightComposeAffine -aff im_affine.aff -df im_warp.df.nii -out' + ' im_warp.df_affdf.nii' >>> node.run() # doctest: +SKIP """ input_spec = ComposeXfmInputSpec @@ -202,18 +202,18 @@ class affSymTensor3DVolInputSpec(CommandLineInputSpec): name_template="%s_affxfmd", keep_extension=True) transform = File(exists=True, argstr="-trans %s", xor=['target', 'translation', 'euler', 'deformation'], - desc='transform to apply: specify an input transformation\ - file; parameters input will be ignored',) + desc='transform to apply: specify an input transformation' + ' file; parameters input will be ignored',) interpolation = traits.Enum('LEI', 'EI', usedefault=True, argstr="-interp %s", desc='Log Euclidean/Euclidean Interpolation') reorient = traits.Enum('PPD', 'NO', 'FS', argstr='-reorient %s', - usedefault=True, desc='Reorientation strategy: \ - preservation of principal direction, no \ - reorientation, or finite strain') + usedefault=True, desc='Reorientation strategy: ' + 'preservation of principal direction, no ' + 'reorientation, or finite strain') target = File(exists=True, argstr="-target %s", xor=['transform'], - desc='output volume specification read from the target volume\ - if specified') + desc='output volume specification read from the target ' + 'volume if specified') translation = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), desc='translation (x,y,z) in mm', @@ -222,7 +222,7 @@ class affSymTensor3DVolInputSpec(CommandLineInputSpec): euler = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), desc='(theta, phi, psi) in degrees', xor=['transform'], argstr='-euler %g %g %g') - deformation = traits.Tuple(traits.Tuple((traits.Float(),) * 6, ...), + deformation = traits.Tuple((traits.Float(),) * 6, desc='(xx,yy,zz,xy,yz,xz)', xor=['transform'], argstr='-deformation %g %g %g %g %g %g') @@ -243,7 +243,7 @@ class affSymTensor3DVol(CommandLineDtitk): >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_affine.aff' >>> node.cmdline - 'affineSymTensor3DVolume -in im1.nii -interp LEI -out im1_affxfmd.nii\ + 'affineSymTensor3DVolume -in im1.nii -interp LEI -out im1_affxfmd.nii' -reorient PPD -trans im_affine.aff' >>> node.run() # doctest: +SKIP """ @@ -260,15 +260,15 @@ class affScalarVolInputSpec(CommandLineInputSpec): name_template="%s_affxfmd", keep_extension=True) transform = File(exists=True, argstr="-trans %s", xor=['target', 'translation', 'euler', 'deformation'], - desc='transform to apply: specify an input transformation\ - file; parameters input will be ignored',) + desc='transform to apply: specify an input transformation' + ' file; parameters input will be ignored',) interpolation = traits.Enum('trilinear', 'NN', usedefault=True, argstr="-interp %s", - desc='trilinear or nearest neighbor\ - interpolation') + desc='trilinear or nearest neighbor' + ' interpolation') target = File(exists=True, argstr="-target %s", xor=['transform'], - desc='output volume specification read from the target volume\ - if specified') + desc='output volume specification read from the target ' + 'volume if specified') translation = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), desc='translation (x,y,z) in mm', @@ -277,7 +277,7 @@ class affScalarVolInputSpec(CommandLineInputSpec): euler = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), desc='(theta, phi, psi) in degrees', xor=['transform'], argstr='-euler %g %g %g') - deformation = traits.Tuple(traits.Tuple((traits.Float(),) * 6, ...), + deformation = traits.Tuple((traits.Float(),) * 6, desc='(xx,yy,zz,xy,yz,xz)', xor=['transform'], argstr='-deformation %g %g %g %g %g %g') @@ -298,8 +298,8 @@ class affScalarVol(CommandLineDtitk): >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_affine.aff' >>> node.cmdline - 'affineScalarVolume -in im1.nii -interp 0 -out im1_affxfmd.nii -trans\ - im_affine.aff' + 'affineScalarVolume -in im1.nii -interp 0 -out im1_affxfmd.nii -trans' + ' im_affine.aff' >>> node.run() # doctest: +SKIP """ input_spec = affScalarVolInputSpec @@ -325,12 +325,12 @@ class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): argstr="-interp %s", desc='Log Euclidean/Euclidean Interpolation') reorient = traits.Enum('PPD', 'FS', argstr='-reorient %s', - usedefault=True, desc='Reorientation strategy: \ - preservation of principal direction or finite \ - strain') + usedefault=True, desc='Reorientation strategy: ' + 'preservation of principal direction or finite ' + 'strain') target = File(exists=True, argstr="-target %s", xor=['voxel_size'], - desc='output volume specification read from the target volume\ - if specified') + desc='output volume specification read from the target ' + 'volume if specified') voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), desc='xyz voxel size (superseded by target)', argstr="-vsize %g %g %g", xor=['target']) @@ -357,8 +357,8 @@ class diffeoSymTensor3DVol(CommandLineDtitk): >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_warp.df.nii' >>> node.cmdline - 'deformationSymTensor3DVolume -df FD -in im1.nii -interp LEI -out\ - im1_diffeoxfmd.nii -reorient PPD -trans im_warp.df.nii' + 'deformationSymTensor3DVolume -df FD -in im1.nii -interp LEI -out' + ' im1_diffeoxfmd.nii -reorient PPD -trans im_warp.df.nii' >>> node.run() # doctest: +SKIP """ @@ -381,8 +381,8 @@ class diffeoScalarVolInputSpec(CommandLineInputSpec): transform = transform = File(exists=True, argstr="-trans %s", mandatory=True, desc='transform to apply') target = File(exists=True, argstr="-target %s", xor=['voxel_size'], - desc='output volume specification read from the target volume\ - if specified') + desc='output volume specification read from the target ' + 'volume if specified') voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), desc='xyz voxel size (superseded by target)', argstr="-vsize %g %g %g", xor=['target']) @@ -413,8 +413,8 @@ class diffeoScalarVol(CommandLineDtitk): >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_warp.df.nii' >>> node.cmdline - 'deformationScalarVolume -in im1.nii -interp 0 -out im1_diffeoxfmd.nii\ - -trans im_warp.df.nii' + 'deformationScalarVolume -in im1.nii -interp 0 -out im1_diffeoxfmd.nii' + ' -trans im_warp.df.nii' >>> node.run() # doctest: +SKIP """ From 1379dc635bdbcfa7ff028efe0c00eb31866d68d6 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Fri, 30 Mar 2018 14:24:08 -0400 Subject: [PATCH 37/53] fixed strings for tests --- nipype/interfaces/dtitk/registration.py | 26 ++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 39934d7211..949307101b 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -184,9 +184,9 @@ class ComposeXfm(CommandLineDtitk): >>> node = dtitk.ComposeXfm() >>> node.inputs.in_df = 'im_warp.df.nii' >>> node.inputs.in_aff= 'im_affine.aff' - >>> node.cmdline - 'dfRightComposeAffine -aff im_affine.aff -df im_warp.df.nii -out' - ' im_warp.df_affdf.nii' + >>> node.cmdline #doctest: + 'dfRightComposeAffine -aff im_affine.aff -df im_warp.df.nii -out\ + im_warp.df_affdf.nii' >>> node.run() # doctest: +SKIP """ input_spec = ComposeXfmInputSpec @@ -242,8 +242,8 @@ class affSymTensor3DVol(CommandLineDtitk): >>> node = dtitk.affSymTensor3DVol() >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_affine.aff' - >>> node.cmdline - 'affineSymTensor3DVolume -in im1.nii -interp LEI -out im1_affxfmd.nii' + >>> node.cmdline #doctest: + 'affineSymTensor3DVolume -in im1.nii -interp LEI -out im1_affxfmd.nii\ -reorient PPD -trans im_affine.aff' >>> node.run() # doctest: +SKIP """ @@ -297,9 +297,9 @@ class affScalarVol(CommandLineDtitk): >>> node = dtitk.affScalarVol() >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_affine.aff' - >>> node.cmdline - 'affineScalarVolume -in im1.nii -interp 0 -out im1_affxfmd.nii -trans' - ' im_affine.aff' + >>> node.cmdline #doctest: + 'affineScalarVolume -in im1.nii -interp 0 -out im1_affxfmd.nii -trans\ + im_affine.aff' >>> node.run() # doctest: +SKIP """ input_spec = affScalarVolInputSpec @@ -356,9 +356,9 @@ class diffeoSymTensor3DVol(CommandLineDtitk): >>> node = dtitk.diffeoSymTensor3DVol() >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_warp.df.nii' - >>> node.cmdline - 'deformationSymTensor3DVolume -df FD -in im1.nii -interp LEI -out' - ' im1_diffeoxfmd.nii -reorient PPD -trans im_warp.df.nii' + >>> node.cmdline #doctest: + 'deformationSymTensor3DVolume -df FD -in im1.nii -interp LEI -out\ + im1_diffeoxfmd.nii -reorient PPD -trans im_warp.df.nii' >>> node.run() # doctest: +SKIP """ @@ -413,8 +413,8 @@ class diffeoScalarVol(CommandLineDtitk): >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_warp.df.nii' >>> node.cmdline - 'deformationScalarVolume -in im1.nii -interp 0 -out im1_diffeoxfmd.nii' - ' -trans im_warp.df.nii' + 'deformationScalarVolume -in im1.nii -interp 0 -out im1_diffeoxfmd.nii\ + -trans im_warp.df.nii' >>> node.run() # doctest: +SKIP """ From 4cedad980fa7628529ff5f5a0dd69e75273ab7a3 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Tue, 3 Apr 2018 14:15:30 -0700 Subject: [PATCH 38/53] merged master, ran make specs --- nipype/interfaces/tests/test_auto_Dcm2nii.py | 110 +++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 nipype/interfaces/tests/test_auto_Dcm2nii.py diff --git a/nipype/interfaces/tests/test_auto_Dcm2nii.py b/nipype/interfaces/tests/test_auto_Dcm2nii.py new file mode 100644 index 0000000000..044a0f918b --- /dev/null +++ b/nipype/interfaces/tests/test_auto_Dcm2nii.py @@ -0,0 +1,110 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..dcm2nii import Dcm2nii + + +def test_Dcm2nii_inputs(): + input_map = dict( + anonymize=dict( + argstr='-a', + usedefault=True, + ), + args=dict(argstr='%s', ), + collapse_folders=dict( + argstr='-c', + usedefault=True, + ), + config_file=dict( + argstr='-b %s', + genfile=True, + ), + convert_all_pars=dict( + argstr='-v', + usedefault=True, + ), + date_in_filename=dict( + argstr='-d', + usedefault=True, + ), + environ=dict( + nohash=True, + usedefault=True, + ), + events_in_filename=dict( + argstr='-e', + usedefault=True, + ), + gzip_output=dict( + argstr='-g', + usedefault=True, + ), + id_in_filename=dict( + argstr='-i', + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + nii_output=dict( + argstr='-n', + usedefault=True, + ), + output_dir=dict( + argstr='-o %s', + genfile=True, + ), + protocol_in_filename=dict( + argstr='-p', + usedefault=True, + ), + reorient=dict(argstr='-r', ), + reorient_and_crop=dict( + argstr='-x', + usedefault=True, + ), + source_dir=dict( + argstr='%s', + mandatory=True, + position=-1, + xor=['source_names'], + ), + source_in_filename=dict( + argstr='-f', + usedefault=True, + ), + source_names=dict( + argstr='%s', + copyfile=False, + mandatory=True, + position=-1, + xor=['source_dir'], + ), + spm_analyze=dict( + argstr='-s', + xor=['nii_output'], + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + ) + inputs = Dcm2nii.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_Dcm2nii_outputs(): + output_map = dict( + bvals=dict(), + bvecs=dict(), + converted_files=dict(), + reoriented_and_cropped_files=dict(), + reoriented_files=dict(), + ) + outputs = Dcm2nii.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 155ae52cc8852e9b292309b134977c4b8aa0e021 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Tue, 3 Apr 2018 16:07:45 -0700 Subject: [PATCH 39/53] miscellaneous fixes from code review --- nipype/interfaces/dtitk/__init__.py | 4 +- nipype/interfaces/dtitk/registration.py | 113 +++++++++--------- .../dtitk/tests/test_auto_Affine.py | 4 +- .../dtitk/tests/test_auto_Diffeo.py | 2 - .../interfaces/dtitk/tests/test_auto_Rigid.py | 4 +- .../dtitk/tests/test_auto_TVtool.py | 5 +- .../dtitk/tests/test_auto_affScalarVol.py | 10 +- .../tests/test_auto_affSymTensor3DVol.py | 10 +- .../dtitk/tests/test_auto_diffeoScalarVol.py | 21 ++-- .../tests/test_auto_diffeoSymTensor3DVol.py | 20 ++-- nipype/interfaces/dtitk/utils.py | 21 ++-- 11 files changed, 98 insertions(+), 116 deletions(-) diff --git a/nipype/interfaces/dtitk/__init__.py b/nipype/interfaces/dtitk/__init__.py index 39a1125cb3..a41c09e588 100644 --- a/nipype/interfaces/dtitk/__init__.py +++ b/nipype/interfaces/dtitk/__init__.py @@ -7,7 +7,7 @@ # from .base import () from .registration import (Rigid, Affine, Diffeo, - ComposeXfm, diffeoSymTensor3DVol, affSymTensor3DVol, - affScalarVol,diffeoScalarVol) + ComposeXfm, DiffeoSymTensor3DVol, AffSymTensor3DVol, + AffScalarVol, DiffeoScalarVol) from .utils import (TVAdjustVoxSp, SVAdjustVoxSp, TVResample, SVResample, TVtool, BinThresh) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 949307101b..56802d36e9 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -39,14 +39,14 @@ class RigidInputSpec(CommandLineInputSpec): similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', mandatory=True, position=2, argstr="%s", desc="similarity metric", usedefault=True) - samplingXYZ = traits.Tuple((4, 4, 4), mandatory=True, position=3, - argstr="%g %g %g", usedefault=True, - desc="dist between samp points (mm) (x,y,z)") + sampling_xyz = traits.Tuple((4, 4, 4), mandatory=True, position=3, + argstr="%g %g %g", usedefault=True, + desc="dist between samp points (mm) (x,y,z)") ftol = traits.Float(mandatory=True, position=4, argstr="%g", desc="cost function tolerance", default_value=0.01, usedefault=True) - useInTrans = traits.Bool(position=5, argstr="1", - desc="to initialize with existing xfm set as 1") + use_in_trans = traits.Bool(position=5, argstr="1", + desc="initialize with existing transform") class RigidOutputSpec(TraitedSpec): @@ -65,9 +65,9 @@ class Rigid(CommandLineDtitk): >>> node.inputs.fixed_file = 'im1.nii' >>> node.inputs.moving_file = 'im2.nii' >>> node.inputs.similarity_metric = 'EDS' - >>> node.inputs.samplingXYZ = (4,4,4) + >>> node.inputs.sampling_xyz = (4,4,4) >>> node.inputs.ftol = 0.01 - >>> node.inputs.useInTrans = True + >>> node.inputs.use_in_trans = True >>> node.cmdline 'dti_rigid_reg im1.nii im2.nii EDS 4 4 4 0.01 1' >>> node.run() # doctest: +SKIP @@ -96,9 +96,9 @@ class Affine(Rigid): >>> node.inputs.fixed_file = 'im1.nii' >>> node.inputs.moving_file = 'im2.nii' >>> node.inputs.similarity_metric = 'EDS' - >>> node.inputs.samplingXYZ = (4,4,4) + >>> node.inputs.sampling_xyz = (4,4,4) >>> node.inputs.ftol = 0.01 - >>> node.inputs.useInTrans = True + >>> node.inputs.use_in_trans = True >>> node.cmdline 'dti_affine_reg im1.nii im2.nii EDS 4 4 4 0.01 1' >>> node.run() # doctest: +SKIP @@ -116,10 +116,10 @@ class DiffeoInputSpec(CommandLineInputSpec): usedefault=True, mandatory=True, position=3, argstr="%d") n_iters = traits.Int(6, desc="number of iterations", - exists=True, mandatory=True, + mandatory=True, position=4, argstr="%d", usedefault=True) ftol = traits.Float(0.002, desc="iteration for the optimization to stop", - exists=True, mandatory=True, position=5, argstr="%g", + mandatory=True, position=5, argstr="%g", usedefault=True) @@ -152,7 +152,7 @@ class Diffeo(CommandLineDtitk): def _list_outputs(self): outputs = self.output_spec().get() - moving = self.inputs.moving_file() + moving = self.inputs.moving_file outputs['out_file_xfm'] = fname_presuffix(moving, suffix='_diffeo.df') outputs['out_file'] = fname_presuffix(moving, suffix='_diffeo') return outputs @@ -184,8 +184,8 @@ class ComposeXfm(CommandLineDtitk): >>> node = dtitk.ComposeXfm() >>> node.inputs.in_df = 'im_warp.df.nii' >>> node.inputs.in_aff= 'im_affine.aff' - >>> node.cmdline #doctest: - 'dfRightComposeAffine -aff im_affine.aff -df im_warp.df.nii -out\ + >>> node.cmdline + 'dfRightComposeAffine -aff im_affine.aff -df im_warp.df.nii -out im_warp.df_affdf.nii' >>> node.run() # doctest: +SKIP """ @@ -194,7 +194,7 @@ class ComposeXfm(CommandLineDtitk): _cmd = 'dfRightComposeAffine' -class affSymTensor3DVolInputSpec(CommandLineInputSpec): +class AffSymTensor3DVolInputSpec(CommandLineInputSpec): in_file = File(desc='moving tensor volume', exists=True, argstr="-in %s", mandatory=True) out_file = File(desc='output filename', @@ -215,7 +215,7 @@ class affSymTensor3DVolInputSpec(CommandLineInputSpec): desc='output volume specification read from the target ' 'volume if specified') translation = traits.Tuple((traits.Float(), traits.Float(), - traits.Float()), + traits.Float()), desc='translation (x,y,z) in mm', argstr='-translation %g %g %g', xor=['transform']) @@ -227,11 +227,11 @@ class affSymTensor3DVolInputSpec(CommandLineInputSpec): argstr='-deformation %g %g %g %g %g %g') -class affSymTensor3DVolOutputSpec(TraitedSpec): +class AffSymTensor3DVolOutputSpec(TraitedSpec): out_file = File(exists=True) -class affSymTensor3DVol(CommandLineDtitk): +class AffSymTensor3DVol(CommandLineDtitk): """ Applies affine transform to a tensor volume @@ -239,20 +239,20 @@ class affSymTensor3DVol(CommandLineDtitk): ------- >>> from nipype.interfaces import dtitk - >>> node = dtitk.affSymTensor3DVol() + >>> node = dtitk.AffSymTensor3DVol() >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_affine.aff' - >>> node.cmdline #doctest: - 'affineSymTensor3DVolume -in im1.nii -interp LEI -out im1_affxfmd.nii\ + >>> node.cmdline + 'affineSymTensor3DVolume -in im1.nii -interp LEI -out im1_affxfmd.nii -reorient PPD -trans im_affine.aff' >>> node.run() # doctest: +SKIP """ - input_spec = affSymTensor3DVolInputSpec - output_spec = affSymTensor3DVolOutputSpec + input_spec = AffSymTensor3DVolInputSpec + output_spec = AffSymTensor3DVolOutputSpec _cmd = 'affineSymTensor3DVolume' -class affScalarVolInputSpec(CommandLineInputSpec): +class AffScalarVolInputSpec(CommandLineInputSpec): in_file = File(desc='moving scalar volume', exists=True, argstr="-in %s", mandatory=True) out_file = File(desc='output filename', @@ -270,7 +270,7 @@ class affScalarVolInputSpec(CommandLineInputSpec): desc='output volume specification read from the target ' 'volume if specified') translation = traits.Tuple((traits.Float(), traits.Float(), - traits.Float()), + traits.Float()), desc='translation (x,y,z) in mm', argstr='-translation %g %g %g', xor=['transform']) @@ -282,11 +282,11 @@ class affScalarVolInputSpec(CommandLineInputSpec): argstr='-deformation %g %g %g %g %g %g') -class affScalarVolOutputSpec(TraitedSpec): +class AffScalarVolOutputSpec(TraitedSpec): out_file = File(desc='moved volume', exists=True) -class affScalarVol(CommandLineDtitk): +class AffScalarVol(CommandLineDtitk): """ Applies affine transform to a scalar volume @@ -294,25 +294,25 @@ class affScalarVol(CommandLineDtitk): ------- >>> from nipype.interfaces import dtitk - >>> node = dtitk.affScalarVol() + >>> node = dtitk.AffScalarVol() >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_affine.aff' - >>> node.cmdline #doctest: - 'affineScalarVolume -in im1.nii -interp 0 -out im1_affxfmd.nii -trans\ + >>> node.cmdline + 'affineScalarVolume -in im1.nii -interp 0 -out im1_affxfmd.nii -trans im_affine.aff' >>> node.run() # doctest: +SKIP """ - input_spec = affScalarVolInputSpec - output_spec = affScalarVolOutputSpec + input_spec = AffScalarVolInputSpec + output_spec = AffScalarVolOutputSpec _cmd = 'affineScalarVolume' def _format_arg(self, name, spec, value): if name == 'interpolation': value = {'trilinear': 0, 'NN': 1}[value] - return super(affScalarVol, self)._format_arg(name, spec, value) + return super(AffScalarVol, self)._format_arg(name, spec, value) -class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): +class DiffeoSymTensor3DVolInputSpec(CommandLineInputSpec): in_file = File(desc='moving tensor volume', exists=True, argstr="-in %s", mandatory=True) out_file = File(desc='output filename', @@ -335,17 +335,17 @@ class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): desc='xyz voxel size (superseded by target)', argstr="-vsize %g %g %g", xor=['target']) flip = traits.Tuple((traits.Int(), traits.Int(), traits.Int()), - exists=True, argstr="-flip %d %d %d") + argstr="-flip %d %d %d") resampling_type = traits.Enum('backward', 'forward', desc='use backward or forward resampling', - exists=True, argstr="-type %s") + argstr="-type %s") -class diffeoSymTensor3DVolOutputSpec(TraitedSpec): +class DiffeoSymTensor3DVolOutputSpec(TraitedSpec): out_file = File(exists=True) -class diffeoSymTensor3DVol(CommandLineDtitk): +class DiffeoSymTensor3DVol(CommandLineDtitk): """ Applies diffeomorphic transform to a tensor volume @@ -353,26 +353,26 @@ class diffeoSymTensor3DVol(CommandLineDtitk): ------- >>> from nipype.interfaces import dtitk - >>> node = dtitk.diffeoSymTensor3DVol() + >>> node = dtitk.DiffeoSymTensor3DVol() >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_warp.df.nii' - >>> node.cmdline #doctest: - 'deformationSymTensor3DVolume -df FD -in im1.nii -interp LEI -out\ + >>> node.cmdline + 'deformationSymTensor3DVolume -df FD -in im1.nii -interp LEI -out im1_diffeoxfmd.nii -reorient PPD -trans im_warp.df.nii' >>> node.run() # doctest: +SKIP """ - input_spec = diffeoSymTensor3DVolInputSpec - output_spec = diffeoSymTensor3DVolOutputSpec + input_spec = DiffeoSymTensor3DVolInputSpec + output_spec = DiffeoSymTensor3DVolOutputSpec _cmd = 'deformationSymTensor3DVolume' def _format_arg(self, name, spec, value): if name == 'resampling_type': value = {'forward': 0, 'backward': 1}[value] - return super(diffeoSymTensor3DVol, self)._format_arg(name, spec, value) + return super(DiffeoSymTensor3DVol, self)._format_arg(name, spec, value) -class diffeoScalarVolInputSpec(CommandLineInputSpec): +class DiffeoScalarVolInputSpec(CommandLineInputSpec): in_file = File(desc='moving scalar volume', exists=True, argstr="-in %s", mandatory=True) out_file = File(desc='output filename', @@ -387,21 +387,21 @@ class diffeoScalarVolInputSpec(CommandLineInputSpec): desc='xyz voxel size (superseded by target)', argstr="-vsize %g %g %g", xor=['target']) flip = traits.Tuple((traits.Int(), traits.Int(), traits.Int()), - exists=True, argstr="-flip %d %d %d") + argstr="-flip %d %d %d") resampling_type = traits.Enum('backward', 'forward', desc='use backward or forward resampling', - exists=True, argstr="-type %s") + argstr="-type %s") interpolation = traits.Enum('trilinear', 'NN', desc='trilinear, or nearest neighbor', - exists=True, argstr="-interp %s", + argstr="-interp %s", usedefault=True) -class diffeoScalarVolOutputSpec(TraitedSpec): +class DiffeoScalarVolOutputSpec(TraitedSpec): out_file = File(desc='moved volume', exists=True) -class diffeoScalarVol(CommandLineDtitk): +class DiffeoScalarVol(CommandLineDtitk): """ Applies diffeomorphic transform to a scalar volume @@ -409,23 +409,22 @@ class diffeoScalarVol(CommandLineDtitk): ------- >>> from nipype.interfaces import dtitk - >>> node = dtitk.diffeoScalarVol() + >>> node = dtitk.DiffeoScalarVol() >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.transform = 'im_warp.df.nii' >>> node.cmdline - 'deformationScalarVolume -in im1.nii -interp 0 -out im1_diffeoxfmd.nii\ + 'deformationScalarVolume -in im1.nii -interp 0 -out im1_diffeoxfmd.nii -trans im_warp.df.nii' >>> node.run() # doctest: +SKIP """ - input_spec = diffeoScalarVolInputSpec - output_spec = diffeoScalarVolOutputSpec + input_spec = DiffeoScalarVolInputSpec + output_spec = DiffeoScalarVolOutputSpec _cmd = 'deformationScalarVolume' def _format_arg(self, name, spec, value): if name == 'resampling_type': value = {'forward': 0, 'backward': 1}[value] - super(diffeoScalarVol, self)._format_arg(name, spec, value) - if name == 'interpolation': + elif name == 'interpolation': value = {'trilinear': 0, 'NN': 1}[value] - return super(diffeoScalarVol, self)._format_arg(name, spec, value) + return super(DiffeoScalarVol, self)._format_arg(name, spec, value) diff --git a/nipype/interfaces/dtitk/tests/test_auto_Affine.py b/nipype/interfaces/dtitk/tests/test_auto_Affine.py index d7ca264464..7bf7ab0e30 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_Affine.py +++ b/nipype/interfaces/dtitk/tests/test_auto_Affine.py @@ -32,7 +32,7 @@ def test_Affine_inputs(): mandatory=True, position=1, ), - samplingXYZ=dict( + sampling_xyz=dict( argstr='%g %g %g', mandatory=True, position=3, @@ -48,7 +48,7 @@ def test_Affine_inputs(): deprecated='1.0.0', nohash=True, ), - useInTrans=dict( + use_in_trans=dict( argstr='1', position=5, ), diff --git a/nipype/interfaces/dtitk/tests/test_auto_Diffeo.py b/nipype/interfaces/dtitk/tests/test_auto_Diffeo.py index d14424d5f0..a389d22bf9 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_Diffeo.py +++ b/nipype/interfaces/dtitk/tests/test_auto_Diffeo.py @@ -16,7 +16,6 @@ def test_Diffeo_inputs(): ), ftol=dict( argstr='%g', - exists=True, mandatory=True, position=5, usedefault=True, @@ -43,7 +42,6 @@ def test_Diffeo_inputs(): ), n_iters=dict( argstr='%d', - exists=True, mandatory=True, position=4, usedefault=True, diff --git a/nipype/interfaces/dtitk/tests/test_auto_Rigid.py b/nipype/interfaces/dtitk/tests/test_auto_Rigid.py index 0d5fdee8ee..a30ac2f440 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_Rigid.py +++ b/nipype/interfaces/dtitk/tests/test_auto_Rigid.py @@ -32,7 +32,7 @@ def test_Rigid_inputs(): mandatory=True, position=1, ), - samplingXYZ=dict( + sampling_xyz=dict( argstr='%g %g %g', mandatory=True, position=3, @@ -48,7 +48,7 @@ def test_Rigid_inputs(): deprecated='1.0.0', nohash=True, ), - useInTrans=dict( + use_in_trans=dict( argstr='1', position=5, ), diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVtool.py b/nipype/interfaces/dtitk/tests/test_auto_TVtool.py index 4f3bae6836..a1eceb7549 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_TVtool.py +++ b/nipype/interfaces/dtitk/tests/test_auto_TVtool.py @@ -19,10 +19,7 @@ def test_TVtool_inputs(): argstr='-in %s', mandatory=True, ), - in_flag=dict( - argstr='-%s', - exists=True, - ), + in_flag=dict(argstr='-%s', ), out_file=dict( argstr='-out %s', genfile=True, diff --git a/nipype/interfaces/dtitk/tests/test_auto_affScalarVol.py b/nipype/interfaces/dtitk/tests/test_auto_affScalarVol.py index d5f229dcc9..b9c01c4933 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_affScalarVol.py +++ b/nipype/interfaces/dtitk/tests/test_auto_affScalarVol.py @@ -1,9 +1,9 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..registration import affScalarVol +from ..registration import AffScalarVol -def test_affScalarVol_inputs(): +def test_AffScalarVol_inputs(): input_map = dict( args=dict(argstr='%s', ), deformation=dict( @@ -54,14 +54,14 @@ def test_affScalarVol_inputs(): xor=['transform'], ), ) - inputs = affScalarVol.input_spec() + inputs = AffScalarVol.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_affScalarVol_outputs(): +def test_AffScalarVol_outputs(): output_map = dict(out_file=dict(), ) - outputs = affScalarVol.output_spec() + outputs = AffScalarVol.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVol.py b/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVol.py index 708aabff73..8004a09add 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVol.py +++ b/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVol.py @@ -1,9 +1,9 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..registration import affSymTensor3DVol +from ..registration import AffSymTensor3DVol -def test_affSymTensor3DVol_inputs(): +def test_AffSymTensor3DVol_inputs(): input_map = dict( args=dict(argstr='%s', ), deformation=dict( @@ -58,14 +58,14 @@ def test_affSymTensor3DVol_inputs(): xor=['transform'], ), ) - inputs = affSymTensor3DVol.input_spec() + inputs = AffSymTensor3DVol.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_affSymTensor3DVol_outputs(): +def test_AffSymTensor3DVol_outputs(): output_map = dict(out_file=dict(), ) - outputs = affSymTensor3DVol.output_spec() + outputs = AffSymTensor3DVol.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVol.py b/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVol.py index 8d944d74d5..86512dfa26 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVol.py +++ b/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVol.py @@ -1,19 +1,16 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..registration import diffeoScalarVol +from ..registration import DiffeoScalarVol -def test_diffeoScalarVol_inputs(): +def test_DiffeoScalarVol_inputs(): input_map = dict( args=dict(argstr='%s', ), environ=dict( nohash=True, usedefault=True, ), - flip=dict( - argstr='-flip %d %d %d', - exists=True, - ), + flip=dict(argstr='-flip %d %d %d', ), ignore_exception=dict( deprecated='1.0.0', nohash=True, @@ -25,7 +22,6 @@ def test_diffeoScalarVol_inputs(): ), interpolation=dict( argstr='-interp %s', - exists=True, usedefault=True, ), out_file=dict( @@ -34,10 +30,7 @@ def test_diffeoScalarVol_inputs(): name_source='in_file', name_template='%s_diffeoxfmd', ), - resampling_type=dict( - argstr='-type %s', - exists=True, - ), + resampling_type=dict(argstr='-type %s', ), target=dict( argstr='-target %s', xor=['voxel_size'], @@ -55,14 +48,14 @@ def test_diffeoScalarVol_inputs(): xor=['target'], ), ) - inputs = diffeoScalarVol.input_spec() + inputs = DiffeoScalarVol.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_diffeoScalarVol_outputs(): +def test_DiffeoScalarVol_outputs(): output_map = dict(out_file=dict(), ) - outputs = diffeoScalarVol.output_spec() + outputs = DiffeoScalarVol.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVol.py b/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVol.py index bcd734e283..31a516a7c9 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVol.py +++ b/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVol.py @@ -1,9 +1,9 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..registration import diffeoSymTensor3DVol +from ..registration import DiffeoSymTensor3DVol -def test_diffeoSymTensor3DVol_inputs(): +def test_DiffeoSymTensor3DVol_inputs(): input_map = dict( args=dict(argstr='%s', ), df=dict( @@ -14,10 +14,7 @@ def test_diffeoSymTensor3DVol_inputs(): nohash=True, usedefault=True, ), - flip=dict( - argstr='-flip %d %d %d', - exists=True, - ), + flip=dict(argstr='-flip %d %d %d', ), ignore_exception=dict( deprecated='1.0.0', nohash=True, @@ -41,10 +38,7 @@ def test_diffeoSymTensor3DVol_inputs(): argstr='-reorient %s', usedefault=True, ), - resampling_type=dict( - argstr='-type %s', - exists=True, - ), + resampling_type=dict(argstr='-type %s', ), target=dict( argstr='-target %s', xor=['voxel_size'], @@ -62,14 +56,14 @@ def test_diffeoSymTensor3DVol_inputs(): xor=['target'], ), ) - inputs = diffeoSymTensor3DVol.input_spec() + inputs = DiffeoSymTensor3DVol.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_diffeoSymTensor3DVol_outputs(): +def test_DiffeoSymTensor3DVol_outputs(): output_map = dict(out_file=dict(), ) - outputs = diffeoSymTensor3DVol.output_spec() + outputs = DiffeoSymTensor3DVol.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index 89f680bc60..a4fd059e8c 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -28,6 +28,7 @@ from ..base import TraitedSpec, CommandLineInputSpec, File, traits, isdefined from ...utils.filemanip import fname_presuffix from .base import CommandLineDtitk +import os __docformat__ = 'restructuredtext' @@ -213,9 +214,9 @@ class TVtoolInputSpec(CommandLineInputSpec): in_file = File(desc="scalar volume to resample", exists=True, argstr="-in %s", mandatory=True) '''NOTE: there are a lot more options here; not implementing all of them''' - in_flag = traits.Enum('fa', 'tr', 'ad', 'rd', 'pd', 'rgb', exists=True, + in_flag = traits.Enum('fa', 'tr', 'ad', 'rd', 'pd', 'rgb', argstr="-%s", desc='') - out_file = File(exists=True, argstr="-out %s", genfile=True) + out_file = File(argstr="-out %s", genfile=True) class TVtoolOutputSpec(TraitedSpec): @@ -243,17 +244,17 @@ class TVtool(CommandLineDtitk): def _list_outputs(self): outputs = self._outputs().get() - if not isdefined(self.inputs.out_file): - outputs['out_file'] = self._gen_filename('out_file') - else: - outputs['out_file'] = self.inputs.out_file + out_file = self.inputs.out_file + if not isdefined(out_file): + out_file = self._gen_filename('out_file') + outputs['out_file'] = os.abspath(out_file) return outputs def _gen_filename(self, name): - tensor_volume = self.inputs.in_file - output_name = fname_presuffix(tensor_volume, - suffix='_'+self.inputs.in_flag) - return output_name + if name != 'out_file': + return + return fname_presuffix(os.path.basename(self.inputs.in_file), + suffix='_' + self.inputs.in_flag) '''Note: SVTool not implemented at this time''' From e921ddf1cd542b0c645be602679eee6904cc2e0b Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Mon, 9 Apr 2018 15:30:49 -0700 Subject: [PATCH 40/53] added descriptions, few minor fixes --- nipype/interfaces/dtitk/registration.py | 4 +- .../dtitk/tests/test_auto_TVAdjustVoxSp.py | 1 - nipype/interfaces/dtitk/utils.py | 42 ++++++++++--------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 56802d36e9..622521bacb 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -378,8 +378,8 @@ class DiffeoScalarVolInputSpec(CommandLineInputSpec): out_file = File(desc='output filename', argstr="-out %s", name_source="in_file", name_template="%s_diffeoxfmd", keep_extension=True) - transform = transform = File(exists=True, argstr="-trans %s", - mandatory=True, desc='transform to apply') + transform = File(exists=True, argstr="-trans %s", + mandatory=True, desc='transform to apply') target = File(exists=True, argstr="-target %s", xor=['voxel_size'], desc='output volume specification read from the target ' 'volume if specified') diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSp.py b/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSp.py index 772e35f8e7..34d8c2bf4f 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSp.py +++ b/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSp.py @@ -25,7 +25,6 @@ def test_TVAdjustVoxSp_inputs(): ), out_file=dict( argstr='-out %s', - genfile=True, keep_extension=True, name_source='in_file', name_template='%s_avs', diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index a4fd059e8c..3fbab8d8b2 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -36,7 +36,7 @@ class TVAdjustVoxSpInputSpec(CommandLineInputSpec): in_file = File(desc="tensor volume to modify", exists=True, mandatory=True, argstr="-in %s") - out_file = File(genfile=True, desc='output path', + out_file = File(desc='output path', argstr="-out %s", name_source='in_file', name_template='%s_avs', keep_extension=True) target_file = File(desc='target volume to match', @@ -263,15 +263,19 @@ def _gen_filename(self, name): class BinThreshInputSpec(CommandLineInputSpec): in_file = File(desc='Image to threshold/binarize', exists=True, position=0, argstr="%s", mandatory=True) - out_file = File(desc='', position=1, argstr="%s", + out_file = File(desc='output path', position=1, argstr="%s", keep_extension=True, name_source='in_file', name_template='%s_thrbin') - lower_bound = traits.Float(0.01, position=2, argstr="%g", mandatory=True) - upper_bound = traits.Float(100, position=3, argstr="%g", mandatory=True) + lower_bound = traits.Float(0.01, position=2, argstr="%g", mandatory=True, + desc='lower bound of binarization range') + upper_bound = traits.Float(100, position=3, argstr="%g", mandatory=True, + desc='upper bound of binarization range') inside_value = traits.Float(1, position=4, argstr="%g", usedefault=True, - mandatory=True) + mandatory=True, desc='value for voxels in ' + 'binarization range') outside_value = traits.Float(0, position=5, argstr="%g", usedefault=True, - mandatory=True) + mandatory=True, desc='value for voxels' + 'outside of binarization range') class BinThreshOutputSpec(TraitedSpec): @@ -282,20 +286,20 @@ class BinThresh(CommandLineDtitk): """ Binarizes an image - Example - ------- + Example + ------- - >>> from nipype.interfaces import dtitk - >>> node = dtitk.BinThresh() - >>> node.inputs.in_file = 'im1.nii' - >>> node.inputs.lower_bound = 0 - >>> node.inputs.upper_bound = 100 - >>> node.inputs.inside_value = 1 - >>> node.inputs.outside_value = 0 - >>> node.cmdline - 'BinaryThresholdImageFilter im1.nii im1_thrbin.nii 0 100 1 0' - >>> node.run() # doctest: +SKIP - """ + >>> from nipype.interfaces import dtitk + >>> node = dtitk.BinThresh() + >>> node.inputs.in_file = 'im1.nii' + >>> node.inputs.lower_bound = 0 + >>> node.inputs.upper_bound = 100 + >>> node.inputs.inside_value = 1 + >>> node.inputs.outside_value = 0 + >>> node.cmdline + 'BinaryThresholdImageFilter im1.nii im1_thrbin.nii 0 100 1 0' + >>> node.run() # doctest: +SKIP + """ input_spec = BinThreshInputSpec output_spec = BinThreshOutputSpec From 08babbc9984f4bb74b6dc5c299743a2b4765f590 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Mon, 9 Apr 2018 15:47:10 -0700 Subject: [PATCH 41/53] removed automatic author label --- nipype/interfaces/dtitk/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index 3fbab8d8b2..df454ddfe3 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -23,7 +23,6 @@ 16899392. """ -__author__ = 'kjordan' from ..base import TraitedSpec, CommandLineInputSpec, File, traits, isdefined from ...utils.filemanip import fname_presuffix From f1fac4091802c378bdaa67e5ecc9c965a4c32f03 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Tue, 10 Apr 2018 09:57:48 -0700 Subject: [PATCH 42/53] temporary fix for composeXfm naming --- nipype/interfaces/dtitk/registration.py | 26 +++++++++++++++---- .../dtitk/tests/test_auto_ComposeXfm.py | 3 +-- nipype/interfaces/dtitk/utils.py | 2 +- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 622521bacb..38964ed13e 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -24,9 +24,10 @@ """ -from ..base import TraitedSpec, CommandLineInputSpec, traits, File +from ..base import TraitedSpec, CommandLineInputSpec, traits, File, isdefined from ...utils.filemanip import fname_presuffix from .base import CommandLineDtitk +import os __docformat__ = 'restructuredtext' @@ -164,9 +165,9 @@ class ComposeXfmInputSpec(CommandLineInputSpec): in_aff = File(desc='affine transform file', exists=True, argstr="-aff %s", mandatory=True) out_file = File(desc='output path', - argstr="-out %s", name_source="in_df", - name_template="%s_affdf.nii") - # keep_extension is keeping the .df but not .nii; need to figure out + argstr="-out %s", genfile=True) + # keep_extension is keeping the .df but not .nii + # need to fix when PR 2506 is done class ComposeXfmOutputSpec(TraitedSpec): @@ -186,13 +187,28 @@ class ComposeXfm(CommandLineDtitk): >>> node.inputs.in_aff= 'im_affine.aff' >>> node.cmdline 'dfRightComposeAffine -aff im_affine.aff -df im_warp.df.nii -out - im_warp.df_affdf.nii' + im_warp_affdf.df.nii' >>> node.run() # doctest: +SKIP """ input_spec = ComposeXfmInputSpec output_spec = ComposeXfmOutputSpec _cmd = 'dfRightComposeAffine' + def _list_outputs(self): + outputs = self._outputs().get() + out_file = self.inputs.out_file + if not isdefined(out_file): + out_file = self._gen_filename('out_file') + outputs['out_file'] = os.path.abspath(out_file) + return outputs + + def _gen_filename(self, name): + if name != 'out_file': + return + return fname_presuffix(os.path.basename( + self.inputs.in_df).split('.')[0], + suffix='_affdf.df.nii') + class AffSymTensor3DVolInputSpec(CommandLineInputSpec): in_file = File(desc='moving tensor volume', exists=True, diff --git a/nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py b/nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py index 7e084ef36b..368bd26fb2 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py +++ b/nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py @@ -26,8 +26,7 @@ def test_ComposeXfm_inputs(): ), out_file=dict( argstr='-out %s', - name_source='in_df', - name_template='%s_affdf.nii', + genfile=True, ), terminal_output=dict( deprecated='1.0.0', diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index df454ddfe3..6588d61482 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -246,7 +246,7 @@ def _list_outputs(self): out_file = self.inputs.out_file if not isdefined(out_file): out_file = self._gen_filename('out_file') - outputs['out_file'] = os.abspath(out_file) + outputs['out_file'] = os.path.abspath(out_file) return outputs def _gen_filename(self, name): From cae974e7023973eab1965587620ec9c8b6cd2b2a Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Tue, 10 Apr 2018 10:19:55 -0700 Subject: [PATCH 43/53] added mixin for backward compatability since interfaces were renamed --- nipype/interfaces/dtitk/base.py | 16 ++++++++++++ nipype/interfaces/dtitk/registration.py | 34 ++++++++++++++++++++++++- nipype/interfaces/dtitk/utils.py | 30 +++++++++++++++++++++- 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/nipype/interfaces/dtitk/base.py b/nipype/interfaces/dtitk/base.py index b14ad5ed23..890badac0d 100644 --- a/nipype/interfaces/dtitk/base.py +++ b/nipype/interfaces/dtitk/base.py @@ -28,10 +28,26 @@ from ...utils.filemanip import fname_presuffix from ..base import CommandLine from nipype.interfaces.fsl.base import Info +import warnings LOGGER = logging.getLogger('interface') +class DTITKRenameMixin(object): + def __init__(self, *args, **kwargs): + classes = [cls.__name__ for cls in self.__class__.mro()] + dep_name = classes[0] + rename_idx = classes.index('DTITKRenameMixin') + new_name = classes[rename_idx + 1] + warnings.warn('The {} interface has been renamed to {}\n' + 'Please see the documentation for DTI-TK ' + 'interfaces, as some inputs have been ' + 'added or renamed for clarity.' + ''.format(dep_name, new_name), + DeprecationWarning) + super(DTITKRenameMixin, self).__init__(*args, **kwargs) + + class CommandLineDtitk(CommandLine): def _gen_fname(self, basename, cwd=None, suffix=None, change_ext=True, diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 38964ed13e..542476b282 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -26,7 +26,7 @@ from ..base import TraitedSpec, CommandLineInputSpec, traits, File, isdefined from ...utils.filemanip import fname_presuffix -from .base import CommandLineDtitk +from .base import CommandLineDtitk, DTITKRenameMixin import os __docformat__ = 'restructuredtext' @@ -444,3 +444,35 @@ def _format_arg(self, name, spec, value): elif name == 'interpolation': value = {'trilinear': 0, 'NN': 1}[value] return super(DiffeoScalarVol, self)._format_arg(name, spec, value) + + +class RigidTask(DTITKRenameMixin, Rigid): + pass + + +class AffineTask(DTITKRenameMixin, Affine): + pass + + +class DiffeoTask(DTITKRenameMixin, Diffeo): + pass + + +class ComposeXfmTask(DTITKRenameMixin, ComposeXfm): + pass + + +class affScalarVolTask(DTITKRenameMixin, AffScalarVol): + pass + + +class affSymTensor3DVolTask(DTITKRenameMixin, AffSymTensor3DVol): + pass + + +class diffeoScalarVolTask(DTITKRenameMixin, DiffeoScalarVol): + pass + + +class diffeoSymTensor3DVolTask(DTITKRenameMixin, DiffeoSymTensor3DVol): + pass diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index 6588d61482..89a67c6af3 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -26,7 +26,7 @@ from ..base import TraitedSpec, CommandLineInputSpec, File, traits, isdefined from ...utils.filemanip import fname_presuffix -from .base import CommandLineDtitk +from .base import CommandLineDtitk, DTITKRenameMixin import os __docformat__ = 'restructuredtext' @@ -303,3 +303,31 @@ class BinThresh(CommandLineDtitk): input_spec = BinThreshInputSpec output_spec = BinThreshOutputSpec _cmd = 'BinaryThresholdImageFilter' + + +class BinThreshTASK(DTITKRenameMixin, BinThresh): + pass + + +class SVAdjustVoxSpTask(DTITKRenameMixin, SVAdjustVoxSp): + pass + + +class SVResampleTask(DTITKRenameMixin, SVResample): + pass + + +class TVAdjustOriginTask(DTITKRenameMixin, TVAdjustVoxSp): + pass + + +class TVAdjustVoxSpTask(DTITKRenameMixin, TVAdjustVoxSp): + pass + + +class TVResampleTask(DTITKRenameMixin, TVResample): + pass + + +class TVtoolTask(DTITKRenameMixin, TVtool): + pass From 7c41d5d498222e94ec8fbd97023ca477c164cae7 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Tue, 10 Apr 2018 11:35:56 -0700 Subject: [PATCH 44/53] fixed composeXfm naming; added tests for old interface names --- nipype/interfaces/dtitk/registration.py | 13 ++-- .../dtitk/tests/test_auto_AffineTask.py | 70 ++++++++++++++++++ .../dtitk/tests/test_auto_BinThreshTASK.py | 68 ++++++++++++++++++ .../dtitk/tests/test_auto_ComposeXfmTask.py | 47 ++++++++++++ .../dtitk/tests/test_auto_DiffeoTask.py | 68 ++++++++++++++++++ .../dtitk/tests/test_auto_RigidTask.py | 70 ++++++++++++++++++ .../tests/test_auto_SVAdjustVoxSpTask.py | 56 +++++++++++++++ .../dtitk/tests/test_auto_SVResampleTask.py | 61 ++++++++++++++++ .../tests/test_auto_TVAdjustOriginTask.py | 56 +++++++++++++++ .../tests/test_auto_TVAdjustVoxSpTask.py | 56 +++++++++++++++ .../dtitk/tests/test_auto_TVResampleTask.py | 62 ++++++++++++++++ .../dtitk/tests/test_auto_TVtoolTask.py | 43 +++++++++++ .../dtitk/tests/test_auto_affScalarVolTask.py | 68 ++++++++++++++++++ .../tests/test_auto_affSymTensor3DVolTask.py | 72 +++++++++++++++++++ .../tests/test_auto_diffeoScalarVolTask.py | 62 ++++++++++++++++ .../test_auto_diffeoSymTensor3DVolTask.py | 70 ++++++++++++++++++ 16 files changed, 936 insertions(+), 6 deletions(-) create mode 100644 nipype/interfaces/dtitk/tests/test_auto_AffineTask.py create mode 100644 nipype/interfaces/dtitk/tests/test_auto_BinThreshTASK.py create mode 100644 nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py create mode 100644 nipype/interfaces/dtitk/tests/test_auto_DiffeoTask.py create mode 100644 nipype/interfaces/dtitk/tests/test_auto_RigidTask.py create mode 100644 nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSpTask.py create mode 100644 nipype/interfaces/dtitk/tests/test_auto_SVResampleTask.py create mode 100644 nipype/interfaces/dtitk/tests/test_auto_TVAdjustOriginTask.py create mode 100644 nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSpTask.py create mode 100644 nipype/interfaces/dtitk/tests/test_auto_TVResampleTask.py create mode 100644 nipype/interfaces/dtitk/tests/test_auto_TVtoolTask.py create mode 100644 nipype/interfaces/dtitk/tests/test_auto_affScalarVolTask.py create mode 100644 nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVolTask.py create mode 100644 nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVolTask.py create mode 100644 nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVolTask.py diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 542476b282..cec2adfcf6 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -25,7 +25,7 @@ """ from ..base import TraitedSpec, CommandLineInputSpec, traits, File, isdefined -from ...utils.filemanip import fname_presuffix +from ...utils.filemanip import fname_presuffix, split_filename from .base import CommandLineDtitk, DTITKRenameMixin import os @@ -166,8 +166,6 @@ class ComposeXfmInputSpec(CommandLineInputSpec): argstr="-aff %s", mandatory=True) out_file = File(desc='output path', argstr="-out %s", genfile=True) - # keep_extension is keeping the .df but not .nii - # need to fix when PR 2506 is done class ComposeXfmOutputSpec(TraitedSpec): @@ -205,9 +203,12 @@ def _list_outputs(self): def _gen_filename(self, name): if name != 'out_file': return - return fname_presuffix(os.path.basename( - self.inputs.in_df).split('.')[0], - suffix='_affdf.df.nii') + path, base, ext = split_filename(self.inputs.in_df) + suffix = '_affdf' + if base.endswith('.df'): + suffix += '.df' + base = base[:-3] + return fname_presuffix(base, suffix=suffix + ext, use_ext=False) class AffSymTensor3DVolInputSpec(CommandLineInputSpec): diff --git a/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py b/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py new file mode 100644 index 0000000000..7a3d7a66ce --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py @@ -0,0 +1,70 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..registration import AffineTask + + +def test_AffineTask_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + fixed_file=dict( + argstr='%s', + mandatory=True, + position=0, + ), + ftol=dict( + argstr='%g', + mandatory=True, + position=4, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + moving_file=dict( + argstr='%s', + copyfile=False, + mandatory=True, + position=1, + ), + sampling_xyz=dict( + argstr='%g %g %g', + mandatory=True, + position=3, + usedefault=True, + ), + similarity_metric=dict( + argstr='%s', + mandatory=True, + position=2, + usedefault=True, + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + use_in_trans=dict( + argstr='1', + position=5, + ), + ) + inputs = AffineTask.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_AffineTask_outputs(): + output_map = dict( + out_file=dict(), + out_file_xfm=dict(), + ) + outputs = AffineTask.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_BinThreshTASK.py b/nipype/interfaces/dtitk/tests/test_auto_BinThreshTASK.py new file mode 100644 index 0000000000..515ff4d63f --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_BinThreshTASK.py @@ -0,0 +1,68 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..utils import BinThreshTASK + + +def test_BinThreshTASK_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='%s', + mandatory=True, + position=0, + ), + inside_value=dict( + argstr='%g', + mandatory=True, + position=4, + usedefault=True, + ), + lower_bound=dict( + argstr='%g', + mandatory=True, + position=2, + ), + out_file=dict( + argstr='%s', + keep_extension=True, + name_source='in_file', + name_template='%s_thrbin', + position=1, + ), + outside_value=dict( + argstr='%g', + mandatory=True, + position=5, + usedefault=True, + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + upper_bound=dict( + argstr='%g', + mandatory=True, + position=3, + ), + ) + inputs = BinThreshTASK.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_BinThreshTASK_outputs(): + output_map = dict(out_file=dict(), ) + outputs = BinThreshTASK.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py b/nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py new file mode 100644 index 0000000000..f76a1bc19d --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py @@ -0,0 +1,47 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..registration import ComposeXfmTask + + +def test_ComposeXfmTask_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_aff=dict( + argstr='-aff %s', + mandatory=True, + ), + in_df=dict( + argstr='-df %s', + copyfile=False, + mandatory=True, + ), + out_file=dict( + argstr='-out %s', + genfile=True, + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + ) + inputs = ComposeXfmTask.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_ComposeXfmTask_outputs(): + output_map = dict(out_file=dict(), ) + outputs = ComposeXfmTask.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_DiffeoTask.py b/nipype/interfaces/dtitk/tests/test_auto_DiffeoTask.py new file mode 100644 index 0000000000..0129f7d70c --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_DiffeoTask.py @@ -0,0 +1,68 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..registration import DiffeoTask + + +def test_DiffeoTask_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + fixed_file=dict( + argstr='%s', + position=0, + ), + ftol=dict( + argstr='%g', + mandatory=True, + position=5, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + legacy=dict( + argstr='%d', + mandatory=True, + position=3, + usedefault=True, + ), + mask_file=dict( + argstr='%s', + position=2, + ), + moving_file=dict( + argstr='%s', + copyfile=False, + position=1, + ), + n_iters=dict( + argstr='%d', + mandatory=True, + position=4, + usedefault=True, + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + ) + inputs = DiffeoTask.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_DiffeoTask_outputs(): + output_map = dict( + out_file=dict(), + out_file_xfm=dict(), + ) + outputs = DiffeoTask.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py b/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py new file mode 100644 index 0000000000..a7dbf275ab --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py @@ -0,0 +1,70 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..registration import RigidTask + + +def test_RigidTask_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + fixed_file=dict( + argstr='%s', + mandatory=True, + position=0, + ), + ftol=dict( + argstr='%g', + mandatory=True, + position=4, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + moving_file=dict( + argstr='%s', + copyfile=False, + mandatory=True, + position=1, + ), + sampling_xyz=dict( + argstr='%g %g %g', + mandatory=True, + position=3, + usedefault=True, + ), + similarity_metric=dict( + argstr='%s', + mandatory=True, + position=2, + usedefault=True, + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + use_in_trans=dict( + argstr='1', + position=5, + ), + ) + inputs = RigidTask.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_RigidTask_outputs(): + output_map = dict( + out_file=dict(), + out_file_xfm=dict(), + ) + outputs = RigidTask.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSpTask.py b/nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSpTask.py new file mode 100644 index 0000000000..88f328d80b --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSpTask.py @@ -0,0 +1,56 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..utils import SVAdjustVoxSpTask + + +def test_SVAdjustVoxSpTask_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + origin=dict( + argstr='-origin %g %g %g', + xor=['target_file'], + ), + out_file=dict( + argstr='-out %s', + keep_extension=True, + name_source='in_file', + name_template='%s_avs', + ), + target_file=dict( + argstr='-target %s', + xor=['voxel_size', 'origin'], + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target_file'], + ), + ) + inputs = SVAdjustVoxSpTask.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_SVAdjustVoxSpTask_outputs(): + output_map = dict(out_file=dict(), ) + outputs = SVAdjustVoxSpTask.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_SVResampleTask.py b/nipype/interfaces/dtitk/tests/test_auto_SVResampleTask.py new file mode 100644 index 0000000000..8058c94435 --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_SVResampleTask.py @@ -0,0 +1,61 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..utils import SVResampleTask + + +def test_SVResampleTask_inputs(): + input_map = dict( + align=dict(argstr='-align %s', ), + args=dict(argstr='%s', ), + array_size=dict( + argstr='-size %d %d %d', + xor=['target_file'], + ), + environ=dict( + nohash=True, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + origin=dict( + argstr='-origin %g %g %g', + xor=['target_file'], + ), + out_file=dict( + argstr='-out %s', + keep_extension=True, + name_source='in_file', + name_template='%s_resampled', + ), + target_file=dict( + argstr='-target %s', + xor=['array_size', 'voxel_size', 'origin'], + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target_file'], + ), + ) + inputs = SVResampleTask.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_SVResampleTask_outputs(): + output_map = dict(out_file=dict(), ) + outputs = SVResampleTask.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVAdjustOriginTask.py b/nipype/interfaces/dtitk/tests/test_auto_TVAdjustOriginTask.py new file mode 100644 index 0000000000..a111687d26 --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_TVAdjustOriginTask.py @@ -0,0 +1,56 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..utils import TVAdjustOriginTask + + +def test_TVAdjustOriginTask_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + origin=dict( + argstr='-origin %g %g %g', + xor=['target_file'], + ), + out_file=dict( + argstr='-out %s', + keep_extension=True, + name_source='in_file', + name_template='%s_avs', + ), + target_file=dict( + argstr='-target %s', + xor=['voxel_size', 'origin'], + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target_file'], + ), + ) + inputs = TVAdjustOriginTask.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_TVAdjustOriginTask_outputs(): + output_map = dict(out_file=dict(), ) + outputs = TVAdjustOriginTask.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSpTask.py b/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSpTask.py new file mode 100644 index 0000000000..7d4c3d6e7b --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSpTask.py @@ -0,0 +1,56 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..utils import TVAdjustVoxSpTask + + +def test_TVAdjustVoxSpTask_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + origin=dict( + argstr='-origin %g %g %g', + xor=['target_file'], + ), + out_file=dict( + argstr='-out %s', + keep_extension=True, + name_source='in_file', + name_template='%s_avs', + ), + target_file=dict( + argstr='-target %s', + xor=['voxel_size', 'origin'], + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target_file'], + ), + ) + inputs = TVAdjustVoxSpTask.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_TVAdjustVoxSpTask_outputs(): + output_map = dict(out_file=dict(), ) + outputs = TVAdjustVoxSpTask.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVResampleTask.py b/nipype/interfaces/dtitk/tests/test_auto_TVResampleTask.py new file mode 100644 index 0000000000..43ae1cd842 --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_TVResampleTask.py @@ -0,0 +1,62 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..utils import TVResampleTask + + +def test_TVResampleTask_inputs(): + input_map = dict( + align=dict(argstr='-align %s', ), + args=dict(argstr='%s', ), + array_size=dict( + argstr='-size %d %d %d', + xor=['target_file'], + ), + environ=dict( + nohash=True, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + interpolation=dict(argstr='-interp %s', ), + origin=dict( + argstr='-origin %g %g %g', + xor=['target_file'], + ), + out_file=dict( + argstr='-out %s', + keep_extension=True, + name_source='in_file', + name_template='%s_resampled', + ), + target_file=dict( + argstr='-target %s', + xor=['array_size', 'voxel_size', 'origin'], + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target_file'], + ), + ) + inputs = TVResampleTask.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_TVResampleTask_outputs(): + output_map = dict(out_file=dict(), ) + outputs = TVResampleTask.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVtoolTask.py b/nipype/interfaces/dtitk/tests/test_auto_TVtoolTask.py new file mode 100644 index 0000000000..cebbdc96a7 --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_TVtoolTask.py @@ -0,0 +1,43 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..utils import TVtoolTask + + +def test_TVtoolTask_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + in_flag=dict(argstr='-%s', ), + out_file=dict( + argstr='-out %s', + genfile=True, + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + ) + inputs = TVtoolTask.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_TVtoolTask_outputs(): + output_map = dict(out_file=dict(), ) + outputs = TVtoolTask.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_affScalarVolTask.py b/nipype/interfaces/dtitk/tests/test_auto_affScalarVolTask.py new file mode 100644 index 0000000000..e0d45372c2 --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_affScalarVolTask.py @@ -0,0 +1,68 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..registration import affScalarVolTask + + +def test_affScalarVolTask_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + deformation=dict( + argstr='-deformation %g %g %g %g %g %g', + xor=['transform'], + ), + environ=dict( + nohash=True, + usedefault=True, + ), + euler=dict( + argstr='-euler %g %g %g', + xor=['transform'], + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + interpolation=dict( + argstr='-interp %s', + usedefault=True, + ), + out_file=dict( + argstr='-out %s', + keep_extension=True, + name_source='in_file', + name_template='%s_affxfmd', + ), + target=dict( + argstr='-target %s', + xor=['transform'], + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + transform=dict( + argstr='-trans %s', + xor=['target', 'translation', 'euler', 'deformation'], + ), + translation=dict( + argstr='-translation %g %g %g', + xor=['transform'], + ), + ) + inputs = affScalarVolTask.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_affScalarVolTask_outputs(): + output_map = dict(out_file=dict(), ) + outputs = affScalarVolTask.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVolTask.py b/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVolTask.py new file mode 100644 index 0000000000..9b9502a4d7 --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVolTask.py @@ -0,0 +1,72 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..registration import affSymTensor3DVolTask + + +def test_affSymTensor3DVolTask_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + deformation=dict( + argstr='-deformation %g %g %g %g %g %g', + xor=['transform'], + ), + environ=dict( + nohash=True, + usedefault=True, + ), + euler=dict( + argstr='-euler %g %g %g', + xor=['transform'], + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + interpolation=dict( + argstr='-interp %s', + usedefault=True, + ), + out_file=dict( + argstr='-out %s', + keep_extension=True, + name_source='in_file', + name_template='%s_affxfmd', + ), + reorient=dict( + argstr='-reorient %s', + usedefault=True, + ), + target=dict( + argstr='-target %s', + xor=['transform'], + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + transform=dict( + argstr='-trans %s', + xor=['target', 'translation', 'euler', 'deformation'], + ), + translation=dict( + argstr='-translation %g %g %g', + xor=['transform'], + ), + ) + inputs = affSymTensor3DVolTask.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_affSymTensor3DVolTask_outputs(): + output_map = dict(out_file=dict(), ) + outputs = affSymTensor3DVolTask.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVolTask.py b/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVolTask.py new file mode 100644 index 0000000000..b3ef9827a6 --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVolTask.py @@ -0,0 +1,62 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..registration import diffeoScalarVolTask + + +def test_diffeoScalarVolTask_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + flip=dict(argstr='-flip %d %d %d', ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + interpolation=dict( + argstr='-interp %s', + usedefault=True, + ), + out_file=dict( + argstr='-out %s', + keep_extension=True, + name_source='in_file', + name_template='%s_diffeoxfmd', + ), + resampling_type=dict(argstr='-type %s', ), + target=dict( + argstr='-target %s', + xor=['voxel_size'], + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + transform=dict( + argstr='-trans %s', + mandatory=True, + ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target'], + ), + ) + inputs = diffeoScalarVolTask.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_diffeoScalarVolTask_outputs(): + output_map = dict(out_file=dict(), ) + outputs = diffeoScalarVolTask.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVolTask.py b/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVolTask.py new file mode 100644 index 0000000000..a380fcabc6 --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVolTask.py @@ -0,0 +1,70 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..registration import diffeoSymTensor3DVolTask + + +def test_diffeoSymTensor3DVolTask_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + df=dict( + argstr='-df %s', + usedefault=True, + ), + environ=dict( + nohash=True, + usedefault=True, + ), + flip=dict(argstr='-flip %d %d %d', ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + interpolation=dict( + argstr='-interp %s', + usedefault=True, + ), + out_file=dict( + argstr='-out %s', + keep_extension=True, + name_source='in_file', + name_template='%s_diffeoxfmd', + ), + reorient=dict( + argstr='-reorient %s', + usedefault=True, + ), + resampling_type=dict(argstr='-type %s', ), + target=dict( + argstr='-target %s', + xor=['voxel_size'], + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + transform=dict( + argstr='-trans %s', + mandatory=True, + ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target'], + ), + ) + inputs = diffeoSymTensor3DVolTask.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_diffeoSymTensor3DVolTask_outputs(): + output_map = dict(out_file=dict(), ) + outputs = diffeoSymTensor3DVolTask.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 5b2462c176308d8128f98f87553a0bdabfbe0ebc Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Tue, 10 Apr 2018 11:59:27 -0700 Subject: [PATCH 45/53] minor fixes --- nipype/interfaces/dtitk/base.py | 6 ++++++ nipype/interfaces/dtitk/utils.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/nipype/interfaces/dtitk/base.py b/nipype/interfaces/dtitk/base.py index 890badac0d..069016e7f3 100644 --- a/nipype/interfaces/dtitk/base.py +++ b/nipype/interfaces/dtitk/base.py @@ -13,6 +13,12 @@ * Rigid Tensor Registration * Affine Tensor Registration * Diffeomorphic Tensor Registration +* Combine affiine and diffeomorphic transforms +* Application of transform to tensor and scalar volumes +* Threshold and Binarize +* Adjusting the voxel space of tensor and scalar volumes +* Resampling tensor and scalar volumes +* Calculation of tensor metrics from tensor volume Examples -------- diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index 89a67c6af3..274ea2914e 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -305,7 +305,7 @@ class BinThresh(CommandLineDtitk): _cmd = 'BinaryThresholdImageFilter' -class BinThreshTASK(DTITKRenameMixin, BinThresh): +class BinThreshTask(DTITKRenameMixin, BinThresh): pass From a3c391cd17a6d30f42cb215c4352dfd03887c17f Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Tue, 10 Apr 2018 12:59:12 -0700 Subject: [PATCH 46/53] task vs TASK --- .../interfaces/dtitk/tests/test_auto_BinThreshTASK.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nipype/interfaces/dtitk/tests/test_auto_BinThreshTASK.py b/nipype/interfaces/dtitk/tests/test_auto_BinThreshTASK.py index 515ff4d63f..1f49ddce43 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_BinThreshTASK.py +++ b/nipype/interfaces/dtitk/tests/test_auto_BinThreshTASK.py @@ -1,9 +1,9 @@ # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT from __future__ import unicode_literals -from ..utils import BinThreshTASK +from ..utils import BinThreshTask -def test_BinThreshTASK_inputs(): +def test_BinThreshTask_inputs(): input_map = dict( args=dict(argstr='%s', ), environ=dict( @@ -54,14 +54,14 @@ def test_BinThreshTASK_inputs(): position=3, ), ) - inputs = BinThreshTASK.input_spec() + inputs = BinThreshTask.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_BinThreshTASK_outputs(): +def test_BinThreshTask_outputs(): output_map = dict(out_file=dict(), ) - outputs = BinThreshTASK.output_spec() + outputs = BinThreshTask.output_spec() for key, metadata in list(output_map.items()): for metakey, value in list(metadata.items()): From c644343cce991dfadad75e469c2fe11a4b6fe680 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Tue, 10 Apr 2018 22:22:53 -0700 Subject: [PATCH 47/53] bug: copyfile=False caused execution input to be changed from the correct directory (previous node) to the current node directory --- nipype/interfaces/dtitk/registration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index cec2adfcf6..221ea6e04f 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -161,7 +161,7 @@ def _list_outputs(self): class ComposeXfmInputSpec(CommandLineInputSpec): in_df = File(desc='diffeomorphic warp file', exists=True, - argstr="-df %s", copyfile=False, mandatory=True) + argstr="-df %s", mandatory=True) in_aff = File(desc='affine transform file', exists=True, argstr="-aff %s", mandatory=True) out_file = File(desc='output path', From 5df307ce6dcd4543121fb9a34d879cca0f84fc51 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Wed, 11 Apr 2018 11:25:52 -0700 Subject: [PATCH 48/53] tests for composexfm change --- nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py | 1 - nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py | 1 - 2 files changed, 2 deletions(-) diff --git a/nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py b/nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py index 368bd26fb2..9ee4c44650 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py +++ b/nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py @@ -21,7 +21,6 @@ def test_ComposeXfm_inputs(): ), in_df=dict( argstr='-df %s', - copyfile=False, mandatory=True, ), out_file=dict( diff --git a/nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py b/nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py index f76a1bc19d..0166be1c37 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py @@ -21,7 +21,6 @@ def test_ComposeXfmTask_inputs(): ), in_df=dict( argstr='-df %s', - copyfile=False, mandatory=True, ), out_file=dict( From 898db0cda1c65e5aae56c48847dbe7cbe2b1be34 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Wed, 11 Apr 2018 21:02:43 -0700 Subject: [PATCH 49/53] made files save to node working directories --- nipype/interfaces/dtitk/registration.py | 23 +++++++++++++------ .../dtitk/tests/test_auto_Affine.py | 10 ++++---- .../dtitk/tests/test_auto_AffineTask.py | 10 ++++---- .../interfaces/dtitk/tests/test_auto_Rigid.py | 10 ++++---- .../dtitk/tests/test_auto_RigidTask.py | 10 ++++---- 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 221ea6e04f..d075911414 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -34,7 +34,7 @@ class RigidInputSpec(CommandLineInputSpec): fixed_file = File(desc="fixed tensor volume", exists=True, - mandatory=True, position=0, argstr="%s") + mandatory=True, position=0, argstr="%s", copyfile=False) moving_file = File(desc="moving tensor volume", exists=True, mandatory=True, position=1, argstr="%s", copyfile=False) similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', @@ -46,8 +46,13 @@ class RigidInputSpec(CommandLineInputSpec): ftol = traits.Float(mandatory=True, position=4, argstr="%g", desc="cost function tolerance", default_value=0.01, usedefault=True) - use_in_trans = traits.Bool(position=5, argstr="1", - desc="initialize with existing transform") + # use_in_trans = traits.Bool(position=5, argstr="1", + # desc="initialize with existing transform") + initialize_xfm = File(desc="DTITK-FORMAT transform ", + copyfile=False, position=5, argstr="%s") + # need to enforce DTITK format or it's a silent failure + # (can we search the stderr for keywords to error if not found?) + # stderr: filename.aff doesn't exist or can't be opened class RigidOutputSpec(TraitedSpec): @@ -68,15 +73,19 @@ class Rigid(CommandLineDtitk): >>> node.inputs.similarity_metric = 'EDS' >>> node.inputs.sampling_xyz = (4,4,4) >>> node.inputs.ftol = 0.01 - >>> node.inputs.use_in_trans = True >>> node.cmdline - 'dti_rigid_reg im1.nii im2.nii EDS 4 4 4 0.01 1' + 'dti_rigid_reg im1.nii im2.nii EDS 4 4 4 0.01' >>> node.run() # doctest: +SKIP """ input_spec = RigidInputSpec output_spec = RigidOutputSpec _cmd = 'dti_rigid_reg' + '''def _format_arg(self, name, spec, value): + if name == 'initialize_xfm': + value = 1 + return super(Rigid, self)._format_arg(name, spec, value)''' + def _list_outputs(self): outputs = self.output_spec().get() moving = self.inputs.moving_file @@ -99,9 +108,9 @@ class Affine(Rigid): >>> node.inputs.similarity_metric = 'EDS' >>> node.inputs.sampling_xyz = (4,4,4) >>> node.inputs.ftol = 0.01 - >>> node.inputs.use_in_trans = True + >>> node.inputs.initialize_xfm = 'im_affine.aff' >>> node.cmdline - 'dti_affine_reg im1.nii im2.nii EDS 4 4 4 0.01 1' + 'dti_affine_reg im1.nii im2.nii EDS 4 4 4 0.01 im_affine.aff' >>> node.run() # doctest: +SKIP """ _cmd = 'dti_affine_reg' diff --git a/nipype/interfaces/dtitk/tests/test_auto_Affine.py b/nipype/interfaces/dtitk/tests/test_auto_Affine.py index 7bf7ab0e30..81c9f688ba 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_Affine.py +++ b/nipype/interfaces/dtitk/tests/test_auto_Affine.py @@ -12,6 +12,7 @@ def test_Affine_inputs(): ), fixed_file=dict( argstr='%s', + copyfile=False, mandatory=True, position=0, ), @@ -26,6 +27,11 @@ def test_Affine_inputs(): nohash=True, usedefault=True, ), + initialize_xfm=dict( + argstr='%s', + copyfile=False, + position=5, + ), moving_file=dict( argstr='%s', copyfile=False, @@ -48,10 +54,6 @@ def test_Affine_inputs(): deprecated='1.0.0', nohash=True, ), - use_in_trans=dict( - argstr='1', - position=5, - ), ) inputs = Affine.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py b/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py index 7a3d7a66ce..265867e56e 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py @@ -12,6 +12,7 @@ def test_AffineTask_inputs(): ), fixed_file=dict( argstr='%s', + copyfile=False, mandatory=True, position=0, ), @@ -26,6 +27,11 @@ def test_AffineTask_inputs(): nohash=True, usedefault=True, ), + initialize_xfm=dict( + argstr='%s', + copyfile=False, + position=5, + ), moving_file=dict( argstr='%s', copyfile=False, @@ -48,10 +54,6 @@ def test_AffineTask_inputs(): deprecated='1.0.0', nohash=True, ), - use_in_trans=dict( - argstr='1', - position=5, - ), ) inputs = AffineTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_Rigid.py b/nipype/interfaces/dtitk/tests/test_auto_Rigid.py index a30ac2f440..6ac4a52c50 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_Rigid.py +++ b/nipype/interfaces/dtitk/tests/test_auto_Rigid.py @@ -12,6 +12,7 @@ def test_Rigid_inputs(): ), fixed_file=dict( argstr='%s', + copyfile=False, mandatory=True, position=0, ), @@ -26,6 +27,11 @@ def test_Rigid_inputs(): nohash=True, usedefault=True, ), + initialize_xfm=dict( + argstr='%s', + copyfile=False, + position=5, + ), moving_file=dict( argstr='%s', copyfile=False, @@ -48,10 +54,6 @@ def test_Rigid_inputs(): deprecated='1.0.0', nohash=True, ), - use_in_trans=dict( - argstr='1', - position=5, - ), ) inputs = Rigid.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py b/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py index a7dbf275ab..af81954f4e 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py @@ -12,6 +12,7 @@ def test_RigidTask_inputs(): ), fixed_file=dict( argstr='%s', + copyfile=False, mandatory=True, position=0, ), @@ -26,6 +27,11 @@ def test_RigidTask_inputs(): nohash=True, usedefault=True, ), + initialize_xfm=dict( + argstr='%s', + copyfile=False, + position=5, + ), moving_file=dict( argstr='%s', copyfile=False, @@ -48,10 +54,6 @@ def test_RigidTask_inputs(): deprecated='1.0.0', nohash=True, ), - use_in_trans=dict( - argstr='1', - position=5, - ), ) inputs = RigidTask.input_spec() From ca52d94b293f88c9aca6b0b1e310e9313b74132f Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Thu, 12 Apr 2018 08:45:26 -0700 Subject: [PATCH 50/53] made check for ".aff not found" to raise error so that it doesn't fail silently --- nipype/interfaces/dtitk/registration.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index d075911414..806a72f35a 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -46,13 +46,8 @@ class RigidInputSpec(CommandLineInputSpec): ftol = traits.Float(mandatory=True, position=4, argstr="%g", desc="cost function tolerance", default_value=0.01, usedefault=True) - # use_in_trans = traits.Bool(position=5, argstr="1", - # desc="initialize with existing transform") initialize_xfm = File(desc="DTITK-FORMAT transform ", copyfile=False, position=5, argstr="%s") - # need to enforce DTITK format or it's a silent failure - # (can we search the stderr for keywords to error if not found?) - # stderr: filename.aff doesn't exist or can't be opened class RigidOutputSpec(TraitedSpec): @@ -86,6 +81,12 @@ class Rigid(CommandLineDtitk): value = 1 return super(Rigid, self)._format_arg(name, spec, value)''' + def _run_interface(self, runtime): + runtime = super(Rigid, self)._run_interface(runtime) + if '''.aff doesn't exist or can't be opened''' in runtime.stderr: + self.raise_exception(runtime) + return runtime + def _list_outputs(self): outputs = self.output_spec().get() moving = self.inputs.moving_file From 62240809996a8e3e1b7cc54375d5aceba3c3592d Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Thu, 12 Apr 2018 12:08:30 -0700 Subject: [PATCH 51/53] changed description on initialize_xfm --- nipype/interfaces/dtitk/registration.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 806a72f35a..f97b7a262b 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -46,8 +46,9 @@ class RigidInputSpec(CommandLineInputSpec): ftol = traits.Float(mandatory=True, position=4, argstr="%g", desc="cost function tolerance", default_value=0.01, usedefault=True) - initialize_xfm = File(desc="DTITK-FORMAT transform ", - copyfile=False, position=5, argstr="%s") + initialize_xfm = File(copyfile=True, desc="Initialize w/DTITK-FORMAT" + "transform ('1' initializes w/existing transform" + "in working directory)", position=5, argstr="%s") class RigidOutputSpec(TraitedSpec): From 769a0fc1f0b66b77eb009cdeca598b86b34dcffd Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Fri, 13 Apr 2018 10:04:25 -0700 Subject: [PATCH 52/53] added workflows for simple linear and nonlinear tensor registration --- nipype/workflows/dmri/dtitk/__init__.py | 8 ++ .../dmri/dtitk/tensor_registration.py | 126 ++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 nipype/workflows/dmri/dtitk/__init__.py create mode 100644 nipype/workflows/dmri/dtitk/tensor_registration.py diff --git a/nipype/workflows/dmri/dtitk/__init__.py b/nipype/workflows/dmri/dtitk/__init__.py new file mode 100644 index 0000000000..02dbf25549 --- /dev/null +++ b/nipype/workflows/dmri/dtitk/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +# coding: utf-8 +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- +# vi: set ft=python sts=4 ts=4 sw=4 et: + +from __future__ import absolute_import +from .tensor_registration import (affine_tensor_pipeline, + diffeomorphic_tensor_pipeline) diff --git a/nipype/workflows/dmri/dtitk/tensor_registration.py b/nipype/workflows/dmri/dtitk/tensor_registration.py new file mode 100644 index 0000000000..bf376d8556 --- /dev/null +++ b/nipype/workflows/dmri/dtitk/tensor_registration.py @@ -0,0 +1,126 @@ +# -*- coding: utf-8 -*- +# coding: utf-8 +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- +# vi: set ft=python sts=4 ts=4 sw=4 et: + +from ....pipeline import engine as pe +from ....interfaces import utility as niu +from ....interfaces import dtitk + + +def affine_tensor_pipeline(name='AffTen'): + + """ + Workflow that performs a linear registration + (Rigid followed by Affine) + + Example + ------- + + >>> from nipype.workflows.dmri.dtitk.tensor_registration import + affine_tensor_pipeline + >>> affine = affine_tensor_pipeline() + >>> affine.inputs.inputnode.fixed_file = 'im1.nii' + >>> affine.inputs.inputnode.moving_file = 'im2.nii' + >>> affine.run() # doctest: +SKIP + + + """ + inputnode = pe.Node(niu.IdentityInterface( + fields=['fixed_file', 'moving_file']), + name='inputnode') + outputnode = pe.Node(niu.IdentityInterface( + fields=['out_file', 'out_file_xfm']), + name='outputnode') + + rigid_node = pe.Node(dtitk.Rigid(), name='rigid_node') + affine_node = pe.Node(dtitk.Affine(), name='affine_node') + + wf = pe.Workflow(name=name) + + wf.connect(inputnode, 'fixed_file', rigid_node, 'fixed_file') + wf.connect(inputnode, 'moving_file', rigid_node, 'moving_file') + wf.connect(rigid_node, 'out_file_xfm', affine_node, 'initialize_xfm') + wf.connect(inputnode, 'fixed_file', affine_node, 'fixed_file') + wf.connect(inputnode, 'moving_file', affine_node, 'moving_file') + wf.connect(affine_node, 'out_file', outputnode, 'out_file') + wf.connect(affine_node, 'out_file_xfm', outputnode, 'out_file_xfm') + + return wf + + +def diffeomorphic_tensor_pipeline(name='DiffeoTen', + params={'array_size': (128, 128, 64)}): + """ + Workflow that performs a diffeomorphic registration + (Rigid and Affine follwed by Diffeomorphic) + Note: the requirements for a diffeomorphic registration specify that + the dimension 0 is a power of 2 so images are resliced prior to + registration + + Example + ------- + + >>> from nipype.workflows.dmri.dtitk.tensor_registration import + diffeomorphic_tensor_pipeline + >>> diffeo = diffeomorphic_tensor_pipeline() + >>> diffeo.inputs.inputnode.fixed_file = 'im1.nii' + >>> diffeo.inputs.inputnode.moving_file = 'im2.nii' + >>> diffeo.run() # doctest: +SKIP + + + """ + inputnode = pe.Node(niu.IdentityInterface( + fields=['fixed_file', 'moving_file']), + name='inputnode') + outputnode = pe.Node(niu.IdentityInterface( + fields=['out_file', 'out_file_xfm']), + name='outputnode') + + reslice_node_pow2 = pe.Node(dtitk.TVResample( + origin=(0, 0, 0), + array_size=params['array_size']), + name='reslice_node_pow2') + reslice_node_moving = pe.Node(dtitk.TVResample(), + name='reslice_node_moving') + mask_node = pe.Node(dtitk.BinThresh(lower_bound=0.01, upper_bound=100, + inside_value=1, outside_value=0), + name='mask_node') + rigid_node = pe.Node(dtitk.Rigid(), name='rigid_node') + affine_node = pe.Node(dtitk.Affine(), name='affine_node') + diffeo_node = pe.Node(dtitk.Diffeo(n_iters=6, ftol=0.002), + name='diffeo_node') + compose_xfm_node = pe.Node(dtitk.ComposeXfm(), name='compose_xfm_node') + apply_xfm_node = pe.Node(dtitk.DiffeoSymTensor3DVol(), + name='apply_xfm_node') + + wf = pe.Workflow(name=name) + + # Reslice input images + wf.connect(inputnode, 'fixed_file', reslice_node_pow2, 'in_file') + wf.connect(reslice_node_pow2, 'out_file', + reslice_node_moving, 'target_file') + wf.connect(inputnode, 'moving_file', reslice_node_moving, 'in_file') + # Rigid registration + wf.connect(reslice_node_pow2, 'out_file', rigid_node, 'fixed_file') + wf.connect(reslice_node_moving, 'out_file', rigid_node, 'moving_file') + # Affine registration + wf.connect(rigid_node, 'out_file_xfm', affine_node, 'initialize_xfm') + wf.connect(reslice_node_pow2, 'out_file', affine_node, 'fixed_file') + wf.connect(reslice_node_moving, 'out_file', affine_node, 'moving_file') + # Diffeo registration + wf.connect(reslice_node_pow2, 'out_file', mask_node, 'in_file') + wf.connect(reslice_node_pow2, 'out_file', diffeo_node, 'fixed_file') + wf.connect(affine_node, 'out_file', diffeo_node, 'moving_file') + wf.connect(mask_node, 'out_file', diffeo_node, 'mask_file') + # Compose transform + wf.connect(diffeo_node, 'out_file_xfm', compose_xfm_node, 'in_df') + wf.connect(affine_node, 'out_file_xfm', compose_xfm_node, 'in_aff') + # Apply transform + wf.connect(reslice_node_moving, 'out_file', apply_xfm_node, 'in_file') + wf.connect(compose_xfm_node, 'out_file', apply_xfm_node, 'transform') + # Send to output + wf.connect(apply_xfm_node, 'out_file', outputnode, 'out_file') + wf.connect(compose_xfm_node, 'out_file', outputnode, 'out_file_xfm') + + return wf From 62e34561708bb257762658c52c63b4d8102676f2 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Fri, 13 Apr 2018 13:12:52 -0700 Subject: [PATCH 53/53] added resliced ims to wf output, tweaked registration interface params --- nipype/interfaces/dtitk/registration.py | 3 +-- nipype/interfaces/dtitk/tests/test_auto_Affine.py | 2 +- nipype/interfaces/dtitk/tests/test_auto_AffineTask.py | 2 +- nipype/interfaces/dtitk/tests/test_auto_Rigid.py | 2 +- nipype/interfaces/dtitk/tests/test_auto_RigidTask.py | 2 +- nipype/workflows/dmri/dtitk/tensor_registration.py | 11 ++++++----- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index f97b7a262b..6aa40d4201 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -47,8 +47,7 @@ class RigidInputSpec(CommandLineInputSpec): desc="cost function tolerance", default_value=0.01, usedefault=True) initialize_xfm = File(copyfile=True, desc="Initialize w/DTITK-FORMAT" - "transform ('1' initializes w/existing transform" - "in working directory)", position=5, argstr="%s") + "affine", position=5, argstr="%s", exists=True) class RigidOutputSpec(TraitedSpec): diff --git a/nipype/interfaces/dtitk/tests/test_auto_Affine.py b/nipype/interfaces/dtitk/tests/test_auto_Affine.py index 81c9f688ba..8a80801ba9 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_Affine.py +++ b/nipype/interfaces/dtitk/tests/test_auto_Affine.py @@ -29,7 +29,7 @@ def test_Affine_inputs(): ), initialize_xfm=dict( argstr='%s', - copyfile=False, + copyfile=True, position=5, ), moving_file=dict( diff --git a/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py b/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py index 265867e56e..c7de1d31c8 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py @@ -29,7 +29,7 @@ def test_AffineTask_inputs(): ), initialize_xfm=dict( argstr='%s', - copyfile=False, + copyfile=True, position=5, ), moving_file=dict( diff --git a/nipype/interfaces/dtitk/tests/test_auto_Rigid.py b/nipype/interfaces/dtitk/tests/test_auto_Rigid.py index 6ac4a52c50..8ffc827e61 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_Rigid.py +++ b/nipype/interfaces/dtitk/tests/test_auto_Rigid.py @@ -29,7 +29,7 @@ def test_Rigid_inputs(): ), initialize_xfm=dict( argstr='%s', - copyfile=False, + copyfile=True, position=5, ), moving_file=dict( diff --git a/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py b/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py index af81954f4e..a2747184da 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py @@ -29,7 +29,7 @@ def test_RigidTask_inputs(): ), initialize_xfm=dict( argstr='%s', - copyfile=False, + copyfile=True, position=5, ), moving_file=dict( diff --git a/nipype/workflows/dmri/dtitk/tensor_registration.py b/nipype/workflows/dmri/dtitk/tensor_registration.py index bf376d8556..c4d3d32484 100644 --- a/nipype/workflows/dmri/dtitk/tensor_registration.py +++ b/nipype/workflows/dmri/dtitk/tensor_registration.py @@ -17,8 +17,7 @@ def affine_tensor_pipeline(name='AffTen'): Example ------- - >>> from nipype.workflows.dmri.dtitk.tensor_registration import - affine_tensor_pipeline + >>> from nipype.workflows.dmri.dtitk.tensor_registration import affine_tensor_pipeline >>> affine = affine_tensor_pipeline() >>> affine.inputs.inputnode.fixed_file = 'im1.nii' >>> affine.inputs.inputnode.moving_file = 'im2.nii' @@ -61,8 +60,7 @@ def diffeomorphic_tensor_pipeline(name='DiffeoTen', Example ------- - >>> from nipype.workflows.dmri.dtitk.tensor_registration import - diffeomorphic_tensor_pipeline + >>> from nipype.workflows.dmri.dtitk.tensor_registration import diffeomorphic_tensor_pipeline >>> diffeo = diffeomorphic_tensor_pipeline() >>> diffeo.inputs.inputnode.fixed_file = 'im1.nii' >>> diffeo.inputs.inputnode.moving_file = 'im2.nii' @@ -74,7 +72,8 @@ def diffeomorphic_tensor_pipeline(name='DiffeoTen', fields=['fixed_file', 'moving_file']), name='inputnode') outputnode = pe.Node(niu.IdentityInterface( - fields=['out_file', 'out_file_xfm']), + fields=['out_file', 'out_file_xfm', + 'fixed_resliced', 'moving_resliced']), name='outputnode') reslice_node_pow2 = pe.Node(dtitk.TVResample( @@ -122,5 +121,7 @@ def diffeomorphic_tensor_pipeline(name='DiffeoTen', # Send to output wf.connect(apply_xfm_node, 'out_file', outputnode, 'out_file') wf.connect(compose_xfm_node, 'out_file', outputnode, 'out_file_xfm') + wf.connect(reslice_node_pow2, 'out_file', outputnode, 'fixed_resliced') + wf.connect(reslice_node_moving, 'out_file', outputnode, 'moving_resliced') return wf