Skip to content

Commit fff5bab

Browse files
committed
RF: Modernize compute_dvars
Directly coerce image dataobj attributes, and mask idiomatically Replace interpolation with method in np.percentile (interpolation deprecated) Call AR_est_YW indirectly to avoid coercion of tuple(array, float)
1 parent 64e176b commit fff5bab

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

nipype/algorithms/confounds.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,12 @@ def _list_outputs(self):
10001000
return self._results
10011001

10021002

1003+
def _AR_est_YW(x, order, rxx=None):
1004+
"""Retrieve AR coefficients while dropping the sig_sq return value"""
1005+
from nitime.algorithms import AR_est_YW
1006+
return AR_est_YW(x, order, rxx=rxx)[0]
1007+
1008+
10031009
def compute_dvars(
10041010
in_file,
10051011
in_mask,
@@ -1037,37 +1043,35 @@ def compute_dvars(
10371043
"""
10381044
import numpy as np
10391045
import nibabel as nb
1040-
from nitime.algorithms import AR_est_YW
10411046
import warnings
10421047

1043-
func = nb.load(in_file).get_fdata(dtype=np.float32)
1044-
mask = np.asanyarray(nb.load(in_mask).dataobj).astype(np.uint8)
1048+
func = np.float32(nb.load(in_file).dataobj)
1049+
mask = np.bool_(nb.load(in_mask).dataobj)
10451050

10461051
if len(func.shape) != 4:
10471052
raise RuntimeError("Input fMRI dataset should be 4-dimensional")
10481053

1049-
idx = np.where(mask > 0)
1050-
mfunc = func[idx[0], idx[1], idx[2], :]
1054+
mfunc = func[mask]
10511055

10521056
if intensity_normalization != 0:
10531057
mfunc = (mfunc / np.median(mfunc)) * intensity_normalization
10541058

10551059
# Robust standard deviation (we are using "lower" interpolation
10561060
# because this is what FSL is doing
10571061
func_sd = (
1058-
np.percentile(mfunc, 75, axis=1, interpolation="lower")
1059-
- np.percentile(mfunc, 25, axis=1, interpolation="lower")
1062+
np.percentile(mfunc, 75, axis=1, method="lower")
1063+
- np.percentile(mfunc, 25, axis=1, method="lower")
10601064
) / 1.349
10611065

10621066
if remove_zerovariance:
1063-
zero_variance_voxels = func_sd > self.inputs.variance_tol
1067+
zero_variance_voxels = func_sd > variance_tol
10641068
mfunc = mfunc[zero_variance_voxels, :]
10651069
func_sd = func_sd[zero_variance_voxels]
10661070

10671071
# Compute (non-robust) estimate of lag-1 autocorrelation
10681072
ar1 = np.apply_along_axis(
1069-
AR_est_YW, 1, regress_poly(0, mfunc, remove_mean=True)[0].astype(np.float32), 1
1070-
)[:, 0]
1073+
_AR_est_YW, 1, regress_poly(0, mfunc, remove_mean=True)[0].astype(np.float32), 1
1074+
)
10711075

10721076
# Compute (predicted) standard deviation of temporal difference time series
10731077
diff_sdhat = np.squeeze(np.sqrt(((1 - ar1) * 2).tolist())) * func_sd

0 commit comments

Comments
 (0)