55import numpy as np
66import nibabel as nb
77from nipype .algorithms .stats import ActivationCount
8+ import pytest
89
910
1011def 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 = (100 , 100 , 100 )),
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-4 )
43+ assert np .isclose (neg .get_data ().mean (), above_thresh * 1.e-2 , rtol = 0.1 , atol = 1.e-4 )
0 commit comments