Skip to content

ENH: Flesh out ConcatenateLTA #2215

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

Merged
merged 1 commit into from
Oct 6, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 58 additions & 12 deletions nipype/interfaces/freesurfer/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -2382,13 +2382,38 @@ def _list_outputs(self):
class ConcatenateLTAInputSpec(FSTraitedSpec):
# required
in_lta1 = File(exists=True, mandatory=True, argstr='%s', position=-3,
desc="maps some src1 to dst1")
in_lta2 = File(exists=True, mandatory=True, argstr='%s', position=-2,
desc="maps dst1(src2) to dst2")
out_file = File(exists=False, position=-1, argstr='%s',
name_source=['in_lta1'], name_template='%s-long',
hash_files=False, keep_extension=True,
desc="the combined LTA maps: src1 to dst2 = LTA2*LTA1")
desc='maps some src1 to dst1')
in_lta2 = traits.Either(
File(exists=True), 'identity.nofile', argstr='%s', position=-2,
mandatory=True, desc='maps dst1(src2) to dst2')
out_file = File(
'concat.lta', usedefault=True, position=-1, argstr='%s',
hash_files=False,
desc='the combined LTA maps: src1 to dst2 = LTA2*LTA1')

# Inversion and transform type
invert_1 = traits.Bool(argstr='-invert1',
desc='invert in_lta1 before applying it')
invert_2 = traits.Bool(argstr='-invert2',
desc='invert in_lta2 before applying it')
invert_out = traits.Bool(argstr='-invertout',
desc='invert output LTA')
out_type = traits.Enum('VOX2VOX', 'RAS2RAS', argstr='-out_type %d',
desc='set final LTA type')

# Talairach options
tal_source_file = traits.File(
exists=True, argstr='-tal %s', position=-5,
requires=['tal_template_file'],
desc='if in_lta2 is talairach.xfm, specify source for talairach')
tal_template_file = traits.File(
exists=True, argstr='%s', position=-4, requires=['tal_source_file'],
desc='if in_lta2 is talairach.xfm, specify template for talairach')

subject = traits.Str(argstr='-subject %s',
desc='set subject in output LTA')
# Note rmsdiff would be xor out_file, and would be most easily dealt with
# in a new interface. -CJM 2017.10.05


class ConcatenateLTAOutputSpec(TraitedSpec):
Expand All @@ -2397,23 +2422,44 @@ class ConcatenateLTAOutputSpec(TraitedSpec):


class ConcatenateLTA(FSCommand):
"""concatenates two consecutive LTA transformations
into one overall transformation, Out = LTA2*LTA1
""" Concatenates two consecutive LTA transformations into one overall
transformation

Out = LTA2*LTA1

Examples
--------
>>> from nipype.interfaces.freesurfer import ConcatenateLTA
>>> conc_lta = ConcatenateLTA()
>>> conc_lta.inputs.in_lta1 = 'trans.mat'
>>> conc_lta.inputs.in_lta2 = 'trans.mat'
>>> conc_lta.inputs.in_lta1 = 'lta1.lta'
>>> conc_lta.inputs.in_lta2 = 'lta2.lta'
>>> conc_lta.cmdline # doctest: +ALLOW_UNICODE
'mri_concatenate_lta lta1.lta lta2.lta concat.lta'

You can use 'identity.nofile' as the filename for in_lta2, e.g.:

>>> conc_lta.inputs.in_lta2 = 'identity.nofile'
>>> conc_lta.inputs.invert_1 = True
>>> conc_lta.inputs.out_file = 'inv1.lta'
>>> conc_lta.cmdline # doctest: +ALLOW_UNICODE
'mri_concatenate_lta trans.mat trans.mat trans-long.mat'
'mri_concatenate_lta -invert1 lta1.lta identity.nofile inv1.lta'

To create a RAS2RAS transform:

>>> conc_lta.inputs.out_type = 'RAS2RAS'
>>> conc_lta.cmdline # doctest: +ALLOW_UNICODE
'mri_concatenate_lta -invert1 -out_type 1 lta1.lta identity.nofile inv1.lta'
"""

_cmd = 'mri_concatenate_lta'
input_spec = ConcatenateLTAInputSpec
output_spec = ConcatenateLTAOutputSpec

def _format_arg(self, name, spec, value):
if name == 'out_type':
value = {'VOX2VOX': 0, 'RAS2RAS': 1}[value]
return super(ConcatenateLTA, self)._format_arg(name, spec, value)

def _list_outputs(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps this can be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing something else would be needed to change? Removing _list_outputs gets me with an <undefined> outputs.out_file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name_source in outputspec

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not able to figure out how to use name_source. Has no effect I can see in output spec, and trying to follow the examples in the docs results in failing to generate a string for inputs.out_file and the interface fails.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind - the logic i had in mind is only implemented if name_source is in the input trait. i think the next refactor needs to take care of filename generation

outputs = self.output_spec().get()
outputs['out_file'] = os.path.abspath(self.inputs.out_file)
Expand Down
22 changes: 19 additions & 3 deletions nipype/interfaces/freesurfer/tests/test_auto_ConcatenateLTA.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,30 @@ def test_ConcatenateLTA_inputs():
mandatory=True,
position=-2,
),
invert_1=dict(argstr='-invert1',
),
invert_2=dict(argstr='-invert2',
),
invert_out=dict(argstr='-invertout',
),
out_file=dict(argstr='%s',
hash_files=False,
keep_extension=True,
name_source=['in_lta1'],
name_template='%s-long',
position=-1,
usedefault=True,
),
out_type=dict(argstr='-out_type %d',
),
subject=dict(argstr='-subject %s',
),
subjects_dir=dict(),
tal_source_file=dict(argstr='-tal %s',
position=-5,
requires=['tal_template_file'],
),
tal_template_file=dict(argstr='%s',
position=-4,
requires=['tal_source_file'],
),
terminal_output=dict(deprecated='1.0.0',
nohash=True,
),
Expand Down
Empty file added nipype/testing/data/lta1.lta
Empty file.
Empty file added nipype/testing/data/lta2.lta
Empty file.