Skip to content

Commit f1d690c

Browse files
authored
Merge pull request #2261 from djarecka/ants2245
changing ANTS input traits, fixes #2245
2 parents 10a0a41 + 51585be commit f1d690c

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

nipype/interfaces/ants/registration.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# -*- coding: utf-8 -*-
2-
"""The ants module provides basic functions for interfacing with ants functions.
2+
"""The ants module provides basic functions for interfacing with ants
3+
functions.
34
45
Change directory to provide relative paths for doctests
56
>>> import os
67
>>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
78
>>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data'))
89
>>> os.chdir(datadir)
910
"""
10-
from __future__ import print_function, division, unicode_literals, absolute_import
11+
from __future__ import (print_function, division, unicode_literals,
12+
absolute_import)
1113
from builtins import range, str
1214
import os
1315

@@ -20,17 +22,19 @@ class ANTSInputSpec(ANTSCommandInputSpec):
2022
dimension = traits.Enum(3, 2, argstr='%d', usedefault=False,
2123
position=1, desc='image dimension (2 or 3)')
2224
fixed_image = InputMultiPath(File(exists=True), mandatory=True,
23-
desc=('image to which the moving image is warped'))
25+
desc=('image to which the moving image is '
26+
'warped'))
2427
moving_image = InputMultiPath(File(exists=True), argstr='%s',
2528
mandatory=True,
26-
desc=('image to apply transformation to (generally a coregistered '
29+
desc=('image to apply transformation to '
30+
'(generally a coregistered'
2731
'functional)'))
2832

2933
# Not all metrics are appropriate for all modalities. Also, not all metrics
30-
# are efficeint or appropriate at all resolution levels, Some metrics perform
31-
# well for gross global registraiton, but do poorly for small changes (i.e.
32-
# Mattes), and some metrics do well for small changes but don't work well for
33-
# gross level changes (i.e. 'CC').
34+
# are efficeint or appropriate at all resolution levels, Some metrics
35+
# perform well for gross global registraiton, but do poorly for small
36+
# changes (i.e. Mattes), and some metrics do well for small changes but
37+
# don't work well for gross level changes (i.e. 'CC').
3438
#
3539
# This is a two stage registration. in the first stage
3640
# [ 'Mattes', .................]
@@ -49,10 +53,18 @@ class ANTSInputSpec(ANTSCommandInputSpec):
4953
metric = traits.List(traits.Enum('CC', 'MI', 'SMI', 'PR', 'SSD',
5054
'MSQ', 'PSE'), mandatory=True, desc='')
5155

52-
metric_weight = traits.List(traits.Float(), requires=['metric'], desc='')
53-
radius = traits.List(traits.Int(), requires=['metric'], desc='')
56+
metric_weight = traits.List(traits.Float(), value=[1.0], usedefault=True,
57+
requires=['metric'], mandatory=True,
58+
desc='the metric weight(s) for each stage. '
59+
'The weights must sum to 1 per stage.')
5460

55-
output_transform_prefix = Str('out', usedefault=True, argstr='--output-naming %s',
61+
radius = traits.List(traits.Int(), requires=['metric'], mandatory=True,
62+
desc='radius of the region (i.e. number of layers'
63+
' around a voxel point)'
64+
' that is used for computing cross correlation')
65+
66+
output_transform_prefix = Str('out', usedefault=True,
67+
argstr='--output-naming %s',
5668
mandatory=True, desc='')
5769
transformation_model = traits.Enum('Diff', 'Elast', 'Exp', 'Greedy Exp',
5870
'SyN', argstr='%s', mandatory=True,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
2+
# vi: set ft=python sts=4 ts=4 sw=4 et:
3+
from __future__ import unicode_literals
4+
from nipype.interfaces.ants import registration
5+
import os
6+
import pytest
7+
8+
9+
def test_ants_mand(tmpdir):
10+
tmpdir.chdir()
11+
filepath = os.path.dirname(os.path.realpath(__file__))
12+
datadir = os.path.realpath(os.path.join(filepath, '../../../testing/data'))
13+
14+
ants = registration.ANTS()
15+
ants.inputs.transformation_model = "SyN"
16+
ants.inputs.moving_image = [os.path.join(datadir, 'resting.nii')]
17+
ants.inputs.fixed_image = [os.path.join(datadir, 'T1.nii')]
18+
ants.inputs.metric = ['MI']
19+
20+
with pytest.raises(ValueError) as er:
21+
ants.run()
22+
assert "ANTS requires a value for input 'radius'" in str(er.value)

0 commit comments

Comments
 (0)