Skip to content

changing ANTS input traits, fixes #2245 #2261

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 5 commits into from
Nov 28, 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
34 changes: 23 additions & 11 deletions nipype/interfaces/ants/registration.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# -*- coding: utf-8 -*-
"""The ants module provides basic functions for interfacing with ants functions.
"""The ants module provides basic functions for interfacing with ants
functions.

Change directory to provide relative paths for doctests
>>> import os
>>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
>>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data'))
>>> os.chdir(datadir)
"""
from __future__ import print_function, division, unicode_literals, absolute_import
from __future__ import (print_function, division, unicode_literals,
absolute_import)
from builtins import range, str
import os

Expand All @@ -20,17 +22,19 @@ class ANTSInputSpec(ANTSCommandInputSpec):
dimension = traits.Enum(3, 2, argstr='%d', usedefault=False,
position=1, desc='image dimension (2 or 3)')
fixed_image = InputMultiPath(File(exists=True), mandatory=True,
desc=('image to which the moving image is warped'))
desc=('image to which the moving image is '
'warped'))
moving_image = InputMultiPath(File(exists=True), argstr='%s',
mandatory=True,
desc=('image to apply transformation to (generally a coregistered '
desc=('image to apply transformation to '
'(generally a coregistered'
'functional)'))

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

metric_weight = traits.List(traits.Float(), requires=['metric'], desc='')
radius = traits.List(traits.Int(), requires=['metric'], desc='')
metric_weight = traits.List(traits.Float(), value=[1.0], usedefault=True,
requires=['metric'], mandatory=True,
desc='the metric weight(s) for each stage. '
'The weights must sum to 1 per stage.')
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this a pep8 warning?

Copy link
Collaborator Author

@djarecka djarecka Nov 27, 2017

Choose a reason for hiding this comment

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

this line doesn't give any warning, but the files indeed violates many. will edit

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will actually review pep8 only for the first part I was changing, will review pep8 for entire file together with other updates


output_transform_prefix = Str('out', usedefault=True, argstr='--output-naming %s',
radius = traits.List(traits.Int(), requires=['metric'], mandatory=True,
desc='radius of the region (i.e. number of layers'
' around a voxel point)'
' that is used for computing cross correlation')

output_transform_prefix = Str('out', usedefault=True,
argstr='--output-naming %s',
mandatory=True, desc='')
transformation_model = traits.Enum('Diff', 'Elast', 'Exp', 'Greedy Exp',
'SyN', argstr='%s', mandatory=True,
Expand Down
22 changes: 22 additions & 0 deletions nipype/interfaces/ants/tests/test_registration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
from __future__ import unicode_literals
from nipype.interfaces.ants import registration
import os
import pytest


def test_ants_mand(tmpdir):
tmpdir.chdir()
filepath = os.path.dirname(os.path.realpath(__file__))
datadir = os.path.realpath(os.path.join(filepath, '../../../testing/data'))

ants = registration.ANTS()
ants.inputs.transformation_model = "SyN"
ants.inputs.moving_image = [os.path.join(datadir, 'resting.nii')]
ants.inputs.fixed_image = [os.path.join(datadir, 'T1.nii')]
ants.inputs.metric = ['MI']

with pytest.raises(ValueError) as er:
ants.run()
assert "ANTS requires a value for input 'radius'" in str(er.value)