Skip to content

Commit 414868a

Browse files
committed
New camino interface for ImageStats
1 parent 99b354a commit 414868a

File tree

6 files changed

+110
-0
lines changed

6 files changed

+110
-0
lines changed

nipype/interfaces/camino/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
ComputeTensorTrace, ComputeEigensystem, DTMetric)
1414
from .calib import (SFPICOCalibData, SFLUTGen)
1515
from .odf import (QBallMX, LinRecon, SFPeaks, MESD)
16+
from .utils import ImageStats
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from nipype.testing import assert_equal
3+
from nipype.interfaces.camino.utils import ImageStats
4+
5+
def test_ImageStats_inputs():
6+
input_map = dict(args=dict(argstr='%s',
7+
),
8+
environ=dict(nohash=True,
9+
usedefault=True,
10+
),
11+
ignore_exception=dict(nohash=True,
12+
usedefault=True,
13+
),
14+
in_files=dict(argstr='-images %s',
15+
mandatory=True,
16+
position=-1,
17+
),
18+
out_type=dict(argstr='-outputdatatype %s',
19+
usedefault=True,
20+
),
21+
output_root=dict(argstr='-outputroot %s',
22+
mandatory=True,
23+
),
24+
stat=dict(argstr='-stat %s',
25+
mandatory=True,
26+
units='NA',
27+
),
28+
terminal_output=dict(mandatory=True,
29+
nohash=True,
30+
),
31+
)
32+
inputs = ImageStats.input_spec()
33+
34+
for key, metadata in input_map.items():
35+
for metakey, value in metadata.items():
36+
yield assert_equal, getattr(inputs.traits()[key], metakey), value
37+
38+
def test_ImageStats_outputs():
39+
output_map = dict(out_file=dict(),
40+
)
41+
outputs = ImageStats.output_spec()
42+
43+
for key, metadata in output_map.items():
44+
for metakey, value in metadata.items():
45+
yield assert_equal, getattr(outputs.traits()[key], metakey), value
46+

nipype/interfaces/camino/utils.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
Change directory to provide relative paths for doctests
3+
>>> import os
4+
>>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
5+
>>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data'))
6+
>>> os.chdir(datadir)
7+
8+
"""
9+
from nipype.interfaces.base import (traits, TraitedSpec, File,
10+
CommandLine, CommandLineInputSpec, isdefined,
11+
InputMultiPath)
12+
from nipype.utils.filemanip import split_filename
13+
import os
14+
15+
class ImageStatsInputSpec(CommandLineInputSpec):
16+
in_files = InputMultiPath(File(exists=True), argstr='-images %s', mandatory=True,
17+
position=-1, desc=('List of images to process. They must '
18+
'be in the same space and have the same '
19+
'dimensions.'))
20+
stat = traits.Enum("min", "max", "mean", "median", "sum", "std", "var",
21+
argstr='-stat %s', units='NA', mandatory=True,
22+
desc="The statistic to compute.")
23+
24+
out_type = traits.Enum("float", "char", "short", "int", "long", "double",
25+
argstr='-outputdatatype %s', usedefault=True,
26+
desc=('A Camino data type string, default is "float". '
27+
'Type must be signed.'))
28+
output_root = File(argstr='-outputroot %s', mandatory=True,
29+
desc=('Filename root prepended onto the names of the output '
30+
' files. The extension will be determined from the input.'))
31+
32+
class ImageStatsOutputSpec(TraitedSpec):
33+
out_file = File(exists=True, desc='Path of the file computed with the statistic chosen')
34+
35+
class ImageStats(CommandLine):
36+
"""
37+
This program computes voxelwise statistics on a series of 3D images. The images
38+
must be in the same space; the operation is performed voxelwise and one output
39+
is produced per voxel.
40+
41+
Examples
42+
--------
43+
44+
>>> import nipype.interfaces.camino as cam
45+
>>> imstats = cam.ImageStats()
46+
>>> imstats.inputs.in_files = ['im1.nii','im2.nii','im3.nii']
47+
>>> imstats.inputs.stat = 'max'
48+
>>> imstats.run() # doctest: +SKIP
49+
"""
50+
_cmd = 'imagestats'
51+
input_spec = ImageStatsInputSpec
52+
output_spec = ImageStatsOutputSpec
53+
54+
def _list_outputs(self):
55+
outputs = self.output_spec().get()
56+
outputs['out_file'] = os.path.abspath(self._gen_outfilename())
57+
return outputs
58+
59+
def _gen_outfilename(self):
60+
output_root = self.inputs.output_root
61+
first_file = self.inputs.in_files[0]
62+
_, _ , ext = split_filename(first_file)
63+
return output_root + ext

nipype/testing/data/im1.nii

Whitespace-only changes.

nipype/testing/data/im2.nii

Whitespace-only changes.

nipype/testing/data/im3.nii

Whitespace-only changes.

0 commit comments

Comments
 (0)