@@ -2618,6 +2618,14 @@ class TShiftInputSpec(AFNICommandInputSpec):
26182618 desc = 'time offsets from the volume acquisition onset for each slice' ,
26192619 argstr = '-tpattern @%s' ,
26202620 xor = ['tpattern' ])
2621+ slice_encoding_direction = traits .Enum (
2622+ 'k' , 'k-' ,
2623+ usedefault = True ,
2624+ desc = 'Direction in which slice_timing is specified (default: k). If negative,'
2625+ 'slice_timing is defined in reverse order, that is, the first entry '
2626+ 'corresponds to the slice with the largest index, and the final entry '
2627+ 'corresponds to slice index zero. Only in effect when slice_timing is '
2628+ 'passed as list, not when it is passed as file.' ,)
26212629 rlt = traits .Bool (
26222630 desc = 'Before shifting, remove the mean and linear trend' ,
26232631 argstr = '-rlt' )
@@ -2660,6 +2668,17 @@ class TShift(AFNICommand):
26602668 >>> tshift._list_outputs()['timing_file'] # doctest: +ELLIPSIS
26612669 '.../slice_timing.1D'
26622670
2671+ >>> np.loadtxt(tshift._list_outputs()['timing_file']).tolist()[:5]
2672+ [0.0, 0.4, 0.8, 1.2, 1.6]
2673+
2674+ If ``slice_encoding_direction`` is set to ``'k-'``, the slice timing is reversed:
2675+
2676+ >>> tshift.inputs.slice_encoding_direction = 'k-'
2677+ >>> tshift.cmdline
2678+ '3dTshift -prefix functional_tshift -tpattern @slice_timing.1D -TR 2.5s -tzero 0.0 functional.nii'
2679+ >>> np.loadtxt(tshift._list_outputs()['timing_file']).tolist()[:5]
2680+ [15.6, 15.2, 14.8, 14.4, 14.0]
2681+
26632682 This method creates a ``slice_timing.1D`` file to be passed to ``3dTshift``.
26642683 A pre-existing slice-timing file may be used in the same way:
26652684
@@ -2723,9 +2742,13 @@ def _format_arg(self, name, trait_spec, value):
27232742 return super (TShift , self )._format_arg (name , trait_spec , value )
27242743
27252744 def _write_slice_timing (self ):
2745+ slice_timing = list (self .inputs .slice_timing )
2746+ if self .inputs .slice_encoding_direction .endswith ("-" ):
2747+ slice_timing .reverse ()
2748+
27262749 fname = 'slice_timing.1D'
27272750 with open (fname , 'w' ) as fobj :
2728- fobj .write ('\t ' .join (map (str , self . inputs . slice_timing )))
2751+ fobj .write ('\t ' .join (map (str , slice_timing )))
27292752 return fname
27302753
27312754 def _list_outputs (self ):
0 commit comments