Skip to content

Commit d5760b0

Browse files
author
Shoshana Berleant
committed
implement remove_mean, refactor into other confounds
1 parent 632087a commit d5760b0

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

nipype/algorithms/confounds.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import nibabel as nb
2121
import numpy as np
22-
from scipy import linalg
22+
from scipy import linalg, signal
2323
from scipy.special import legendre
2424

2525
from .. import logging
@@ -339,9 +339,7 @@ def _run_interface(self, runtime):
339339
# removed [prior to ...]"
340340
if self.inputs.use_regress_poly:
341341
voxel_timecourses = regress_poly(self.inputs.regress_poly_degree,
342-
voxel_timecourses)
343-
voxel_timecourses = voxel_timecourses - np.mean(voxel_timecourses,
344-
axis=1)[:, np.newaxis]
342+
voxel_timecourses, remove_mean=True)
345343

346344
# "Voxel time series from the noise ROI (either anatomical or tSTD) were
347345
# placed in a matrix M of size Nxm, with time along the row dimension
@@ -518,6 +516,9 @@ def regress_poly(degree, data, remove_mean=False):
518516
datashape = data.shape
519517
timepoints = datashape[-1]
520518

519+
if remove_mean: # i.e. regress_poly degree 0, which the following does not do
520+
data = signal.detrend(data, axis=-1, type='constant')
521+
521522
# Rearrange all voxel-wise time-series in rows
522523
data = data.reshape((-1, timepoints))
523524

@@ -591,7 +592,7 @@ def compute_dvars(in_file, in_mask, remove_zerovariance=False):
591592
mfunc = func[idx[0], idx[1], idx[2], :]
592593

593594
# Demean
594-
mfunc -= mfunc.mean(axis=1).astype(np.float32)[..., np.newaxis]
595+
mfunc = regress_poly(0, mfunc, remove_mean=True).astype(np.float32)
595596

596597
# Compute (non-robust) estimate of lag-1 autocorrelation
597598
ar1 = np.apply_along_axis(AR_est_YW, 1, mfunc, 1)[:, 0]

0 commit comments

Comments
 (0)