Skip to content

Commit 9c6df2f

Browse files
committed
Fixes for PR #847
Added a test: #847 (comment) Changed interface name
1 parent ef8e0c7 commit 9c6df2f

File tree

6 files changed

+66
-6
lines changed

6 files changed

+66
-6
lines changed

nipype/algorithms/misc.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,32 +1207,34 @@ def calc_moments(timeseries_file, moment):
12071207
return np.where(zero, 0, m3 / m2**(moment/2.0))
12081208

12091209

1210-
class NormalizeMapsInputSpec(TraitedSpec):
1210+
class NormalizeProbabilityMapSetInputSpec(TraitedSpec):
12111211
in_files = InputMultiPath(File(exists=True, mandatory=True,
12121212
desc='The tpms to be normalized') )
12131213
in_mask = File(exists=True, mandatory=False,
12141214
desc='Masked voxels must sum up 1.0, 0.0 otherwise.')
12151215

1216-
class NormalizeMapsOutputSpec(TraitedSpec):
1216+
class NormalizeProbabilityMapSetOutputSpec(TraitedSpec):
12171217
out_files = OutputMultiPath(File(exists=True),
12181218
desc="normalized maps")
12191219

12201220

1221-
class NormalizeMaps(BaseInterface):
1221+
class NormalizeProbabilityMapSet(BaseInterface):
12221222
""" Returns the input tissue probability maps (tpms, aka volume fractions)
12231223
normalized to sum up 1.0 at each voxel within the mask.
12241224
1225+
.. note:: Please recall this is not a spatial normalization algorithm
1226+
12251227
Example
12261228
-------
12271229
12281230
>>> import nipype.algorithms.misc as misc
1229-
>>> normalize = misc.NormalizeMaps()
1231+
>>> normalize = misc.NormalizeProbabilityMapSet()
12301232
>>> normalize.inputs.in_files = [ 'csf.nii', 'wm.nii', 'gm.nii' ]
12311233
>>> normalize.inputs.in_mask = [ 'brain.nii' ]
12321234
>>> normalize.run() # doctest: +SKIP
12331235
"""
1234-
input_spec = NormalizeMapsInputSpec
1235-
output_spec = NormalizeMapsOutputSpec
1236+
input_spec = NormalizeProbabilityMapSetInputSpec
1237+
output_spec = NormalizeProbabilityMapSetOutputSpec
12361238

12371239
def _run_interface(self, runtime):
12381240
mask = None
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
4+
# vi: set ft=python sts=4 ts=4 sw=4 et:
5+
#
6+
# @Author: oesteban - [email protected]
7+
# @Date: 2014-05-28 17:57:20
8+
# @Last Modified by: oesteban
9+
# @Last Modified time: 2014-05-28 18:55:27
10+
11+
import os
12+
from shutil import rmtree
13+
from tempfile import mkdtemp
14+
15+
16+
import numpy as np
17+
import nibabel as nb
18+
import nipype.testing as nit
19+
20+
from nipype.algorithms.misc import normalize_tpms
21+
22+
def test_normalize_tpms():
23+
tempdir = mkdtemp()
24+
25+
in_mask = os.path.join(nit.basedir, 'data' , 'tpms_msk.nii.gz' )
26+
mskdata = nb.load( in_mask ).get_data()
27+
mskdata[mskdata>0.0] = 1.0
28+
29+
mapdata = []
30+
in_files = []
31+
out_files = []
32+
33+
for i in range(3):
34+
mapname = os.path.join(nit.basedir, 'data' , 'tpm_%02d.nii.gz' % i)
35+
filename = os.path.join(tempdir, 'modtpm_%02d.nii.gz' % i )
36+
out_files.append(os.path.join(tempdir, 'normtpm_%02d.nii.gz' % i ))
37+
38+
im = nb.load(mapname)
39+
data = im.get_data()
40+
mapdata.append( data.copy() )
41+
42+
nb.Nifti1Image(2.0 * (data * mskdata), im.get_affine(),
43+
im.get_header() ).to_filename(filename)
44+
in_files.append( filename )
45+
46+
normalize_tpms( in_files, in_mask, out_files=out_files )
47+
48+
sumdata = np.zeros_like(mskdata)
49+
50+
for i,tstfname in enumerate( out_files ):
51+
normdata = nb.load( tstfname ).get_data()
52+
sumdata+=normdata
53+
yield assert_equal, np.all( normdata[mskdata==0]==0 ), True
54+
yield assert_equal, np.allclose( normdata, mapdata[i] ), True
55+
56+
yield assert_equal, np.allclose( sumdata, mskdata ), True
57+
58+
rmtree(tempdir)

nipype/testing/data/tpm_00.nii.gz

157 KB
Binary file not shown.

nipype/testing/data/tpm_01.nii.gz

137 KB
Binary file not shown.

nipype/testing/data/tpm_02.nii.gz

136 KB
Binary file not shown.

nipype/testing/data/tpms_msk.nii.gz

20 KB
Binary file not shown.

0 commit comments

Comments
 (0)