Skip to content

[ENH] FSL maths interface, add the remaining dimension reduction operations… #1956

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
Apr 20, 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
4 changes: 3 additions & 1 deletion nipype/interfaces/fsl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
TractSkeleton, MakeDyadicVectors, BEDPOSTX5, XFibres5)
from .maths import (ChangeDataType, Threshold, MeanImage, ApplyMask,
IsotropicSmooth, TemporalFilter, DilateImage, ErodeImage,
SpatialFilter, UnaryMaths, BinaryMaths, MultiImageMaths)
SpatialFilter, UnaryMaths, BinaryMaths, MultiImageMaths,
MaxnImage, MinImage, MedianImage, PercentileImage,
AR1Image)

from .possum import B0Calc
92 changes: 92 additions & 0 deletions nipype/interfaces/fsl/maths.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,98 @@ class MaxImage(MathsCommand):
_suffix = "_max"


class PercentileImageInput(MathsInput):

dimension = traits.Enum("T", "X", "Y", "Z", usedefault=True,
argstr="-%sperc", position=4,
desc="dimension to percentile across")
perc = traits.Range(low=0, high=100, usedefault=False,
argstr="%f", position=5,
desc=("nth percentile (0-100) of FULL RANGE "
"across dimension"))


class PercentileImage(MathsCommand):
"""Use fslmaths to generate a percentile image across a given dimension.

Examples
--------
>>> from nipype.interfaces.fsl.maths import MaxImage
>>> percer = PercentileImage()
>>> percer.inputs.in_file = "functional.nii" # doctest: +SKIP
>>> percer.dimension = "T"
>>> percer.perc = 90
>>> percer.cmdline # doctest: +SKIP
'fslmaths functional.nii -Tperc 90 functional_perc.nii'

"""
input_spec = PercentileImageInput
_suffix = "_perc"


class MaxnImageInput(MathsInput):

dimension = traits.Enum("T", "X", "Y", "Z", usedefault=True,
argstr="-%smaxn", position=4,
desc="dimension to index max across")


class MaxnImage(MathsCommand):
"""Use fslmaths to generate an image of index of max across
a given dimension.

"""
input_spec = MaxnImageInput
_suffix = "_maxn"


class MinImageInput(MathsInput):

dimension = traits.Enum("T", "X", "Y", "Z", usedefault=True,
argstr="-%smin", position=4,
desc="dimension to min across")


class MinImage(MathsCommand):
"""Use fslmaths to generate a minimum image across a given dimension.

"""
input_spec = MinImageInput
_suffix = "_min"


class MedianImageInput(MathsInput):

dimension = traits.Enum("T", "X", "Y", "Z", usedefault=True,
argstr="-%smedian", position=4,
desc="dimension to median across")


class MedianImage(MathsCommand):
"""Use fslmaths to generate a median image across a given dimension.

"""
input_spec = MedianImageInput
_suffix = "_median"


class AR1ImageInput(MathsInput):

dimension = traits.Enum("T", "X", "Y", "Z", usedefault=True,
argstr="-%sar1", position=4,
desc=("dimension to find AR(1) coefficient"
"across"))


class AR1Image(MathsCommand):
"""Use fslmaths to generate an AR1 coefficient image across a
given dimension. (Should use -odt float and probably demean first)

"""
input_spec = AR1ImageInput
_suffix = "_ar1"


class IsotropicSmoothInput(MathsInput):

