1
1
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
2
2
# vi: set ft=python sts=4 ts=4 sw=4 et:
3
3
from nipype .testing import (assert_equal , assert_false , assert_true ,
4
- assert_raises , assert_almost_equal )
4
+ assert_almost_equal )
5
5
import nipype .algorithms .rapidart as ra
6
6
from nipype .interfaces .base import Bunch
7
- from tempfile import mkdtemp
8
- import os
9
- from shutil import rmtree
10
7
import numpy as np
11
8
9
+
12
10
def test_artifactdetect ():
13
- input_map = dict (intersect_mask = dict (),
14
- mask_file = dict (),
15
- mask_threshold = dict (),
16
- mask_type = dict (),
17
- norm_threshold = dict (),
18
- parameter_source = dict (mandatory = True ,),
19
- realigned_files = dict (mandatory = True ,),
20
- realignment_parameters = dict (),
21
- rotation_threshold = dict (),
22
- translation_threshold = dict (),
23
- use_differences = dict (usedefault = True ,),
24
- use_norm = dict (usedefault = True ,),
25
- zintensity_threshold = dict (),
11
+ input_map = dict (intersect_mask = dict (),
12
+ mask_file = dict (),
13
+ mask_threshold = dict (),
14
+ mask_type = dict (),
15
+ norm_threshold = dict (),
16
+ parameter_source = dict (mandatory = True ,),
17
+ realigned_files = dict (mandatory = True ,),
18
+ realignment_parameters = dict (),
19
+ rotation_threshold = dict (),
20
+ translation_threshold = dict (),
21
+ use_differences = dict (usedefault = True ,),
22
+ use_norm = dict (usedefault = True ,),
23
+ zintensity_threshold = dict (),
26
24
)
27
25
instance = ra .ArtifactDetect ()
28
26
for key , metadata in input_map .items ():
29
27
for metakey , value in metadata .items ():
30
28
yield assert_equal , getattr (instance .inputs .traits ()[key ], metakey ), value
31
29
30
+
32
31
def test_stimuluscorrelation ():
33
- input_map = dict (concatenated_design = dict (mandatory = True ,),
34
- intensity_values = dict (mandatory = True ,),
35
- realignment_parameters = dict (mandatory = True ,),
36
- spm_mat_file = dict (mandatory = True ,),
32
+ input_map = dict (concatenated_design = dict (mandatory = True ,),
33
+ intensity_values = dict (mandatory = True ,),
34
+ realignment_parameters = dict (mandatory = True ,),
35
+ spm_mat_file = dict (mandatory = True ,),
37
36
)
38
37
instance = ra .StimulusCorrelation ()
39
38
for key , metadata in input_map .items ():
40
39
for metakey , value in metadata .items ():
41
40
yield assert_equal , getattr (instance .inputs .traits ()[key ], metakey ), value
42
41
42
+
43
43
def test_ad_init ():
44
- ad = ra .ArtifactDetect (use_differences = [True ,False ])
44
+ ad = ra .ArtifactDetect (use_differences = [True , False ])
45
45
yield assert_true , ad .inputs .use_differences [0 ]
46
46
yield assert_false , ad .inputs .use_differences [1 ]
47
47
48
+
48
49
def test_ad_output_filenames ():
49
50
ad = ra .ArtifactDetect ()
50
51
outputdir = '/tmp'
51
52
f = 'motion.nii'
52
- outlierfile ,intensityfile ,statsfile ,normfile ,plotfile = ad ._get_output_filenames (f ,outputdir )
53
+ outlierfile , intensityfile , statsfile , normfile , plotfile = ad ._get_output_filenames (f , outputdir )
53
54
yield assert_equal , outlierfile , '/tmp/art.motion_outliers.txt'
54
55
yield assert_equal , intensityfile , '/tmp/global_intensity.motion.txt'
55
56
yield assert_equal , statsfile , '/tmp/stats.motion.txt'
56
57
yield assert_equal , normfile , '/tmp/norm.motion.txt'
57
58
yield assert_equal , plotfile , '/tmp/plot.motion.png'
58
59
60
+
59
61
def test_ad_get_affine_matrix ():
60
62
ad = ra .ArtifactDetect ()
61
63
matrix = ad ._get_affine_matrix (np .array ([0 ]))
62
64
yield assert_equal , matrix , np .eye (4 )
63
65
# test translation
64
- params = [1 ,2 , 3 ]
66
+ params = [1 , 2 , 3 ]
65
67
matrix = ad ._get_affine_matrix (params )
66
68
out = np .eye (4 )
67
- out [0 :3 ,3 ] = params
69
+ out [0 :3 , 3 ] = params
68
70
yield assert_equal , matrix , out
69
71
# test rotation
70
- params = np .array ([0 ,0 , 0 , np .pi / 2 , np .pi / 2 , np .pi / 2 ])
72
+ params = np .array ([0 , 0 , 0 , np .pi / 2 , np .pi / 2 , np .pi / 2 ])
71
73
matrix = ad ._get_affine_matrix (params )
72
- out = np .array ([0 ,0 , 1 , 0 , 0 , - 1 ,0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ]).reshape ((4 ,4 ))
74
+ out = np .array ([0 , 0 , 1 , 0 , 0 , - 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ]).reshape ((4 , 4 ))
73
75
yield assert_almost_equal , matrix , out
74
76
# test scaling
75
- params = np .array ([0 ,0 , 0 , 0 , 0 , 0 , 1 , 2 , 3 ])
77
+ params = np .array ([0 , 0 , 0 , 0 , 0 , 0 , 1 , 2 , 3 ])
76
78
matrix = ad ._get_affine_matrix (params )
77
- out = np .array ([1 ,0 , 0 , 0 , 0 , 2 , 0 , 0 , 0 , 0 , 3 , 0 , 0 , 0 , 0 , 1 ]).reshape ((4 ,4 ))
79
+ out = np .array ([1 , 0 , 0 , 0 , 0 , 2 , 0 , 0 , 0 , 0 , 3 , 0 , 0 , 0 , 0 , 1 ]).reshape ((4 , 4 ))
78
80
yield assert_equal , matrix , out
79
81
# test shear
80
- params = np .array ([0 ,0 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 2 , 3 ])
82
+ params = np .array ([0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 2 , 3 ])
81
83
matrix = ad ._get_affine_matrix (params )
82
- out = np .array ([1 ,1 , 2 , 0 , 0 , 1 , 3 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 ]).reshape ((4 ,4 ))
84
+ out = np .array ([1 , 1 , 2 , 0 , 0 , 1 , 3 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 ]).reshape ((4 , 4 ))
83
85
yield assert_equal , matrix , out
84
86
87
+
85
88
def test_ad_get_norm ():
86
89
ad = ra .ArtifactDetect ()
87
- params = np .array ([0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,np .pi / 4 ,np .pi / 4 ,np .pi / 4 ,0 ,0 ,0 ,- np .pi / 4 ,- np .pi / 4 ,- np .pi / 4 ]).reshape ((3 ,6 ))
88
- norm = ad ._calc_norm (params ,False )
89
- yield assert_almost_equal , norm , np .array ([18.86436316 , 37.74610158 , 31.29780829 ])
90
- norm = ad ._calc_norm (params ,True )
91
- yield assert_almost_equal , norm , np .array ([ 0. , 143.72192614 , 173.92527131 ])
90
+ params = np .array ([0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , np .pi / 4 , np .pi / 4 ,
91
+ np .pi / 4 , 0 , 0 , 0 , - np .pi / 4 ,
92
+ - np .pi / 4 , - np .pi / 4 ]).reshape ((3 , 6 ))
93
+ norm = ad ._calc_norm (params , False )
94
+ yield assert_almost_equal , norm , np .array ([18.86436316 , 37.74610158 , 31.29780829 ])
95
+ norm = ad ._calc_norm (params , True )
96
+ yield assert_almost_equal , norm , np .array ([0. , 143.72192614 , 173.92527131 ])
97
+
92
98
93
99
def test_sc_init ():
94
100
sc = ra .StimulusCorrelation (concatenated_design = True )
95
101
yield assert_true , sc .inputs .concatenated_design
96
102
103
+
97
104
def test_sc_populate_inputs ():
98
105
sc = ra .StimulusCorrelation ()
99
106
inputs = Bunch (realignment_parameters = None ,
@@ -102,10 +109,10 @@ def test_sc_populate_inputs():
102
109
concatenated_design = None )
103
110
yield assert_equal , sc .inputs .__dict__ .keys (), inputs .__dict__ .keys ()
104
111
112
+
105
113
def test_sc_output_filenames ():
106
114
sc = ra .StimulusCorrelation ()
107
115
outputdir = '/tmp'
108
116
f = 'motion.nii'
109
- corrfile = sc ._get_output_filenames (f ,outputdir )
117
+ corrfile = sc ._get_output_filenames (f , outputdir )
110
118
yield assert_equal , corrfile , '/tmp/qa.motion_stimcorr.txt'
111
-
0 commit comments