@@ -136,20 +136,6 @@ def _calc_norm(mc, use_differences, source, brain_pts=None):
136
136
return normdata , displacement
137
137
138
138
139
- def _nanmean (a , axis = None ):
140
- """Return the mean excluding items that are nan
141
-
142
- >>> a = [1, 2, np.nan]
143
- >>> _nanmean(a)
144
- 1.5
145
-
146
- """
147
- if axis :
148
- return np .nansum (a , axis ) / np .sum (1 - np .isnan (a ), axis )
149
- else :
150
- return np .nansum (a ) / np .sum (1 - np .isnan (a ))
151
-
152
-
153
139
class ArtifactDetectInputSpec (BaseInterfaceInputSpec ):
154
140
realigned_files = InputMultiPath (File (exists = True ),
155
141
desc = "Names of realigned functional data files" ,
@@ -376,11 +362,11 @@ def _detect_outliers_core(self, imgfile, motionfile, runidx, cwd=None):
376
362
vol = data [:, :, :, t0 ]
377
363
# Use an SPM like approach
378
364
mask_tmp = vol > \
379
- (_nanmean (vol ) / self .inputs .global_threshold )
365
+ (np . nanmean (vol ) / self .inputs .global_threshold )
380
366
mask = mask * mask_tmp
381
367
for t0 in range (timepoints ):
382
368
vol = data [:, :, :, t0 ]
383
- g [t0 ] = _nanmean (vol [mask ])
369
+ g [t0 ] = np . nanmean (vol [mask ])
384
370
if len (find_indices (mask )) < (np .prod ((x , y , z )) / 10 ):
385
371
intersect_mask = False
386
372
g = np .zeros ((timepoints , 1 ))
@@ -390,7 +376,7 @@ def _detect_outliers_core(self, imgfile, motionfile, runidx, cwd=None):
390
376
for t0 in range (timepoints ):
391
377
vol = data [:, :, :, t0 ]
392
378
mask_tmp = vol > \
393
- (_nanmean (vol ) / self .inputs .global_threshold )
379
+ (np . nanmean (vol ) / self .inputs .global_threshold )
394
380
mask [:, :, :, t0 ] = mask_tmp
395
381
g [t0 ] = np .nansum (vol * mask_tmp ) / np .nansum (mask_tmp )
396
382
elif masktype == 'file' : # uses a mask image to determine intensity
@@ -400,15 +386,15 @@ def _detect_outliers_core(self, imgfile, motionfile, runidx, cwd=None):
400
386
mask = mask > 0.5
401
387
for t0 in range (timepoints ):
402
388
vol = data [:, :, :, t0 ]
403
- g [t0 ] = _nanmean (vol [mask ])
389
+ g [t0 ] = np . nanmean (vol [mask ])
404
390
elif masktype == 'thresh' : # uses a fixed signal threshold
405
391
for t0 in range (timepoints ):
406
392
vol = data [:, :, :, t0 ]
407
393
mask = vol > self .inputs .mask_threshold
408
- g [t0 ] = _nanmean (vol [mask ])
394
+ g [t0 ] = np . nanmean (vol [mask ])
409
395
else :
410
396
mask = np .ones ((x , y , z ))
411
- g = _nanmean (data [mask > 0 , :], 1 )
397
+ g = np . nanmean (data [mask > 0 , :], 1 )
412
398
413
399
# compute normalized intensity values
414
400
gz = signal .detrend (g , axis = 0 ) # detrend the signal
0 commit comments