@@ -1082,10 +1082,11 @@ def is_outlier(points, thresh=3.5):
10821082 return timepoints_to_discard
10831083
10841084
1085- def cosine_filter (data , timestep , period_cut , remove_mean = True , axis = - 1 ):
1085+ def cosine_filter (data , timestep , period_cut , remove_mean = True , axis = - 1 ,
1086+ failure_mode = 'error' ):
10861087 datashape = data .shape
10871088 timepoints = datashape [axis ]
1088- if datashape [0 ] == 0 :
1089+ if datashape [0 ] == 0 and failure_mode != 'error' :
10891090 return data , np .array ([])
10901091
10911092 data = data .reshape ((- 1 , timepoints ))
@@ -1105,7 +1106,8 @@ def cosine_filter(data, timestep, period_cut, remove_mean=True, axis=-1):
11051106 return residuals .reshape (datashape ), non_constant_regressors
11061107
11071108
1108- def regress_poly (degree , data , remove_mean = True , axis = - 1 ):
1109+ def regress_poly (degree , data , remove_mean = True , axis = - 1 ,
1110+ failure_mode = 'error' ):
11091111 """
11101112 Returns data with degree polynomial regressed out.
11111113
@@ -1118,7 +1120,7 @@ def regress_poly(degree, data, remove_mean=True, axis=-1):
11181120
11191121 datashape = data .shape
11201122 timepoints = datashape [axis ]
1121- if datashape [0 ] == 0 :
1123+ if datashape [0 ] == 0 and failure_mode != 'error' :
11221124 return data , np .array ([])
11231125
11241126 # Rearrange all voxel-wise time-series in rows
@@ -1285,12 +1287,14 @@ def compute_noise_components(imgseries, mask_images, components_criterion=0.5,
12851287 raise ValueError (
12861288 'Repetition time must be provided for cosine filter' )
12871289 voxel_timecourses , basis = cosine_filter (
1288- voxel_timecourses , repetition_time , period_cut )
1290+ voxel_timecourses , repetition_time , period_cut ,
1291+ failure_mode = failure_mode )
12891292 elif filter_type in ('polynomial' , False ):
12901293 # from paper:
12911294 # "The constant and linear trends of the columns in the matrix M were
12921295 # removed [prior to ...]"
1293- voxel_timecourses , basis = regress_poly (degree , voxel_timecourses )
1296+ voxel_timecourses , basis = regress_poly (degree , voxel_timecourses ,
1297+ failure_mode = failure_mode )
12941298
12951299 # "Voxel time series from the noise ROI (either anatomical or tSTD) were
12961300 # placed in a matrix M of size Nxm, with time along the row dimension
0 commit comments