Skip to content

Commit e89436c

Browse files
authored
Merge pull request #1956 from imalone/fslmaths-dimension-reducing
[ENH] FSL maths interface, add the remaining dimension reduction operations…
2 parents 94ec7e0 + 1a02111 commit e89436c

File tree

7 files changed

+374
-1
lines changed

7 files changed

+374
-1
lines changed

nipype/interfaces/fsl/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
TractSkeleton, MakeDyadicVectors, BEDPOSTX5, XFibres5)
3030
from .maths import (ChangeDataType, Threshold, MeanImage, ApplyMask,
3131
IsotropicSmooth, TemporalFilter, DilateImage, ErodeImage,
32-
SpatialFilter, UnaryMaths, BinaryMaths, MultiImageMaths)
32+
SpatialFilter, UnaryMaths, BinaryMaths, MultiImageMaths,
33+
MaxnImage, MinImage, MedianImage, PercentileImage,
34+
AR1Image)
3335

3436
from .possum import B0Calc

nipype/interfaces/fsl/maths.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,98 @@ class MaxImage(MathsCommand):
174174
_suffix = "_max"
175175

176176

177+
class PercentileImageInput(MathsInput):
178+
179+
dimension = traits.Enum("T", "X", "Y", "Z", usedefault=True,
180+
argstr="-%sperc", position=4,
181+
desc="dimension to percentile across")
182+
perc = traits.Range(low=0, high=100, usedefault=False,
183+
argstr="%f", position=5,
184+
desc=("nth percentile (0-100) of FULL RANGE "
185+
"across dimension"))
186+
187+
188+
class PercentileImage(MathsCommand):
189+
"""Use fslmaths to generate a percentile image across a given dimension.
190+
191+
Examples
192+
--------
193+
>>> from nipype.interfaces.fsl.maths import MaxImage
194+
>>> percer = PercentileImage()
195+
>>> percer.inputs.in_file = "functional.nii" # doctest: +SKIP
196+
>>> percer.dimension = "T"
197+
>>> percer.perc = 90
198+
>>> percer.cmdline # doctest: +SKIP
199+
'fslmaths functional.nii -Tperc 90 functional_perc.nii'
200+
201+
"""
202+
input_spec = PercentileImageInput
203+
_suffix = "_perc"
204+
205+
206+
class MaxnImageInput(MathsInput):
207+
208+
dimension = traits.Enum("T", "X", "Y", "Z", usedefault=True,
209+
argstr="-%smaxn", position=4,
210+
desc="dimension to index max across")
211+
212+
213+
class MaxnImage(MathsCommand):
214+
"""Use fslmaths to generate an image of index of max across
215+
a given dimension.
216+
217+
"""
218+
input_spec = MaxnImageInput
219+
_suffix = "_maxn"
220+
221+
222+
class MinImageInput(MathsInput):
223+
224+
dimension = traits.Enum("T", "X", "Y", "Z", usedefault=True,
225+
argstr="-%smin", position=4,
226+
desc="dimension to min across")
227+
228+
229+
class MinImage(MathsCommand):
230+
"""Use fslmaths to generate a minimum image across a given dimension.
231+
232+
"""
233+
input_spec = MinImageInput
234+
_suffix = "_min"
235+
236+
237+
class MedianImageInput(MathsInput):
238+
239+
dimension = traits.Enum("T", "X", "Y", "Z", usedefault=True,
240+
argstr="-%smedian", position=4,
241+
desc="dimension to median across")
242+
243+
244+
class MedianImage(MathsCommand):
245+
"""Use fslmaths to generate a median image across a given dimension.
246+
247+
"""
248+
input_spec = MedianImageInput
249+
_suffix = "_median"
250+
251+
252+
class AR1ImageInput(MathsInput):
253+
254+
dimension = traits.Enum("T", "X", "Y", "Z", usedefault=True,
255+
argstr="-%sar1", position=4,
256+
desc=("dimension to find AR(1) coefficient"
257+
"across"))
258+
259+
260+
class AR1Image(MathsCommand):
261+
"""Use fslmaths to generate an AR1 coefficient image across a
262+
given dimension. (Should use -odt float and probably demean first)
263+
264+
"""
265+
input_spec = AR1ImageInput
266+
_suffix = "_ar1"
267+
268+
177269
class IsotropicSmoothInput(MathsInput):
178270

