File tree Expand file tree Collapse file tree 2 files changed +28
-7
lines changed Expand file tree Collapse file tree 2 files changed +28
-7
lines changed Original file line number Diff line number Diff line change 13
13
'''
14
14
from __future__ import (print_function , division , unicode_literals ,
15
15
absolute_import )
16
- from builtins import str
17
16
18
17
import numpy as np
19
18
@@ -71,11 +70,7 @@ def _run_interface(self, runtime):
71
70
ins = self .inputs
72
71
73
72
if ins .stat == 'mean' : # always true for now
74
- nlmasker = nl .NiftiLabelsMasker (ins .label_file ,
75
- detrend = ins .detrend )
76
- nlmasker .fit ()
77
- region_signals = nlmasker .transform_single_imgs (ins .in_file )
78
-
73
+ region_signals = self ._3d_label_handler (nl , ins )
79
74
num_labels_found = region_signals .shape [1 ]
80
75
if len (ins .class_labels ) != num_labels_found :
81
76
raise ValueError ('The length of class_labels {} does not '
@@ -90,6 +85,13 @@ def _run_interface(self, runtime):
90
85
np .savetxt (ins .out_file , output , fmt = b'%s' , delimiter = '\t ' )
91
86
return runtime
92
87
88
+ def _3d_label_handler (self , nl , ins ):
89
+ nlmasker = nl .NiftiLabelsMasker (ins .label_file ,
90
+ detrend = ins .detrend )
91
+ nlmasker .fit ()
92
+ region_signals = nlmasker .transform_single_imgs (ins .in_file )
93
+ return region_signals
94
+
93
95
def _list_outputs (self ):
94
96
outputs = self ._outputs ().get ()
95
97
outputs ['out_file' ] = self .inputs .out_file
Original file line number Diff line number Diff line change 13
13
14
14
no_nilearn = True
15
15
try :
16
- import nilearn
16
+ __import__ ( ' nilearn' )
17
17
no_nilearn = False
18
18
except ImportError :
19
19
pass
@@ -23,6 +23,7 @@ class TestSignalExtraction(unittest.TestCase):
23
23
filenames = {
24
24
'in_file' : 'fmri.nii' ,
25
25
'label_file' : 'labels.nii' ,
26
+ '4d_label_file' : '4dlabels.nii' ,
26
27
'out_file' : 'signals.tsv'
27
28
}
28
29
@@ -70,6 +71,11 @@ def test_signal_extraction_bad_class_labels(self):
70
71
label_file = self .filenames ['label_file' ],
71
72
class_labels = ['bad' ]).run ()
72
73
74
+ @skipif (no_nilearn )
75
+ def test_signal_extraction_4d_label (self ):
76
+ # setup
77
+ utils .save_toy_nii (self .fake_4d_label_data , self .filenames ['4d_label_file' ])
78
+
73
79
def tearDown (self ):
74
80
os .chdir (self .orig_dir )
75
81
shutil .rmtree (self .temp_dir )
@@ -92,3 +98,16 @@ def tearDown(self):
92
98
93
99
[[2 , 0 ],
94
100
[1 , 3 ]]])
101
+
102
+ fake_4d_label_data = np .array ([[[[0.2 , 0.3 , 0.5 ],
103
+ [0.1 , 0.1 , 0.8 ]],
104
+
105
+ [[0.1 , 0.3 , 0.6 ],
106
+ [0.3 , 0.4 , 0.3 ]]],
107
+
108
+
109
+ [[[0.2 , 0.2 , 0.6 ],
110
+ [0. , 0.3 , 0.7 ]],
111
+
112
+ [[0.3 , 0.3 , 0.4 ],
113
+ [0.3 , 0.4 , 0.3 ]]]])
You can’t perform that action at this time.
0 commit comments