Skip to content

Commit 77f644a

Browse files
authored
Merge pull request #1518 from satra/fix/stdimage
Fix/stdimage
2 parents 9d793c1 + 09082af commit 77f644a

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

nipype/interfaces/fsl/maths.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ def _format_arg(self, name, spec, value):
111111
return arg
112112
return super(Threshold, self)._format_arg(name, spec, value)
113113

114+
class StdImageInput(MathsInput):
115+
116+
dimension = traits.Enum("T", "X", "Y", "Z", usedefault=True, argstr="-%sstd", position=4,
117+
desc="dimension to standard deviate across")
118+
119+
120+
class StdImage(MathsCommand):
121+
"""Use fslmaths to generate a standard deviation in an image across a given dimension.
122+
"""
123+
input_spec = StdImageInput
124+
_suffix = "_std"
114125

115126
class MeanImageInput(MathsInput):
116127

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 ....testing import assert_equal
3+
from ..maths import StdImage
4+
5+
6+
def test_StdImage_inputs():
7+
input_map = dict(args=dict(argstr='%s',
8+
),
9+
dimension=dict(argstr='-%sstd',
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 = StdImage.input_spec()
42+
43+
for key, metadata in list(input_map.items()):
44+
for metakey, value in list(metadata.items()):
45+
yield assert_equal, getattr(inputs.traits()[key], metakey), value
46+
47+
48+
def test_StdImage_outputs():
49+
output_map = dict(out_file=dict(),
50+
)
51+
outputs = StdImage.output_spec()
52+
53+
for key, metadata in list(output_map.items()):
54+
for metakey, value in list(metadata.items()):
55+
yield assert_equal, getattr(outputs.traits()[key], metakey), value

nipype/interfaces/fsl/tests/test_maths.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,33 @@ def test_meanimage(fsl_output_type=None):
194194
clean_directory(testdir, origdir)
195195
set_output_type(prev_type)
196196

197+
@skipif(no_fsl)
198+
def test_stdimage(fsl_output_type=None):
199+
prev_type = set_output_type(fsl_output_type)
200+
files, testdir, origdir, out_ext = create_files_in_directory()
201+
202+
# Get the command
203+
stder = fsl.StdImage(in_file="a.nii",out_file="b.nii")
204+
205+
# Test the underlying command
206+
yield assert_equal, stder.cmd, "fslmaths"
207+
208+
# Test the defualt opstring
209+
yield assert_equal, stder.cmdline, "fslmaths a.nii -Tstd b.nii"
210+
211+
# Test the other dimensions
212+
cmdline = "fslmaths a.nii -%sstd b.nii"
213+
for dim in ["X","Y","Z","T"]:
214+
stder.inputs.dimension=dim
215+
yield assert_equal, stder.cmdline, cmdline%dim
216+
217+
# Test the auto naming
218+
stder = fsl.StdImage(in_file="a.nii")
219+
yield assert_equal, stder.cmdline, "fslmaths a.nii -Tstd %s"%os.path.join(testdir, "a_std.nii")
220+
221+
# Clean up our mess
222+
clean_directory(testdir, origdir)
223+
set_output_type(prev_type)
197224

198225
@skipif(no_fsl)
199226
def test_maximage(fsl_output_type=None):

0 commit comments

Comments
 (0)