Skip to content

Commit 6e53f01

Browse files
committed
adding tests that checks pos/neg for normal distribution
1 parent b126b70 commit 6e53f01

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

nipype/algorithms/tests/test_stats.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66
import nibabel as nb
77
from nipype.algorithms.stats import ActivationCount
8+
import pytest
89

910

1011
def test_ActivationCount(tmpdir):
@@ -20,3 +21,23 @@ def test_ActivationCount(tmpdir):
2021
pos = nb.load(res.outputs.acm_pos)
2122
neg = nb.load(res.outputs.acm_neg)
2223
assert np.allclose(diff.get_data(), pos.get_data() - neg.get_data())
24+
25+
26+
@pytest.mark.parametrize("threshold, above_thresh", [
27+
(1, 15.865), # above one standard deviation (one side)
28+
(2, 2.275), # above two standard deviations (one side)
29+
(3, 0.135) # above three standard deviations (one side)
30+
])
31+
def test_ActivationCount_normaldistr(tmpdir, threshold, above_thresh):
32+
tmpdir.chdir()
33+
in_files = ['{:d}.nii'.format(i) for i in range(3)]
34+
for fname in in_files:
35+
nb.Nifti1Image(np.random.normal(size=(50, 50, 50)),
36+
np.eye(4)).to_filename(fname)
37+
38+
acm = ActivationCount(in_files=in_files, threshold=threshold)
39+
res = acm.run()
40+
pos = nb.load(res.outputs.acm_pos)
41+
neg = nb.load(res.outputs.acm_neg)
42+
assert np.isclose(pos.get_data().mean(), above_thresh*1.e-2, rtol=0.1, atol=1.e-6)
43+
assert np.isclose(neg.get_data().mean(), above_thresh*1.e-2, rtol=0.1, atol=1.e-6)

0 commit comments

Comments
 (0)