@@ -2618,6 +2618,14 @@ class TShiftInputSpec(AFNICommandInputSpec):
2618
2618
desc = 'time offsets from the volume acquisition onset for each slice' ,
2619
2619
argstr = '-tpattern @%s' ,
2620
2620
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.' ,)
2621
2629
rlt = traits .Bool (
2622
2630
desc = 'Before shifting, remove the mean and linear trend' ,
2623
2631
argstr = '-rlt' )
@@ -2660,6 +2668,17 @@ class TShift(AFNICommand):
2660
2668
>>> tshift._list_outputs()['timing_file'] # doctest: +ELLIPSIS
2661
2669
'.../slice_timing.1D'
2662
2670
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
+
2663
2682
This method creates a ``slice_timing.1D`` file to be passed to ``3dTshift``.
2664
2683
A pre-existing slice-timing file may be used in the same way:
2665
2684
@@ -2723,9 +2742,13 @@ def _format_arg(self, name, trait_spec, value):
2723
2742
return super (TShift , self )._format_arg (name , trait_spec , value )
2724
2743
2725
2744
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
+
2726
2749
fname = 'slice_timing.1D'
2727
2750
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 )))
2729
2752
return fname
2730
2753
2731
2754
def _list_outputs (self ):
0 commit comments