Skip to content

Commit 1bcf9d1

Browse files
committed
ENH: Flesh out ConcatenateLTA
1 parent 2b10ff2 commit 1bcf9d1

File tree

4 files changed

+77
-15
lines changed

4 files changed

+77
-15
lines changed

nipype/interfaces/freesurfer/preprocess.py

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,13 +2382,38 @@ def _list_outputs(self):
23822382
class ConcatenateLTAInputSpec(FSTraitedSpec):
23832383
# required
23842384
in_lta1 = File(exists=True, mandatory=True, argstr='%s', position=-3,
2385-
desc="maps some src1 to dst1")
2386-
in_lta2 = File(exists=True, mandatory=True, argstr='%s', position=-2,
2387-
desc="maps dst1(src2) to dst2")
2388-
out_file = File(exists=False, position=-1, argstr='%s',
2389-
name_source=['in_lta1'], name_template='%s-long',
2390-
hash_files=False, keep_extension=True,
2391-
desc="the combined LTA maps: src1 to dst2 = LTA2*LTA1")
2385+
desc='maps some src1 to dst1')
2386+
in_lta2 = traits.Either(
2387+
File(exists=True), 'identity.nofile', argstr='%s', position=-2,
2388+
mandatory=True, desc='maps dst1(src2) to dst2')
2389+
out_file = File(
2390+
'concat.lta', usedefault=True, position=-1, argstr='%s',
2391+
hash_files=False,
2392+
desc='the combined LTA maps: src1 to dst2 = LTA2*LTA1')
2393+
2394+
# Inversion and transform type
2395+
invert_1 = traits.Bool(argstr='-invert1',
2396+
desc='invert in_lta1 before applying it')
2397+
invert_2 = traits.Bool(argstr='-invert2',
2398+
desc='invert in_lta2 before applying it')
2399+
invert_out = traits.Bool(argstr='-invertout',
2400+
desc='invert output LTA')
2401+
out_type = traits.Enum('VOX2VOX', 'RAS2RAS', argstr='-out_type %d',
2402+
desc='set final LTA type')
2403+
2404+
# Talairach options
2405+
tal_source_file = traits.File(
2406+
exists=True, argstr='-tal %s', position=-5,
2407+
requires=['tal_template_file'],
2408+
desc='if in_lta2 is talairach.xfm, specify source for talairach')
2409+
tal_template_file = traits.File(
2410+
exists=True, argstr='%s', position=-4, requires=['tal_source_file'],
2411+
desc='if in_lta2 is talairach.xfm, specify template for talairach')
2412+
2413+
subject = traits.Str(argstr='-subject %s',
2414+
desc='set subject in output LTA')
2415+
# Note rmsdiff would be xor out_file, and would be most easily dealt with
2416+
# in a new interface. -CJM 2017.10.05
23922417

23932418

23942419
class ConcatenateLTAOutputSpec(TraitedSpec):
@@ -2397,23 +2422,44 @@ class ConcatenateLTAOutputSpec(TraitedSpec):
23972422

23982423

23992424
class ConcatenateLTA(FSCommand):
2400-
"""concatenates two consecutive LTA transformations
2401-
into one overall transformation, Out = LTA2*LTA1
2425+
""" Concatenates two consecutive LTA transformations into one overall
2426+
transformation
2427+
2428+
Out = LTA2*LTA1
24022429
24032430
Examples
24042431
--------
24052432
>>> from nipype.interfaces.freesurfer import ConcatenateLTA
24062433
>>> conc_lta = ConcatenateLTA()
2407-
>>> conc_lta.inputs.in_lta1 = 'trans.mat'
2408-
>>> conc_lta.inputs.in_lta2 = 'trans.mat'
2434+
>>> conc_lta.inputs.in_lta1 = 'lta1.lta'
2435+
>>> conc_lta.inputs.in_lta2 = 'lta2.lta'
2436+
>>> conc_lta.cmdline # doctest: +ALLOW_UNICODE
2437+
'mri_concatenate_lta lta1.lta lta2.lta concat.lta'
2438+
2439+
You can use 'identity.nofile' as the filename for in_lta2, e.g.:
2440+
2441+
>>> conc_lta.inputs.in_lta2 = 'identity.nofile'
2442+
>>> conc_lta.inputs.invert_1 = True
2443+
>>> conc_lta.inputs.out_file = 'inv1.lta'
24092444
>>> conc_lta.cmdline # doctest: +ALLOW_UNICODE
2410-
'mri_concatenate_lta trans.mat trans.mat trans-long.mat'
2445+
'mri_concatenate_lta -invert1 lta1.lta identity.nofile inv1.lta'
2446+
2447+
To create a RAS2RAS transform:
2448+
2449+
>>> conc_lta.inputs.out_type = 'RAS2RAS'
2450+
>>> conc_lta.cmdline # doctest: +ALLOW_UNICODE
2451+
'mri_concatenate_lta -invert1 -out_type 1 lta1.lta identity.nofile inv1.lta'
24112452
"""
24122453

24132454
_cmd = 'mri_concatenate_lta'
24142455
input_spec = ConcatenateLTAInputSpec
24152456
output_spec = ConcatenateLTAOutputSpec
24162457

2458+
def _format_arg(self, name, spec, value):
2459+
if name == 'out_type':
2460+
value = {'VOX2VOX': 0, 'RAS2RAS': 1}[value]
2461+
return super(ConcatenateLTA, self)._format_arg(name, spec, value)
2462+
24172463
def _list_outputs(self):
24182464
outputs = self.output_spec().get()
24192465
outputs['out_file'] = os.path.abspath(self.inputs.out_file)

nipype/interfaces/freesurfer/tests/test_auto_ConcatenateLTA.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,30 @@ def test_ConcatenateLTA_inputs():
2020
mandatory=True,
2121
position=-2,
2222
),
23+
invert_1=dict(argstr='-invert1',
24+
),
25+
invert_2=dict(argstr='-invert2',
26+
),
27+
invert_out=dict(argstr='-invertout',
28+
),
2329
out_file=dict(argstr='%s',
2430
hash_files=False,
25-
keep_extension=True,
26-
name_source=['in_lta1'],
27-
name_template='%s-long',
2831
position=-1,
32+
usedefault=True,
33+
),
34+
out_type=dict(argstr='-out_type %d',
35+
),
36+
subject=dict(argstr='-subject %s',
2937
),
3038
subjects_dir=dict(),
39+
tal_source_file=dict(argstr='-tal %s',
40+
position=-5,
41+
requires=['tal_template_file'],
42+
),
43+
tal_template_file=dict(argstr='%s',
44+
position=-4,
45+
requires=['tal_source_file'],
46+
),
3147
terminal_output=dict(deprecated='1.0.0',
3248
nohash=True,
3349
),

nipype/testing/data/lta1.lta

Whitespace-only changes.

nipype/testing/data/lta2.lta

Whitespace-only changes.

0 commit comments

Comments
 (0)