5
5
import numpy as np
6
6
import nibabel as nb
7
7
from nipype .algorithms .stats import ActivationCount
8
+ import pytest
8
9
9
10
10
11
def test_ActivationCount (tmpdir ):
@@ -20,3 +21,23 @@ def test_ActivationCount(tmpdir):
20
21
pos = nb .load (res .outputs .acm_pos )
21
22
neg = nb .load (res .outputs .acm_neg )
22
23
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