@@ -412,6 +412,11 @@ class CompCorInputSpec(BaseInterfaceInputSpec):
412
412
low = 0 ,
413
413
usedefault = True ,
414
414
desc = 'Number of volumes at start of series to ignore' )
415
+ failure_mode = traits .Enum (
416
+ 'error' , 'NaN' ,
417
+ usedefault = True ,
418
+ desc = 'When no components are found or convergence fails, raise an error '
419
+ 'or silently return columns of NaNs.' )
415
420
416
421
417
422
class CompCorOutputSpec (TraitedSpec ):
@@ -1185,13 +1190,20 @@ def compute_noise_components(imgseries, mask_images, num_components,
1185
1190
1186
1191
# "The covariance matrix C = MMT was constructed and decomposed into its
1187
1192
# principal components using a singular value decomposition."
1188
- u , _ , _ = np .linalg .svd (M , full_matrices = False )
1193
+ try :
1194
+ u , _ , _ = np .linalg .svd (M , full_matrices = False )
1195
+ except np .linalg .LinAlgError :
1196
+ if self .inputs .failure_mode == 'error' :
1197
+ raise
1198
+ u = np .ones ((M .shape [0 ], num_components ), dtype = np .float32 ) * np .nan
1189
1199
if components is None :
1190
1200
components = u [:, :num_components ]
1191
1201
else :
1192
1202
components = np .hstack ((components , u [:, :num_components ]))
1193
1203
if components is None and num_components > 0 :
1194
- raise ValueError ('No components found' )
1204
+ if self .inputs .failure_mode == 'error' :
1205
+ raise ValueError ('No components found' )
1206
+ components = np .ones ((M .shape [0 ], num_components ), dtype = np .float32 ) * np .nan
1195
1207
return components , basis
1196
1208
1197
1209
0 commit comments