Skip to content

Commit 668cf8a

Browse files
committed
fix: sidestep Undefined issue
1 parent 164a78e commit 668cf8a

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

nipype/algorithms/confounds.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,11 @@ class CompCorInputSpec(BaseInterfaceInputSpec):
308308
mask_files = InputMultiPath(File(exists=True,
309309
desc='One or more mask files that determines ROI (3D)'))
310310
merge_method = traits.Enum('union', 'intersect', 'none', xor=['mask_index'],
311+
requires=['mask_files'],
311312
desc='Merge method if multiple masks are present - `union` aggregates '
312313
'all masks, `intersect` computes the truth value of all masks, `none` '
313314
'performs CompCor on each mask individually')
314-
mask_index = traits.Range(0, value=0, xor=['merge_method'], usedefault=True,
315+
mask_index = traits.Range(0, xor=['merge_method'], requires=['mask_files'],
315316
desc='Position of mask in `mask_files` to use - first is the default')
316317
components_file = File('components_file.txt', exists=False, usedefault=True,
317318
desc='filename to store physiological components')
@@ -364,6 +365,11 @@ def _run_interface(self, runtime, tCompCor_mask=False):
364365
mmap=NUMPY_MMAP).get_data()
365366
components = None
366367

368+
if isdefined(self.inputs.mask_files) or isdefined(self.inputs.mask_file):
369+
if (not isdefined(self.inputs.mask_index) and
370+
not isdefined(self.inputs.merge_method)):
371+
self.inputs.mask_index = 0
372+
367373
if isdefined(self.inputs.mask_index):
368374
if self.inputs.mask_index < len(self.inputs.mask_files):
369375
self.inputs.mask_files = [
@@ -519,6 +525,9 @@ def _run_interface(self, runtime):
519525
imgseries.shape))
520526

521527
if isdefined(self.inputs.mask_files):
528+
if (not isdefined(self.inputs.mask_index) and
529+
not isdefined(self.inputs.merge_method)):
530+
self.inputs.mask_index = 0
522531
if isdefined(self.inputs.mask_index):
523532
if self.inputs.mask_index < len(self.inputs.mask_files):
524533
self.inputs.mask_files = [

nipype/algorithms/tests/test_compcor.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ def test_tcompcor_merge_intersect_masks(self):
110110
for method in ['union', 'intersect']:
111111
TCompCor(realigned_file=self.realigned_file,
112112
mask_files=self.mask_files,
113-
merge_method=method,
114-
mask_index=Undefined).run()
113+
merge_method=method).run()
115114
if method == 'union':
116115
assert np.array_equal(nb.load('mask.nii').get_data(),
117116
([[[0,0],[0,0]],[[0,0],[1,0]]]))
@@ -120,7 +119,6 @@ def test_tcompcor_merge_intersect_masks(self):
120119
([[[0,0],[0,0]],[[0,1],[0,0]]]))
121120

122121
def test_tcompcor_index_mask(self):
123-
print(len(self.mask_files))
124122
TCompCor(realigned_file=self.realigned_file,
125123
mask_files=self.mask_files,
126124
mask_index=1).run()

0 commit comments

Comments
 (0)