|
19 | 19 |
|
20 | 20 | import nibabel as nb
|
21 | 21 | import numpy as np
|
22 |
| -from scipy import linalg |
| 22 | +from scipy import linalg, signal |
23 | 23 | from scipy.special import legendre
|
24 | 24 |
|
25 | 25 | from .. import logging
|
@@ -339,9 +339,7 @@ def _run_interface(self, runtime):
|
339 | 339 | # removed [prior to ...]"
|
340 | 340 | if self.inputs.use_regress_poly:
|
341 | 341 | 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) |
345 | 343 |
|
346 | 344 | # "Voxel time series from the noise ROI (either anatomical or tSTD) were
|
347 | 345 | # 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):
|
518 | 516 | datashape = data.shape
|
519 | 517 | timepoints = datashape[-1]
|
520 | 518 |
|
| 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 | + |
521 | 522 | # Rearrange all voxel-wise time-series in rows
|
522 | 523 | data = data.reshape((-1, timepoints))
|
523 | 524 |
|
@@ -591,7 +592,7 @@ def compute_dvars(in_file, in_mask, remove_zerovariance=False):
|
591 | 592 | mfunc = func[idx[0], idx[1], idx[2], :]
|
592 | 593 |
|
593 | 594 | # Demean
|
594 |
| - mfunc -= mfunc.mean(axis=1).astype(np.float32)[..., np.newaxis] |
| 595 | + mfunc = regress_poly(0, mfunc, remove_mean=True).astype(np.float32) |
595 | 596 |
|
596 | 597 | # Compute (non-robust) estimate of lag-1 autocorrelation
|
597 | 598 | ar1 = np.apply_along_axis(AR_est_YW, 1, mfunc, 1)[:, 0]
|
|
0 commit comments