11
11
import numpy as np
12
12
import nibabel as nb
13
13
14
- from .. import logging
15
- from ..interfaces .base import (traits , TraitedSpec , BaseInterface ,
16
- BaseInterfaceInputSpec , File , InputMultiPath )
17
- IFLOGGER = logging .getLogger ('interface' )
14
+ from ..interfaces .base import (traits , TraitedSpec , LibraryBaseInterface ,
15
+ SimpleInterface , BaseInterfaceInputSpec , File ,
16
+ InputMultiPath )
17
+
18
+
19
+ class NilearnBaseInterface (LibraryBaseInterface ):
20
+ _pkg = 'nilearn'
18
21
19
22
20
23
class SignalExtractionInputSpec (BaseInterfaceInputSpec ):
@@ -70,7 +73,7 @@ class SignalExtractionOutputSpec(TraitedSpec):
70
73
'header row with values from class_labels' )
71
74
72
75
73
- class SignalExtraction (BaseInterface ):
76
+ class SignalExtraction (NilearnBaseInterface , SimpleInterface ):
74
77
'''
75
78
Extracts signals over tissue classes or brain regions
76
79
@@ -85,7 +88,6 @@ class SignalExtraction(BaseInterface):
85
88
'''
86
89
input_spec = SignalExtractionInputSpec
87
90
output_spec = SignalExtractionOutputSpec
88
- _results = {}
89
91
90
92
def _run_interface (self , runtime ):
91
93
maskers = self ._process_inputs ()
@@ -99,14 +101,16 @@ def _run_interface(self, runtime):
99
101
region_signals .astype (str )))
100
102
101
103
# save output
102
- self ._results ['out_file' ] = os .path .join (runtime .cwd , self .inputs .out_file )
104
+ self ._results ['out_file' ] = os .path .join (runtime .cwd ,
105
+ self .inputs .out_file )
103
106
np .savetxt (
104
107
self ._results ['out_file' ], output , fmt = b'%s' , delimiter = '\t ' )
105
108
return runtime
106
109
107
110
def _process_inputs (self ):
108
111
''' validate and process inputs into useful form.
109
- Returns a list of nilearn maskers and the list of corresponding label names.'''
112
+ Returns a list of nilearn maskers and the list of corresponding label
113
+ names.'''
110
114
import nilearn .input_data as nl
111
115
import nilearn .image as nli
112
116
@@ -119,12 +123,12 @@ def _process_inputs(self):
119
123
maskers .append (nl .NiftiLabelsMasker (label_data ))
120
124
else : # 4d labels
121
125
n_labels = label_data .get_data ().shape [3 ]
122
- if self .inputs .incl_shared_variance : # 4d labels, independent computation
126
+ if self .inputs .incl_shared_variance : # independent computation
123
127
for img in nli .iter_img (label_data ):
124
128
maskers .append (
125
129
nl .NiftiMapsMasker (
126
130
self ._4d (img .get_data (), img .affine )))
127
- else : # 4d labels, one computation fitting all
131
+ else : # one computation fitting all
128
132
maskers .append (nl .NiftiMapsMasker (label_data ))
129
133
130
134
# check label list size
@@ -160,6 +164,3 @@ def _4d(self, array, affine):
160
164
''' takes a 3-dimensional numpy array and an affine,
161
165
returns the equivalent 4th dimensional nifti file '''
162
166
return nb .Nifti1Image (array [:, :, :, np .newaxis ], affine )
163
-
164
- def _list_outputs (self ):
165
- return self ._results
0 commit comments