25
25
class SignalExtractionInputSpec (BaseInterfaceInputSpec ):
26
26
in_file = File (exists = True , mandatory = True , desc = '4-D fMRI nii file' )
27
27
label_files = InputMultiPath (File (exists = True ), mandatory = True ,
28
- desc = 'a 3-D label image, with 0 denoting '
29
- 'background, or a list of 3-D probability '
30
- 'maps (one per label) or the equivalent 4D '
31
- 'file.' )
28
+ desc = 'a 3-D label image, with 0 denoting '
29
+ 'background, or a list of 3-D probability '
30
+ 'maps (one per label) or the equivalent 4D '
31
+ 'file.' )
32
32
class_labels = traits .List (mandatory = True ,
33
33
desc = 'Human-readable labels for each segment '
34
34
'in the label file, in order. The length of '
@@ -43,12 +43,12 @@ class SignalExtractionInputSpec(BaseInterfaceInputSpec):
43
43
'(True), returns simple time series calculated from each '
44
44
'region independently (e.g., for noise regression). If '
45
45
'False, returns unique signals for each region, discarding '
46
- 'shared variance (e.g., for connectivity)' )
46
+ 'shared variance (e.g., for connectivity. Only has effect '
47
+ 'with 4D probability maps.' )
47
48
include_global = traits .Bool (False , usedefault = True , mandatory = False ,
48
49
desc = 'If True, include an extra column '
49
50
'labeled "global", with values calculated from the entire brain '
50
- '(instead of just regions). Only has effect with 4D probability '
51
- 'maps.' )
51
+ '(instead of just regions).' )
52
52
detrend = traits .Bool (False , usedefault = True , mandatory = False ,
53
53
desc = 'If True, perform detrending using nilearn.' )
54
54
@@ -105,8 +105,7 @@ def _process_inputs(self):
105
105
n_labels = label_data .get_data ().shape [3 ]
106
106
if self .inputs .incl_shared_variance : # 4d labels, independent computation
107
107
for img in nli .iter_img (label_data ):
108
- sortof_4d_img = nb .Nifti1Image (img .get_data ()[:, :, :, np .newaxis ], np .eye (4 ))
109
- maskers .append (nl .NiftiMapsMasker (sortof_4d_img ))
108
+ maskers .append (nl .NiftiMapsMasker (self ._4d (img .get_data (), img .affine )))
110
109
else : # 4d labels, one computation fitting all
111
110
maskers .append (nl .NiftiMapsMasker (label_data ))
112
111
@@ -115,15 +114,14 @@ def _process_inputs(self):
115
114
raise ValueError ('The length of class_labels {} does not '
116
115
'match the number of regions {} found in '
117
116
'label_files {}' .format (self .inputs .class_labels ,
118
- n_labels ,
119
- self .inputs .label_files ))
117
+ n_labels ,
118
+ self .inputs .label_files ))
120
119
121
120
if self .inputs .include_global :
122
- global_label_data = label_data .get_data ().sum (axis = 3 )
123
- global_label_data = np .rint (global_label_data ).astype (int ).clip (0 , 1 )
124
- global_label_data = global_label_data [:, :, :, np .newaxis ] # add back 4th dimension
125
- global_label_data = nb .Nifti1Image (global_label_data , np .eye (4 ))
126
- global_masker = nl .NiftiMapsMasker (global_label_data , detrend = self .inputs .detrend )
121
+ global_label_data = label_data .get_data ().sum (axis = 3 ) # sum across all regions
122
+ global_label_data = np .rint (global_label_data ).astype (int ).clip (0 , 1 ) # binarize
123
+ global_label_data = self ._4d (global_label_data , label_data .affine )
124
+ global_masker = nl .NiftiLabelsMasker (global_label_data , detrend = self .inputs .detrend )
127
125
maskers .insert (0 , global_masker )
128
126
self .inputs .class_labels .insert (0 , 'global' )
129
127
@@ -132,6 +130,11 @@ def _process_inputs(self):
132
130
133
131
return maskers
134
132
133
+ def _4d (self , array , affine ):
134
+ ''' takes a 3-dimensional numpy array and an affine,
135
+ returns the equivalent 4th dimensional nifti file '''
136
+ return nb .Nifti1Image (array [:, :, :, np .newaxis ], affine )
137
+
135
138
def _list_outputs (self ):
136
139
outputs = self ._outputs ().get ()
137
140
outputs ['out_file' ] = self .inputs .out_file
0 commit comments