Skip to content

Commit 1ef1821

Browse files
committed
add option to save transform
1 parent 6c00f85 commit 1ef1821

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

nipype/interfaces/afni/preprocess.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,7 +2758,8 @@ class WarpInputSpec(AFNICommandInputSpec):
27582758
name_template='%s_warp',
27592759
desc='output image file name',
27602760
argstr='-prefix %s',
2761-
name_source='in_file')
2761+
name_source='in_file',
2762+
keep_extension=True)
27622763
tta2mni = traits.Bool(
27632764
desc='transform dataset from Talairach to MNI152', argstr='-tta2mni')
27642765
mni2tta = traits.Bool(
@@ -2789,6 +2790,13 @@ class WarpInputSpec(AFNICommandInputSpec):
27892790
argstr='-zpad %d')
27902791
verbose = traits.Bool(
27912792
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')
27922800

27932801

27942802
class Warp(AFNICommand):
@@ -2820,7 +2828,48 @@ class Warp(AFNICommand):
28202828
"""
28212829
_cmd = '3dWarp'
28222830
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
28242873

28252874

28262875
class QwarpPlusMinusInputSpec(CommandLineInputSpec):

0 commit comments

Comments
 (0)