Skip to content

Commit 0c7c649

Browse files
author
Shoshana Berleant
committed
explicity check + error out if mask file and func file don't match in compcor
1 parent e811b96 commit 0c7c649

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

nipype/algorithms/confounds.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ class CompCor(BaseInterface):
330330
def _run_interface(self, runtime):
331331
imgseries = nb.load(self.inputs.realigned_file).get_data()
332332
mask = nb.load(self.inputs.mask_file).get_data()
333+
334+
if imgseries.shape[:3] != mask.shape:
335+
raise ValueError("Inputs for CompCor, func {} and mask {}, do not have matching '
336+
'spatial dimensions ({} and {}, respectively)"
337+
.format(self.inputs.realigned_file, self.inputs.mask_file,
338+
imgseries.shape[:3], mask.shape))
339+
333340
voxel_timecourses = imgseries[mask > 0]
334341
# Zero-out any bad values
335342
voxel_timecourses[np.isnan(np.sum(voxel_timecourses, axis=1)), :] = 0

nipype/algorithms/tests/test_compcor.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,17 @@ def test_tcompcor_asymmetric_dim(self):
7979
asymmetric_data = utils.save_toy_nii(np.zeros(asymmetric_shape), 'asymmetric.nii')
8080

8181
TCompCor(realigned_file=asymmetric_data).run()
82-
8382
self.assertEqual(nb.load('mask.nii').get_data().shape, asymmetric_shape[:3])
8483

84+
def test_compcor_bad_input_shapes(self):
85+
shape_less_than = (1, 2, 2, 5) # dim 0 is < dim 0 of self.mask_file (2)
86+
shape_more_than = (3, 3, 3, 5) # dim 0 is > dim 0 of self.mask_file (2)
87+
88+
for data_shape in (shape_less_than, shape_more_than):
89+
data_file = utils.save_toy_nii(np.zeros(data_shape), 'temp.nii')
90+
interface = CompCor(realigned_file=data_file, mask_file=self.mask_file)
91+
self.assertRaisesRegexp(ValueError, "dimensions", interface.run)
92+
8593
def run_cc(self, ccinterface, expected_components):
8694
# run
8795
ccresult = ccinterface.run()

0 commit comments

Comments
 (0)