Skip to content

Commit 37c7895

Browse files
committed
RF: NilearnBaseInterface
1 parent 2723c61 commit 37c7895

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

nipype/interfaces/nilearn.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
import numpy as np
1212
import nibabel as nb
1313

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'
1821

1922

2023
class SignalExtractionInputSpec(BaseInterfaceInputSpec):
@@ -70,7 +73,7 @@ class SignalExtractionOutputSpec(TraitedSpec):
7073
'header row with values from class_labels')
7174

7275

73-
class SignalExtraction(BaseInterface):
76+
class SignalExtraction(NilearnBaseInterface, SimpleInterface):
7477
'''
7578
Extracts signals over tissue classes or brain regions
7679
@@ -85,7 +88,6 @@ class SignalExtraction(BaseInterface):
8588
'''
8689
input_spec = SignalExtractionInputSpec
8790
output_spec = SignalExtractionOutputSpec
88-
_results = {}
8991

9092
def _run_interface(self, runtime):
9193
maskers = self._process_inputs()
@@ -99,14 +101,16 @@ def _run_interface(self, runtime):
99101
region_signals.astype(str)))
100102

101103
# 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)
103106
np.savetxt(
104107
self._results['out_file'], output, fmt=b'%s', delimiter='\t')
105108
return runtime
106109

107110
def _process_inputs(self):
108111
''' 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.'''
110114
import nilearn.input_data as nl
111115
import nilearn.image as nli
112116

@@ -119,12 +123,12 @@ def _process_inputs(self):
119123
maskers.append(nl.NiftiLabelsMasker(label_data))
120124
else: # 4d labels
121125
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
123127
for img in nli.iter_img(label_data):
124128
maskers.append(
125129
nl.NiftiMapsMasker(
126130
self._4d(img.get_data(), img.affine)))
127-
else: # 4d labels, one computation fitting all
131+
else: # one computation fitting all
128132
maskers.append(nl.NiftiMapsMasker(label_data))
129133

130134
# check label list size
@@ -160,6 +164,3 @@ def _4d(self, array, affine):
160164
''' takes a 3-dimensional numpy array and an affine,
161165
returns the equivalent 4th dimensional nifti file '''
162166
return nb.Nifti1Image(array[:, :, :, np.newaxis], affine)
163-
164-
def _list_outputs(self):
165-
return self._results

0 commit comments

Comments
 (0)