@@ -369,61 +369,60 @@ def _run_interface(self, runtime):
369
369
' {} instead' ).format (self .inputs .mask_files [0 ])
370
370
self .inputs .mask_files = self .inputs .mask_files [0 ]
371
371
372
- if isdefined (self .inputs .mask_files ):
373
- for mask_file in self .inputs .mask_files :
374
- mask = nb .load (mask_file , mmap = NUMPY_MMAP ).get_data ()
375
-
376
- if imgseries .shape [:3 ] != mask .shape :
377
- raise ValueError ('Inputs for CompCor, func {} and mask {}, '
378
- 'do not have matching spatial dimensions '
379
- '({} and {}, respectively)' .format (
380
- self .inputs .realigned_file , mask_file ,
381
- imgseries .shape [:3 ], mask .shape ))
372
+ for mask_file in self .inputs .mask_files :
373
+ mask = nb .load (mask_file , mmap = NUMPY_MMAP ).get_data ()
374
+
375
+ if imgseries .shape [:3 ] != mask .shape :
376
+ raise ValueError ('Inputs for CompCor, func {} and mask {}, '
377
+ 'do not have matching spatial dimensions '
378
+ '({} and {}, respectively)' .format (
379
+ self .inputs .realigned_file , mask_file ,
380
+ imgseries .shape [:3 ], mask .shape ))
381
+
382
+ if (isdefined (self .inputs .merge_method ) and
383
+ self .merge_method != 'none' and
384
+ len (self .inputs .mask_files > 1 )):
385
+ if mask_file == self .inputs .mask_files [0 ]:
386
+ new_mask = mask
387
+ continue
388
+ else :
389
+ if self .inputs .merge_method == 'union' :
390
+ new_mask = np .logical_or (new_mask , mask ).astype (int )
391
+ elif self .inputs .merge_method == 'intersect' :
392
+ new_mask = np .logical_and (new_mask , mask ).astype (int )
382
393
383
- if (isdefined (self .inputs .merge_method ) and
384
- self .merge_method != 'none' and
385
- len (self .inputs .mask_files > 1 )):
386
- if mask_file == self .inputs .mask_files [0 ]:
387
- new_mask = mask
394
+ if mask_file != self .inputs .mask_files [- 1 ]:
388
395
continue
389
- else :
390
- if self .inputs .merge_method == 'union' :
391
- new_mask = np .logical_or (new_mask , mask ).astype (int )
392
- elif self .inputs .merge_method == 'intersect' :
393
- new_mask = np .logical_and (new_mask , mask ).astype (int )
394
-
395
- if mask_file != self .inputs .mask_files [- 1 ]:
396
- continue
397
- else : # merge complete
398
- mask = new_mask
399
-
400
- voxel_timecourses = imgseries [mask > 0 ]
401
- # Zero-out any bad values
402
- voxel_timecourses [np .isnan (np .sum (voxel_timecourses , axis = 1 )), :] = 0
403
-
404
- # from paper:
405
- # "The constant and linear trends of the columns in the matrix M were
406
- # removed [prior to ...]"
407
- degree = (self .inputs .regress_poly_degree if
408
- self .inputs .use_regress_poly else 0 )
409
- voxel_timecourses = regress_poly (degree , voxel_timecourses )
410
-
411
- # "Voxel time series from the noise ROI (either anatomical or tSTD) were
412
- # placed in a matrix M of size Nxm, with time along the row dimension
413
- # and voxels along the column dimension."
414
- M = voxel_timecourses .T
415
-
416
- # "[... were removed] prior to column-wise variance normalization."
417
- M = M / self ._compute_tSTD (M , 1. )
418
-
419
- # "The covariance matrix C = MMT was constructed and decomposed into its
420
- # principal components using a singular value decomposition."
421
- u , _ , _ = linalg .svd (M , full_matrices = False )
422
- if components is None :
423
- components = u [:, :self .inputs .num_components ]
424
- else :
425
- components = np .hstack ((components ,
426
- u [:, :self .inputs .num_components ]))
396
+ else : # merge complete
397
+ mask = new_mask
398
+
399
+ voxel_timecourses = imgseries [mask > 0 ]
400
+ # Zero-out any bad values
401
+ voxel_timecourses [np .isnan (np .sum (voxel_timecourses , axis = 1 )), :] = 0
402
+
403
+ # from paper:
404
+ # "The constant and linear trends of the columns in the matrix M were
405
+ # removed [prior to ...]"
406
+ degree = (self .inputs .regress_poly_degree if
407
+ self .inputs .use_regress_poly else 0 )
408
+ voxel_timecourses = regress_poly (degree , voxel_timecourses )
409
+
410
+ # "Voxel time series from the noise ROI (either anatomical or tSTD) were
411
+ # placed in a matrix M of size Nxm, with time along the row dimension
412
+ # and voxels along the column dimension."
413
+ M = voxel_timecourses .T
414
+
415
+ # "[... were removed] prior to column-wise variance normalization."
416
+ M = M / self ._compute_tSTD (M , 1. )
417
+
418
+ # "The covariance matrix C = MMT was constructed and decomposed into its
419
+ # principal components using a singular value decomposition."
420
+ u , _ , _ = linalg .svd (M , full_matrices = False )
421
+ if components is None :
422
+ components = u [:, :self .inputs .num_components ]
423
+ else :
424
+ components = np .hstack ((components ,
425
+ u [:, :self .inputs .num_components ]))
427
426
428
427
components_file = os .path .join (os .getcwd (), self .inputs .components_file )
429
428
self ._set_header ()
0 commit comments