@@ -43,9 +43,12 @@ class WarpTimeSeriesImageMultiTransformInputSpec(ANTSCommandInputSpec):
4343 desc = 'transformation file(s) to be applied' ,
4444 mandatory = True , copyfile = False )
4545 invert_affine = traits .List (traits .Int ,
46- desc = ('List of Affine transformations to invert. '
46+ desc = ('List of Affine transformations to invert.'
4747 'E.g.: [1,4,5] inverts the 1st, 4th, and 5th Affines '
48- 'found in transformation_series' ))
48+ 'found in transformation_series. Note that indexing '
49+ 'starts with 1 and does not include warp fields. Affine '
50+ 'transformations are distinguished '
51+ 'from warp fields by the word "affine" included in their filenames.' ))
4952
5053
5154class WarpTimeSeriesImageMultiTransformOutputSpec (TraitedSpec ):
@@ -67,6 +70,14 @@ class WarpTimeSeriesImageMultiTransform(ANTSCommand):
6770 'WarpTimeSeriesImageMultiTransform 4 resting.nii resting_wtsimt.nii -R ants_deformed.nii.gz ants_Warp.nii.gz \
6871 ants_Affine.txt'
6972
73+ >>> wtsimt = WarpTimeSeriesImageMultiTransform()
74+ >>> wtsimt.inputs.input_image = 'resting.nii'
75+ >>> wtsimt.inputs.reference_image = 'ants_deformed.nii.gz'
76+ >>> wtsimt.inputs.transformation_series = ['ants_Warp.nii.gz','ants_Affine.txt']
77+ >>> wtsimt.inputs.invert_affine = [1] # # this will invert the 1st Affine file: ants_Affine.txt
78+ >>> wtsimt.cmdline # doctest: +ALLOW_UNICODE
79+ 'WarpTimeSeriesImageMultiTransform 4 resting.nii resting_wtsimt.nii -R ants_deformed.nii.gz ants_Warp.nii.gz \
80+ -i ants_Affine.txt'
7081 """
7182
7283 _cmd = 'WarpTimeSeriesImageMultiTransform'
@@ -81,13 +92,22 @@ def _format_arg(self, opt, spec, val):
8192 if opt == 'transformation_series' :
8293 series = []
8394 affine_counter = 0
95+ affine_invert = []
8496 for transformation in val :
8597 if 'Affine' in transformation and \
8698 isdefined (self .inputs .invert_affine ):
8799 affine_counter += 1
88100 if affine_counter in self .inputs .invert_affine :
89101 series += ['-i' ]
102+ affine_invert .append (affine_counter )
90103 series += [transformation ]
104+
105+ if isdefined (self .inputs .invert_affine ):
106+ diff_inv = set (self .inputs .invert_affine ) - set (affine_invert )
107+ if diff_inv :
108+ raise Exceptions ("Review invert_affine, not all indexes from invert_affine were used, "
109+ "check the description for the full definition" )
110+
91111 return ' ' .join (series )
92112 return super (WarpTimeSeriesImageMultiTransform , self )._format_arg (opt , spec , val )
93113
@@ -168,7 +188,7 @@ class WarpImageMultiTransform(ANTSCommand):
168188 >>> wimt.inputs.reference_image = 'functional.nii'
169189 >>> wimt.inputs.transformation_series = ['func2anat_coreg_Affine.txt','func2anat_InverseWarp.nii.gz', \
170190 'dwi2anat_Warp.nii.gz','dwi2anat_coreg_Affine.txt']
171- >>> wimt.inputs.invert_affine = [1]
191+ >>> wimt.inputs.invert_affine = [1] # this will invert the 1st Affine file: 'func2anat_coreg_Affine.txt'
172192 >>> wimt.cmdline # doctest: +ALLOW_UNICODE
173193 'WarpImageMultiTransform 3 diffusion_weighted.nii diffusion_weighted_wimt.nii -R functional.nii \
174194 -i func2anat_coreg_Affine.txt func2anat_InverseWarp.nii.gz dwi2anat_Warp.nii.gz dwi2anat_coreg_Affine.txt'
@@ -190,14 +210,24 @@ def _format_arg(self, opt, spec, val):
190210 if opt == 'transformation_series' :
191211 series = []
192212 affine_counter = 0
213+ affine_invert = []
193214 for transformation in val :
194215 if "affine" in transformation .lower () and \
195216 isdefined (self .inputs .invert_affine ):
196217 affine_counter += 1
197218 if affine_counter in self .inputs .invert_affine :
198219 series += ['-i' ]
220+ affine_invert .append (affine_counter )
199221 series += [transformation ]
222+
223+ if isdefined (self .inputs .invert_affine ):
224+ diff_inv = set (self .inputs .invert_affine ) - set (affine_invert )
225+ if diff_inv :
226+ raise Exceptions ("Review invert_affine, not all indexes from invert_affine were used, "
227+ "check the description for the full definition" )
228+
200229 return ' ' .join (series )
230+
201231 return super (WarpImageMultiTransform , self )._format_arg (opt , spec , val )
202232
203233 def _list_outputs (self ):
0 commit comments