Skip to content

enh: add interface for LabelGeometryMeasures #2586

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 2 commits into from
May 19, 2018
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
2 changes: 1 addition & 1 deletion nipype/interfaces/ants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
# Utility Programs
from .utils import (AverageAffineTransform, AverageImages, MultiplyImages,
CreateJacobianDeterminantImage, AffineInitializer,
ComposeMultiTransform)
ComposeMultiTransform, LabelGeometry)
60 changes: 60 additions & 0 deletions nipype/interfaces/ants/tests/test_auto_LabelGeometry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
from __future__ import unicode_literals
from ..utils import LabelGeometry


def test_LabelGeometry_inputs():
input_map = dict(
args=dict(argstr='%s', ),
dimension=dict(
argstr='%d',
position=0,
usedefault=True,
),
environ=dict(
nohash=True,
usedefault=True,
),
ignore_exception=dict(
deprecated='1.0.0',
nohash=True,
usedefault=True,
),
intensity_image=dict(
argstr='%s',
mandatory=True,
position=2,
usedefault=True,
),
label_image=dict(
argstr='%s',
mandatory=True,
position=1,
),
num_threads=dict(
nohash=True,
usedefault=True,
),
output_file=dict(
argstr='%s',
name_source=['label_image'],
name_template='%s.csv',
position=3,
),
terminal_output=dict(
deprecated='1.0.0',
nohash=True,
),
)
inputs = LabelGeometry.input_spec()

for key, metadata in list(input_map.items()):
for metakey, value in list(metadata.items()):
assert getattr(inputs.traits()[key], metakey) == value
def test_LabelGeometry_outputs():
output_map = dict(output_file=dict(), )
outputs = LabelGeometry.output_spec()

for key, metadata in list(output_map.items()):
for metakey, value in list(metadata.items()):
assert getattr(outputs.traits()[key], metakey) == value
57 changes: 57 additions & 0 deletions nipype/interfaces/ants/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,60 @@ class ComposeMultiTransform(ANTSCommand):
_cmd = 'ComposeMultiTransform'
input_spec = ComposeMultiTransformInputSpec
output_spec = ComposeMultiTransformOutputSpec


class LabelGeometryInputSpec(ANTSCommandInputSpec):
dimension = traits.Enum(
3,
2,
argstr='%d',
usedefault=True,
position=0,
desc='image dimension (2 or 3)')
label_image = File(
argstr='%s',
position=1,
mandatory=True,
desc='label image to use for extracting geometry measures')
intensity_image = File(
value='[]',
exists=True,
Copy link
Member

Choose a reason for hiding this comment

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

exists=True seems weird, given a default value of '[]'. I guess it applies only to non-default values?

Copy link
Member Author

Choose a reason for hiding this comment

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

exists only applies to non-default values (could be considered a bug). i'm taking advantage of that here, without writing a _format_arg function, but something to keep in mind.

argstr='%s',
mandatory=True,
usedefault=True,
position=2,
desc='Intensity image to extract values from. '
'This is an optional input')
output_file = traits.Str(
name_source=['label_image'],
name_template='%s.csv',
argstr='%s',
position=3,
desc='name of output file')


class LabelGeometryOutputSpec(TraitedSpec):
output_file = File(exists=True, desc='CSV file of geometry measures')


class LabelGeometry(ANTSCommand):
"""
Extracts geometry measures using a label file and an optional image file

Examples
--------
>>> from nipype.interfaces.ants import LabelGeometry
>>> label_extract = LabelGeometry()
>>> label_extract.inputs.dimension = 3
>>> label_extract.inputs.label_image = 'atlas.nii.gz'
>>> label_extract.cmdline
'LabelGeometryMeasures 3 atlas.nii.gz [] atlas.csv'

>>> label_extract.inputs.intensity_image = 'ants_Warp.nii.gz'
>>> label_extract.cmdline
'LabelGeometryMeasures 3 atlas.nii.gz ants_Warp.nii.gz atlas.csv'

"""
_cmd = 'LabelGeometryMeasures'
input_spec = LabelGeometryInputSpec
output_spec = LabelGeometryOutputSpec