fwhm = traits.Float(mandatory=True, xor=["sigma"],
Expand Down
55 changes: 55 additions & 0 deletions nipype/interfaces/fsl/tests/test_auto_AR1Image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
from __future__ import unicode_literals
from ..maths import AR1Image


def test_AR1Image_inputs():
input_map = dict(args=dict(argstr='%s',
),
dimension=dict(argstr='-%sar1',
position=4,
usedefault=True,
),
environ=dict(nohash=True,
usedefault=True,
),
ignore_exception=dict(nohash=True,
usedefault=True,
),
in_file=dict(argstr='%s',
mandatory=True,
position=2,
),
internal_datatype=dict(argstr='-dt %s',
position=1,
),
nan2zeros=dict(argstr='-nan',
position=3,
),
out_file=dict(argstr='%s',
genfile=True,
hash_files=False,
position=-2,
),
output_datatype=dict(argstr='-odt %s',
position=-1,
),
output_type=dict(),
terminal_output=dict(nohash=True,
),
)
inputs = AR1Image.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_AR1Image_outputs():
output_map = dict(out_file=dict(),
)
outputs = AR1Image.output_spec()

for key, metadata in list(output_map.items()):
for metakey, value in list(metadata.items()):
assert getattr(outputs.traits()[key], metakey) == value
55 changes: 55 additions & 0 deletions nipype/interfaces/fsl/tests/test_auto_MaxnImage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
from __future__ import unicode_literals
from ..maths import MaxnImage


def test_MaxnImage_inputs():
input_map = dict(args=dict(argstr='%s',
),
dimension=dict(argstr='-%smaxn',
position=4,
usedefault=True,
),
environ=dict(nohash=True,
usedefault=True,
),
ignore_exception=dict(nohash=True,
usedefault=True,
),
in_file=dict(argstr='%s',
mandatory=True,
position=2,
),
internal_datatype=dict(argstr='-dt %s',
position=1,
),
nan2zeros=dict(argstr='-nan',
position=3,
),
out_file=dict(argstr='%s',
genfile=True,
hash_files=False,
position=-2,
),
output_datatype=dict(argstr='-odt %s',
position=-1,
),
output_type=dict(),
terminal_output=dict(nohash=True,
),
)
inputs = MaxnImage.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_MaxnImage_outputs():
output_map = dict(out_file=dict(),
)
outputs = MaxnImage.output_spec()

for key, metadata in list(output_map.items()):
for metakey, value in list(metadata.items()):
assert getattr(outputs.traits()[key], metakey) == value
55 changes: 55 additions & 0 deletions nipype/interfaces/fsl/tests/test_auto_MedianImage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
from __future__ import unicode_literals
from ..maths import MedianImage


def test_MedianImage_inputs():
input_map = dict(args=dict(argstr='%s',
),
dimension=dict(argstr='-%smedian',
position=4,
usedefault=True,
),
environ=dict(nohash=True,
usedefault=True,
),
ignore_exception=dict(nohash=True,
usedefault=True,
),
in_file=dict(argstr='%s',
mandatory=True,
position=2,
),
internal_datatype=dict(argstr='-dt %s',
position=1,
),
nan2zeros=dict(argstr='-nan',
position=3,
),
out_file=dict(argstr='%s',
genfile=True,
hash_files=False,
position=-2,
),
output_datatype=dict(argstr='-odt %s',
position=-1,
),
output_type=dict(),
terminal_output=dict(nohash=True,
),
)
inputs = MedianImage.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_MedianImage_outputs():
output_map = dict(out_file=dict(),
)
outputs = MedianImage.output_spec()

for key, metadata in list(output_map.items()):
for metakey, value in list(metadata.items()):
assert getattr(outputs.traits()[key], metakey) == value
55 changes: 55 additions & 0 deletions nipype/interfaces/fsl/tests/test_auto_MinImage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
from __future__ import unicode_literals
from ..maths import MinImage


def test_MinImage_inputs():
input_map = dict(args=dict(argstr='%s',
),
dimension=dict(argstr='-%smin',
position=4,
usedefault=True,
),
environ=dict(nohash=True,
usedefault=True,
),
ignore_exception=dict(nohash=True,
usedefault=True,
),
in_file=dict(argstr='%s',
mandatory=True,
position=2,
),
internal_datatype=dict(argstr='-dt %s',
position=1,
),
nan2zeros=dict(argstr='-nan',
position=3,
),
out_file=dict(argstr='%s',
genfile=True,
hash_files=False,
position=-2,
),
output_datatype=dict(argstr='-odt %s',
position=-1,
),
output_type=dict(),
terminal_output=dict(nohash=True,
),
)
inputs = MinImage.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_MinImage_outputs():
output_map = dict(out_file=dict(),
)
outputs = MinImage.output_spec()

for key, metadata in list(output_map.items()):
for metakey, value in list(metadata.items()):
assert getattr(outputs.traits()[key], metakey) == value
59 changes: 59 additions & 0 deletions nipype/interfaces/fsl/tests/test_auto_PercentileImage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
from __future__ import unicode_literals
from ..maths import PercentileImage


def test_PercentileImage_inputs():
input_map = dict(args=dict(argstr='%s',
),
dimension=dict(argstr='-%sperc',
position=4,
usedefault=True,
),
environ=dict(nohash=True,
usedefault=True,
),
ignore_exception=dict(nohash=True,
usedefault=True,
),
in_file=dict(argstr='%s',
mandatory=True,
position=2,
),
internal_datatype=dict(argstr='-dt %s',
position=1,
),
nan2zeros=dict(argstr='-nan',
position=3,
),
out_file=dict(argstr='%s',
genfile=True,
hash_files=False,
position=-2,
),
output_datatype=dict(argstr='-odt %s',
position=-1,
),
output_type=dict(),
perc=dict(argstr='%f',
position=5,
usedefault=False,
),
terminal_output=dict(nohash=True,
),
)
inputs = PercentileImage.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_PercentileImage_outputs():
output_map = dict(out_file=dict(),
)
outputs = PercentileImage.output_spec()

for key, metadata in list(output_map.items()):
for metakey, value in list(metadata.items()):
assert getattr(outputs.traits()[key], metakey) == value