Skip to content
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
14 changes: 10 additions & 4 deletions nipype/interfaces/fsl/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,9 @@ class FLIRTInputSpec(FSLCommandInputSpec):
name_template='%s_flirt.log', desc='output log')
in_matrix_file = File(argstr='-init %s', desc='input 4x4 affine matrix')
apply_xfm = traits.Bool(
argstr='-applyxfm', requires=['in_matrix_file'],
desc='apply transformation supplied by in_matrix_file')
argstr='-applyxfm',
desc=('apply transformation supplied by in_matrix_file or uses_qform to'
' use the affine matrix stored in the reference header'))
apply_isoxfm = traits.Float(
argstr='-applyisoxfm %f', xor=['apply_xfm'],
desc='as applyxfm but forces isotropic resampling')
Expand Down Expand Up @@ -561,13 +562,18 @@ def _parse_inputs(self, skip=None):
if isdefined(self.inputs.save_log) and self.inputs.save_log:
if not isdefined(self.inputs.verbose) or self.inputs.verbose == 0:
self.inputs.verbose = 1
if isdefined(self.inputs.apply_xfm) and self.inputs.apply_xfm:
if not self.inputs.in_matrix_file and not self.inputs.uses_qform:
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be if not isdefined(self.inputs.in_matrix_file) and not (isdefined(self.inputs.uses_qform) and not self.inputs.uses_qform)

Copy link
Member Author

Choose a reason for hiding this comment

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

is isdefined necessary in this case? I added a test for both cases of using apply_xfm

Copy link
Member

Choose a reason for hiding this comment

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

what if someone sets them to Undefined

In [1]: from traits.api import Undefined

In [2]: not Undefined
Out[2]: False

Copy link
Member

@satra satra Mar 17, 2017

Choose a reason for hiding this comment

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

however the check with not appears to work now

Copy link
Member

Choose a reason for hiding this comment

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

In [20]: foo.inputs.wmnorms = Undefined

In [21]: not foo.inputs.wmnorms
Out[21]: True

haven't figured out why yet

Copy link
Member Author

Choose a reason for hiding this comment

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

@satra should this be changed?

raise RuntimeError('Argument apply_xfm requires in_matrix_file '
'or uses_qform arguments to run')
skip.append('save_log')
return super(FLIRT, self)._parse_inputs(skip=skip)

class ApplyXFMInputSpec(FLIRTInputSpec):
apply_xfm = traits.Bool(
True, argstr='-applyxfm', requires=['in_matrix_file'],
desc='apply transformation supplied by in_matrix_file',
True, argstr='-applyxfm',
desc=('apply transformation supplied by in_matrix_file or uses_qform to'
' use the affine matrix stored in the reference header'),
usedefault=True)


Expand Down
1 change: 0 additions & 1 deletion nipype/interfaces/fsl/tests/test_auto_ApplyXFM.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def test_ApplyXFM_inputs():
xor=['apply_xfm'],
),
apply_xfm=dict(argstr='-applyxfm',
requires=['in_matrix_file'],
usedefault=True,
),
args=dict(argstr='%s',
Expand Down
164 changes: 0 additions & 164 deletions nipype/interfaces/fsl/tests/test_auto_ApplyXfm.py

This file was deleted.

1 change: 0 additions & 1 deletion nipype/interfaces/fsl/tests/test_auto_FLIRT.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def test_FLIRT_inputs():
xor=['apply_xfm'],
),
apply_xfm=dict(argstr='-applyxfm',
requires=['in_matrix_file'],
),
args=dict(argstr='%s',
),
Expand Down
20 changes: 18 additions & 2 deletions nipype/interfaces/fsl/tests/test_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import os
import tempfile
from copy import deepcopy

import pytest
from nipype.utils.filemanip import split_filename, filename_to_list
Expand Down Expand Up @@ -220,12 +221,13 @@ def test_flirt(setup_flirt):
flirter = fsl.FLIRT()
# infile not specified
with pytest.raises(ValueError):
flirter.run()
flirter.cmdline
flirter.inputs.in_file = infile
# reference not specified
with pytest.raises(ValueError):
flirter.run()
flirter.cmdline
flirter.inputs.reference = reffile

# Generate outfile and outmatrix
pth, fname, ext = split_filename(infile)
outfile = fsl_name(flirter, '%s_flirt' % fname)
Expand All @@ -234,6 +236,20 @@ def test_flirt(setup_flirt):
outfile, outmat)
assert flirter.cmdline == realcmd

# test apply_xfm option
axfm = deepcopy(flirter)
axfm.inputs.apply_xfm = True
# in_matrix_file or uses_qform must be defined
with pytest.raises(RuntimeError): axfm.cmdline
axfm2 = deepcopy(axfm)
# test uses_qform
axfm.inputs.uses_qform = True
assert axfm.cmdline == (realcmd + ' -applyxfm -usesqform')
# test in_matrix_file
axfm2.inputs.in_matrix_file = reffile
assert axfm2.cmdline == (realcmd + ' -applyxfm -init %s' % reffile)


_, tmpfile = tempfile.mkstemp(suffix='.nii', dir=tmpdir)
# Loop over all inputs, set a reasonable value and make sure the
# cmdline is updated correctly.
Expand Down