@@ -2758,7 +2758,8 @@ class WarpInputSpec(AFNICommandInputSpec):
2758
2758
name_template = '%s_warp' ,
2759
2759
desc = 'output image file name' ,
2760
2760
argstr = '-prefix %s' ,
2761
- name_source = 'in_file' )
2761
+ name_source = 'in_file' ,
2762
+ keep_extension = True )
2762
2763
tta2mni = traits .Bool (
2763
2764
desc = 'transform dataset from Talairach to MNI152' , argstr = '-tta2mni' )
2764
2765
mni2tta = traits .Bool (
@@ -2789,6 +2790,13 @@ class WarpInputSpec(AFNICommandInputSpec):
2789
2790
argstr = '-zpad %d' )
2790
2791
verbose = traits .Bool (
2791
2792
desc = 'Print out some information along the way.' , argstr = '-verb' )
2793
+ save_warp = traits .Bool (
2794
+ False , usedefault = True , desc = 'save warp as .mat file' )
2795
+
2796
+
2797
+ class WarpOutputSpec (TraitedSpec ):
2798
+ out_file = File (desc = 'Warped file.' , exists = True )
2799
+ warp_file = File (desc = 'warp transfrom .mat file' )
2792
2800
2793
2801
2794
2802
class Warp (AFNICommand ):
@@ -2820,7 +2828,48 @@ class Warp(AFNICommand):
2820
2828
"""
2821
2829
_cmd = '3dWarp'
2822
2830
input_spec = WarpInputSpec
2823
- output_spec = AFNICommandOutputSpec
2831
+ output_spec = WarpOutputSpec
2832
+
2833
+ def _run_interface (self , runtime ):
2834
+ runtime = super (Warp , self )._run_interface (runtime )
2835
+
2836
+ if self .inputs .save_warp :
2837
+ import numpy as np
2838
+ if not self .inputs .out_file :
2839
+ warp_file = fname_presuffix (self .inputs .in_file ,
2840
+ suffix = '_warp_transform.mat' ,
2841
+ use_ext = False )
2842
+ else :
2843
+ warp_file = fname_presuffix (self .inputs .out_file ,
2844
+ suffix = '_transform.mat' ,
2845
+ use_ext = False )
2846
+ np .savetxt (warp_file , [runtime .stdout ], fmt = str ('%s' ))
2847
+ return runtime
2848
+
2849
+ def _list_outputs (self ):
2850
+ outputs = self .output_spec ().get ()
2851
+ if not self .inputs .out_file :
2852
+ fname , ext = os .path .splitext (self .inputs .in_file )
2853
+ if '.gz' in ext :
2854
+ _ , ext2 = os .path .splitext (fname )
2855
+ ext = ext2 + ext
2856
+ out_file = self ._gen_fname (self .inputs .in_file , suffix = '_warp' ,
2857
+ ext = ext )
2858
+ outputs ['out_file' ] = os .path .abspath (out_file )
2859
+ if self .inputs .save_warp :
2860
+ warp_file = fname_presuffix (self .inputs .in_file ,
2861
+ suffix = '_warp_transform.mat' ,
2862
+ use_ext = False )
2863
+ outputs ['warp_file' ] = os .path .abspath (warp_file )
2864
+ else :
2865
+ outputs ['out_file' ] = os .path .abspath (self .inputs .out_file )
2866
+ if self .inputs .save_warp :
2867
+ warp_file = fname_presuffix (self .inputs .out_file ,
2868
+ suffix = '_transform.mat' ,
2869
+ use_ext = False )
2870
+ outputs ['warp_file' ] = os .path .abspath (warp_file )
2871
+
2872
+ return outputs
2824
2873
2825
2874
2826
2875
class QwarpPlusMinusInputSpec (CommandLineInputSpec ):
0 commit comments