Skip to content

Commit 8c0ab54

Browse files
committed
refactor
1 parent 7295e67 commit 8c0ab54

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

nipype/algorithms/confounds.py

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -648,15 +648,6 @@ def compute_dvars(in_file, in_mask, remove_zerovariance=False,
648648
raise RuntimeError(
649649
"Input fMRI dataset should be 4-dimensional")
650650

651-
# Robust standard deviation
652-
func_sd = (np.percentile(func, 75, axis=3) -
653-
np.percentile(func, 25, axis=3)) / 1.349
654-
func_sd[mask <= 0] = 0
655-
656-
if remove_zerovariance:
657-
# Remove zero-variance voxels across time axis
658-
mask = zero_remove(func_sd, mask)
659-
660651
idx = np.where(mask > 0)
661652
mfunc = func[idx[0], idx[1], idx[2], :]
662653

@@ -666,11 +657,19 @@ def compute_dvars(in_file, in_mask, remove_zerovariance=False,
666657
if intensity_normalization != 0:
667658
mfunc = (mfunc / np.median(mfunc)) * intensity_normalization
668659

660+
# Robust standard deviation
661+
func_sd = (np.percentile(mfunc, 75, axis=1) -
662+
np.percentile(mfunc, 25, axis=1)) / 1.349
663+
664+
if remove_zerovariance:
665+
mfunc = mfunc[func_sd != 0, :]
666+
func_sd = func_sd[func_sd != 0]
667+
669668
# Compute (non-robust) estimate of lag-1 autocorrelation
670669
ar1 = np.apply_along_axis(AR_est_YW, 1, mfunc, 1)[:, 0]
671670

672671
# Compute (predicted) standard deviation of temporal difference time series
673-
diff_sdhat = np.squeeze(np.sqrt(((1 - ar1) * 2).tolist())) * func_sd[mask > 0].reshape(-1)
672+
diff_sdhat = np.squeeze(np.sqrt(((1 - ar1) * 2).tolist())) * func_sd
674673
diff_sd_mean = diff_sdhat.mean()
675674

676675
# Compute temporal difference time series
@@ -691,19 +690,6 @@ def compute_dvars(in_file, in_mask, remove_zerovariance=False,
691690

692691
return (dvars_stdz, dvars_nstd, dvars_vx_stdz)
693692

694-
def zero_remove(data, mask):
695-
"""
696-
Modify inputted mask to also mask out zero values
697-
698-
:param numpy.ndarray data: e.g. voxelwise stddev of fMRI dataset, after motion correction
699-
:param numpy.ndarray mask: brain mask (same dimensions as data)
700-
:return: the mask with any additional zero voxels removed (same dimensions as inputs)
701-
:rtype: numpy.ndarray
702-
703-
"""
704-
new_mask = mask.copy()
705-
new_mask[data == 0] = 0
706-
return new_mask
707693

708694
def plot_confound(tseries, figsize, name, units=None,
709695
series_tr=None, normalize=False):

0 commit comments

Comments
 (0)