Skip to content

Commit 0e90204

Browse files
author
Shoshana Berleant
committed
use numpy.polynomial.Legendre.basis; make regress_poly default more intuitive
1 parent 323e595 commit 0e90204

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

nipype/algorithms/confounds.py

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

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

2525
from .. import logging
2626
from ..external.due import BibTeX
@@ -337,10 +337,8 @@ def _run_interface(self, runtime):
337337
# from paper:
338338
# "The constant and linear trends of the columns in the matrix M were
339339
# removed [prior to ...]"
340-
if self.inputs.use_regress_poly:
341-
voxel_timecourses = regress_poly(self.inputs.regress_poly_degree,
342-
voxel_timecourses)
343-
voxel_timecourses = regress_poly(0, voxel_timecourses, remove_mean=True)
340+
degree = self.inputs.regress_poly_degree if self.inputs.use_regress_poly else 0
341+
voxel_timecourses = regress_poly(degree, voxel_timecourses)
344342

345343
# "Voxel time series from the noise ROI (either anatomical or tSTD) were
346344
# placed in a matrix M of size Nxm, with time along the row dimension
@@ -408,7 +406,7 @@ def _run_interface(self, runtime):
408406
# "For each voxel time series, the temporal standard deviation is
409407
# defined as the standard deviation of the time series after the removal
410408
# of low-frequency nuisance terms (e.g., linear and quadratic drift)."
411-
imgseries = regress_poly(2, imgseries, remove_mean=True)
409+
imgseries = regress_poly(2, imgseries)
412410

413411
time_voxels = imgseries.T
414412
num_voxels = np.prod(time_voxels.shape[1:])
@@ -484,7 +482,7 @@ def _run_interface(self, runtime):
484482
data = data.astype(np.float32)
485483

486484
if isdefined(self.inputs.regress_poly):
487-
data = regress_poly(self.inputs.regress_poly, data)
485+
data = regress_poly(self.inputs.regress_poly, data, remove_mean=False)
488486
img = nb.Nifti1Image(data, img.get_affine(), header)
489487
nb.save(img, op.abspath(self.inputs.detrended_file))
490488

@@ -509,7 +507,7 @@ def _list_outputs(self):
509507
outputs['detrended_file'] = op.abspath(self.inputs.detrended_file)
510508
return outputs
511509

512-
def regress_poly(degree, data, remove_mean=False, axis=-1):
510+
def regress_poly(degree, data, remove_mean=True, axis=-1):
513511
''' returns data with degree polynomial regressed out.
514512
Be default it is calculated along the last axis (usu. time)
515513
'''
@@ -525,7 +523,7 @@ def regress_poly(degree, data, remove_mean=False, axis=-1):
525523
# Generate design matrix
526524
X = np.ones((timepoints, 1))
527525
for i in range(degree):
528-
polynomial_func = legendre(i+1)
526+
polynomial_func = Legendre.basis(i+1)
529527
value_array = np.linspace(-1, 1, timepoints)
530528
X = np.hstack((X, polynomial_func(value_array)[:, np.newaxis]))
531529

0 commit comments

Comments
 (0)