179271
fwhm = traits.Float(mandatory=True, xor=["sigma"],
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..maths import AR1Image
4+
5+
6+
def test_AR1Image_inputs():
7+
input_map = dict(args=dict(argstr='%s',
8+
),
9+
dimension=dict(argstr='-%sar1',
10+
position=4,
11+
usedefault=True,
12+
),
13+
environ=dict(nohash=True,
14+
usedefault=True,
15+
),
16+
ignore_exception=dict(nohash=True,
17+
usedefault=True,
18+
),
19+
in_file=dict(argstr='%s',
20+
mandatory=True,
21+
position=2,
22+
),
23+
internal_datatype=dict(argstr='-dt %s',
24+
position=1,
25+
),
26+
nan2zeros=dict(argstr='-nan',
27+
position=3,
28+
),
29+
out_file=dict(argstr='%s',
30+
genfile=True,
31+
hash_files=False,
32+
position=-2,
33+
),
34+
output_datatype=dict(argstr='-odt %s',
35+
position=-1,
36+
),
37+
output_type=dict(),
38+
terminal_output=dict(nohash=True,
39+
),
40+
)
41+
inputs = AR1Image.input_spec()
42+
43+
for key, metadata in list(input_map.items()):
44+
for metakey, value in list(metadata.items()):
45+
assert getattr(inputs.traits()[key], metakey) == value
46+
47+
48+
def test_AR1Image_outputs():
49+
output_map = dict(out_file=dict(),
50+
)
51+
outputs = AR1Image.output_spec()
52+
53+
for key, metadata in list(output_map.items()):
54+
for metakey, value in list(metadata.items()):
55+
assert getattr(outputs.traits()[key], metakey) == value
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..maths import MaxnImage
4+
5+
6+
def test_MaxnImage_inputs():
7+
input_map = dict(args=dict(argstr='%s',
8+
),
9+
dimension=dict(argstr='-%smaxn',
10+
position=4,
11+
usedefault=True,
12+
),
13+
environ=dict(nohash=True,
14+
usedefault=True,
15+
),
16+
ignore_exception=dict(nohash=True,
17+
usedefault=True,
18+
),
19+
in_file=dict(argstr='%s',
20+
mandatory=True,
21+
position=2,
22+
),
23+
internal_datatype=dict(argstr='-dt %s',
24+
position=1,
25+
),
26+
nan2zeros=dict(argstr='-nan',
27+
position=3,
28+
),
29+
out_file=dict(argstr='%s',
30+
genfile=True,
31+
hash_files=False,
32+
position=-2,
33+
),
34+
output_datatype=dict(argstr='-odt %s',
35+
position=-1,
36+
),
37+
output_type=dict(),
38+
terminal_output=dict(nohash=True,
39+
),
40+
)
41+
inputs = MaxnImage.input_spec()
42+
43+
for key, metadata in list(input_map.items()):
44+
for metakey, value in list(metadata.items()):
45+
assert getattr(inputs.traits()[key], metakey) == value
46+
47+
48+
def test_MaxnImage_outputs():
49+
output_map = dict(out_file=dict(),
50+
)
51+
outputs = MaxnImage.output_spec()
52+
53+
for key, metadata in list(output_map.items()):
54+
for metakey, value in list(metadata.items()):
55+
assert getattr(outputs.traits()[key], metakey) == value
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..maths import MedianImage
4+
5+
6+
def test_MedianImage_inputs():
7+
input_map = dict(args=dict(argstr='%s',
8+
),
9+
dimension=dict(argstr='-%smedian',
10+
position=4,
11+
usedefault=True,
12+
),
13+
environ=dict(nohash=True,
14+
usedefault=True,
15+
),
16+
ignore_exception=dict(nohash=True,
17+
usedefault=True,
18+
),
19+
in_file=dict(argstr='%s',
20+
mandatory=True,
21+
position=2,
22+
),
23+
internal_datatype=dict(argstr='-dt %s',
24+
position=1,
25+
),
26+
nan2zeros=dict(argstr='-nan',
27+
position=3,
28+
),
29+
out_file=dict(argstr='%s',
30+
genfile=True,
31+
hash_files=False,
32+
position=-2,
33+
),
34+
output_datatype=dict(argstr='-odt %s',
35+
position=-1,
36+
),
37+
output_type=dict(),
38+
terminal_output=dict(nohash=True,
39+
),
40+
)
41+
inputs = MedianImage.input_spec()
42+
43+
for key, metadata in list(input_map.items()):
44+
for metakey, value in list(metadata.items()):
45+
assert getattr(inputs.traits()[key], metakey) == value
46+
47+
48+
def test_MedianImage_outputs():
49+
output_map = dict(out_file=dict(),
50+
)
51+
outputs = MedianImage.output_spec()
52+
53+
for key, metadata in list(output_map.items()):
54+
for metakey, value in list(metadata.items()):
55+
assert getattr(outputs.traits()[key], metakey) == value
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..maths import MinImage
4+
5+
6+
def test_MinImage_inputs():
7+
input_map = dict(args=dict(argstr='%s',
8+
),
9+
dimension=dict(argstr='-%smin',
10+
position=4,
11+
usedefault=True,
12+
),
13+
environ=dict(nohash=True,
14+
usedefault=True,
15+
),
16+
ignore_exception=dict(nohash=True,
17+
usedefault=True,
18+
),
19+
in_file=dict(argstr='%s',
20+
mandatory=True,
21+
position=2,
22+
),
23+
internal_datatype=dict(argstr='-dt %s',
24+
position=1,
25+
),
26+
nan2zeros=dict(argstr='-nan',
27+
position=3,
28+
),
29+
out_file=dict(argstr='%s',
30+
genfile=True,
31+
hash_files=False,
32+
position=-2,
33+
),
34+
output_datatype=dict(argstr='-odt %s',
35+
position=-1,
36+
),
37+
output_type=dict(),
38+
terminal_output=dict(nohash=True,
39+
),
40+
)
41+
inputs = MinImage.input_spec()
42+
43+
for key, metadata in list(input_map.items()):
44+
for metakey, value in list(metadata.items()):
45+
assert getattr(inputs.traits()[key], metakey) == value
46+
47+
48+
def test_MinImage_outputs():
49+
output_map = dict(out_file=dict(),
50+
)
51+
outputs = MinImage.output_spec()
52+
53+
for key, metadata in list(output_map.items()):
54+
for metakey, value in list(metadata.items()):
55+
assert getattr(outputs.traits()[key], metakey) == value
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..maths import PercentileImage
4+
5+
6+
def test_PercentileImage_inputs():
7+
input_map = dict(args=dict(argstr='%s',
8+
),
9+
dimension=dict(argstr='-%sperc',
10+
position=4,
11+
usedefault=True,
12+
),
13+
environ=dict(nohash=True,
14+
usedefault=True,
15+
),
16+
ignore_exception=dict(nohash=True,
17+
usedefault=True,
18+
),
19+
in_file=dict(argstr='%s',
20+
mandatory=True,
21+
position=2,
22+
),
23+
internal_datatype=dict(argstr='-dt %s',
24+
position=1,
25+
),
26+
nan2zeros=dict(argstr='-nan',
27+
position=3,
28+
),
29+
out_file=dict(argstr='%s',
30+
genfile=True,
31+
hash_files=False,
32+
position=-2,
33+
),
34+
output_datatype=dict(argstr='-odt %s',
35+
position=-1,
36+
),
37+
output_type=dict(),
38+
perc=dict(argstr='%f',
39+
position=5,
40+
usedefault=False,
41+
),
42+
terminal_output=dict(nohash=True,
43+
),
44+
)
45+
inputs = PercentileImage.input_spec()
46+
47+
for key, metadata in list(input_map.items()):
48+
for metakey, value in list(metadata.items()):
49+
assert getattr(inputs.traits()[key], metakey) == value
50+
51+
52+
def test_PercentileImage_outputs():
53+
output_map = dict(out_file=dict(),
54+
)
55+
outputs = PercentileImage.output_spec()
56+
57+
for key, metadata in list(output_map.items()):
58+
for metakey, value in list(metadata.items()):
59+
assert getattr(outputs.traits()[key], metakey) == value

0 commit comments

Comments
 (0)