Skip to content

Commit 8bd261f

Browse files
committed
Add tests
1 parent 173d6f3 commit 8bd261f

File tree

5 files changed

+53
-6
lines changed

5 files changed

+53
-6
lines changed

nipype/algorithms/metrics.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ def _run_interface(self, runtime):
339339

340340
self._labels = labels
341341
self._ove_rois = results
342-
self._vol_rois = np.abs(np.array(volumes1) - np.array(volumes2))
342+
self._vol_rois = ((np.array(volumes1) - np.array(volumes2)) /
343+
np.array(volumes1))
343344

344345
self._dice = round(np.sum(weights*results['dice']), 5)
345346
self._jaccard = round(np.sum(weights*results['jaccard']), 5)

nipype/algorithms/tests/test_normalize_tpms.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
# -*- coding: utf-8 -*-
33
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
44
# vi: set ft=python sts=4 ts=4 sw=4 et:
5-
#
6-
# @Author: oesteban - code@oscaresteban.es
7-
# @Date: 2014-05-28 17:57:20
8-
# @Last Modified by: oesteban
9-
# @Last Modified time: 2014-05-29 13:43:09
105

116
import os
127
from shutil import rmtree
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
import os
7+
from shutil import rmtree
8+
from tempfile import mkdtemp
9+
10+
from nipype.testing import (assert_equal, assert_raises,
11+
assert_almost_equal, example_data)
12+
13+
import numpy as np
14+
import nibabel as nb
15+
16+
17+
def test_overlap():
18+
from nipype.algorithms.metrics import Overlap
19+
20+
def check_close(val1, val2):
21+
import numpy.testing as npt
22+
return npt.assert_almost_equal(val1, val2, decimal=3)
23+
24+
tempdir = mkdtemp()
25+
in1 = example_data('segmentation0.nii.gz')
26+
in2 = example_data('segmentation1.nii.gz')
27+
28+
os.chdir(tempdir)
29+
overlap = Overlap()
30+
overlap.inputs.volume1 = in1
31+
overlap.inputs.volume2 = in1
32+
res = overlap.run()
33+
yield check_close, res.outputs.jaccard, 1.0
34+
overlap = Overlap()
35+
overlap.inputs.volume1 = in1
36+
overlap.inputs.volume2 = in2
37+
res = overlap.run()
38+
39+
yield check_close, res.outputs.jaccard, 0.99705
40+
41+
overlap = Overlap()
42+
overlap.inputs.volume1 = in1
43+
overlap.inputs.volume2 = in2
44+
overlap.inputs.vol_units = 'mm'
45+
res = overlap.run()
46+
47+
yield check_close, res.outputs.jaccard, 0.99705
48+
yield (check_close, res.outputs.roi_voldiff,
49+
np.array([0.0063086, -0.0025506, 0.0]))
50+
51+
rmtree(tempdir)
27.8 KB
Binary file not shown.
25.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)