@@ -400,7 +400,7 @@ class CompCorInputSpec(BaseInterfaceInputSpec):
400
400
'components_file.txt' ,
401
401
usedefault = True ,
402
402
desc = 'Filename to store physiological components' )
403
- num_components = traits .Either ('all' , traits .Int ,
403
+ num_components = traits .Either ('all' , traits .Range ( low = 1 ) ,
404
404
xor = ['variance_threshold' ],
405
405
desc = 'Number of components to return from the decomposition. If '
406
406
'`num_components` is `all`, then all components will be '
@@ -1280,34 +1280,36 @@ def compute_noise_components(imgseries, mask_images, components_criterion=0.5,
1280
1280
try :
1281
1281
u , s , _ = fallback_svd (M , full_matrices = False )
1282
1282
except np .linalg .LinAlgError :
1283
- if self . inputs . failure_mode == 'error' :
1283
+ if failure_mode == 'error' :
1284
1284
raise
1285
1285
if components_criterion >= 1 :
1286
1286
u = np .empty ((M .shape [0 ], components_criterion ),
1287
1287
dtype = np .float32 ) * np .nan
1288
1288
else :
1289
1289
continue
1290
1290
1291
- variance_explained = np . array ( [value ** 2 / np .sum (s ** 2 ) for value in s ])
1291
+ variance_explained = [value ** 2 / np .sum (s ** 2 ) for value in s ]
1292
1292
cumulative_variance_explained = np .cumsum (variance_explained )
1293
+
1294
+ num_components = int (components_criterion )
1293
1295
if 0 < components_criterion < 1 :
1294
1296
num_components = np .searchsorted (cumulative_variance_explained ,
1295
1297
components_criterion ) + 1
1296
1298
elif components_criterion == - 1 :
1297
1299
num_components = len (s )
1298
- else :
1299
- num_components = int (components_criterion )
1300
+
1301
+ num_components = int (num_components )
1302
+ # check whether num_components == 0, break if so
1300
1303
if components is None :
1301
1304
components = u [:, :num_components ]
1302
1305
metadata = OrderedDict ()
1303
- metadata ['mask' ] = np . array ( [i ] * len (s ) )
1306
+ metadata ['mask' ] = [i ] * len (s )
1304
1307
metadata ['singular_value' ] = s
1305
1308
metadata ['variance_explained' ] = variance_explained
1306
1309
metadata ['cumulative_variance_explained' ] = (
1307
1310
cumulative_variance_explained )
1308
- metadata ['retained' ] = np .array (
1309
- [True if i < num_components
1310
- else False for i in range (len (s ))], dtype = 'bool' )
1311
+ metadata ['retained' ] = [
1312
+ i < num_components for i in range (len (s ))]
1311
1313
else :
1312
1314
components = np .hstack ((components , u [:, :num_components ]))
1313
1315
metadata ['mask' ] = np .hstack ((metadata ['mask' ],
@@ -1324,8 +1326,8 @@ def compute_noise_components(imgseries, mask_images, components_criterion=0.5,
1324
1326
[True if i < num_components
1325
1327
else False
1326
1328
for i in range (len (s ))]))
1327
- if components is None and num_components != 0 :
1328
- if self . inputs . failure_mode == 'error' :
1329
+ if components is None :
1330
+ if failure_mode == 'error' :
1329
1331
raise ValueError ('No components found' )
1330
1332
components = np .ones ((M .shape [0 ], num_components ),
1331
1333
dtype = np .float32 ) * np .nan
0 commit comments