Skip to content

Commit b48395d

Browse files
author
Shoshana Berleant
committed
don't let divide by zero errors pass by
1 parent d5e1a0b commit b48395d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

nipype/algorithms/confounds.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ def compute_dvars(in_file, in_mask, remove_zerovariance=False):
610610
import numpy as np
611611
import nibabel as nb
612612
from nitime.algorithms import AR_est_YW
613+
import warnings
613614

614615
func = nb.load(in_file).get_data().astype(np.float32)
615616
mask = nb.load(in_mask).get_data().astype(np.uint8)
@@ -649,9 +650,13 @@ def compute_dvars(in_file, in_mask, remove_zerovariance=False):
649650
# standardization
650651
dvars_stdz = dvars_nstd / diff_sd_mean
651652

652-
# voxelwise standardization
653-
diff_vx_stdz = func_diff / np.array([diff_sdhat] * func_diff.shape[-1]).T
654-
dvars_vx_stdz = diff_vx_stdz.std(axis=0, ddof=1)
653+
654+
with warnings.catch_warnings(): # catch divide by zero errors
655+
warnings.filterwarnings('error')
656+
657+
# voxelwise standardization
658+
diff_vx_stdz = func_diff / np.array([diff_sdhat] * func_diff.shape[-1]).T
659+
dvars_vx_stdz = diff_vx_stdz.std(axis=0, ddof=1)
655660

656661
return (dvars_stdz, dvars_nstd, dvars_vx_stdz)
657662

0 commit comments

Comments
 (0)