Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Allow transform to be saved from AFNI 3dWarp #2642

Merged
merged 3 commits into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 30 additions & 4 deletions nipype/interfaces/afni/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ...utils.filemanip import (load_json, save_json, split_filename,
fname_presuffix)
from ..base import (CommandLineInputSpec, CommandLine, TraitedSpec, traits,
isdefined, File, InputMultiPath, Undefined, Str,
isdefined, File, InputMultiPath, Undefined, Str,
InputMultiObject)

from .base import (AFNICommandBase, AFNICommand, AFNICommandInputSpec,
Expand Down Expand Up @@ -2563,7 +2563,7 @@ class TProject(AFNICommand):
_cmd = '3dTproject'
input_spec = TProjectInputSpec
output_spec = AFNICommandOutputSpec


class TShiftInputSpec(AFNICommandInputSpec):
in_file = File(
Expand Down Expand Up @@ -2758,7 +2758,8 @@ class WarpInputSpec(AFNICommandInputSpec):
name_template='%s_warp',
desc='output image file name',
argstr='-prefix %s',
name_source='in_file')
name_source='in_file',
keep_extension=True)
tta2mni = traits.Bool(
desc='transform dataset from Talairach to MNI152', argstr='-tta2mni')
mni2tta = traits.Bool(
Expand Down Expand Up @@ -2789,6 +2790,13 @@ class WarpInputSpec(AFNICommandInputSpec):
argstr='-zpad %d')
verbose = traits.Bool(
desc='Print out some information along the way.', argstr='-verb')
save_warp = traits.Bool(
desc='save warp as .mat file', requires=['verbose'])


class WarpOutputSpec(TraitedSpec):
out_file = File(desc='Warped file.', exists=True)
warp_file = File(desc='warp transform .mat file')


class Warp(AFNICommand):
Expand Down Expand Up @@ -2820,7 +2828,25 @@ class Warp(AFNICommand):
"""
_cmd = '3dWarp'
input_spec = WarpInputSpec
output_spec = AFNICommandOutputSpec
output_spec = WarpOutputSpec

def _run_interface(self, runtime):
runtime = super(Warp, self)._run_interface(runtime)

if self.inputs.save_warp:
import numpy as np
warp_file = self._list_outputs()['warp_file']
np.savetxt(warp_file, [runtime.stdout], fmt=str('%s'))
return runtime

def _list_outputs(self):
outputs = super(Warp, self)._list_outputs()
if self.inputs.save_warp:
outputs['warp_file'] = fname_presuffix(outputs['out_file'],
suffix='_transform.mat',
use_ext=False)

return outputs


class QwarpPlusMinusInputSpec(CommandLineInputSpec):
Expand Down
7 changes: 6 additions & 1 deletion nipype/interfaces/afni/tests/test_auto_Warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ def test_Warp_inputs():
oblique_parent=dict(argstr='-oblique_parent %s', ),
out_file=dict(
argstr='-prefix %s',
keep_extension=True,
name_source='in_file',
name_template='%s_warp',
),
outputtype=dict(),
save_warp=dict(requires=['verbose'], ),
tta2mni=dict(argstr='-tta2mni', ),
verbose=dict(argstr='-verb', ),
zpad=dict(argstr='-zpad %d', ),
Expand All @@ -43,7 +45,10 @@ def test_Warp_inputs():
for metakey, value in list(metadata.items()):
assert getattr(inputs.traits()[key], metakey) == value
def test_Warp_outputs():
output_map = dict(out_file=dict(), )
output_map = dict(
out_file=dict(),
warp_file=dict(),
)
outputs = Warp.output_spec()

for key, metadata in list(output_map.items()):
Expand Down