19
19
20
20
import nibabel as nb
21
21
import numpy as np
22
+ from numpy .polynomial import Legendre
22
23
from scipy import linalg , signal
23
- from scipy .special import legendre
24
24
25
25
from .. import logging
26
26
from ..external .due import BibTeX
@@ -337,10 +337,8 @@ def _run_interface(self, runtime):
337
337
# from paper:
338
338
# "The constant and linear trends of the columns in the matrix M were
339
339
# 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 )
344
342
345
343
# "Voxel time series from the noise ROI (either anatomical or tSTD) were
346
344
# placed in a matrix M of size Nxm, with time along the row dimension
@@ -408,7 +406,7 @@ def _run_interface(self, runtime):
408
406
# "For each voxel time series, the temporal standard deviation is
409
407
# defined as the standard deviation of the time series after the removal
410
408
# 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 )
412
410
413
411
time_voxels = imgseries .T
414
412
num_voxels = np .prod (time_voxels .shape [1 :])
@@ -484,7 +482,7 @@ def _run_interface(self, runtime):
484
482
data = data .astype (np .float32 )
485
483
486
484
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 )
488
486
img = nb .Nifti1Image (data , img .get_affine (), header )
489
487
nb .save (img , op .abspath (self .inputs .detrended_file ))
490
488
@@ -509,7 +507,7 @@ def _list_outputs(self):
509
507
outputs ['detrended_file' ] = op .abspath (self .inputs .detrended_file )
510
508
return outputs
511
509
512
- def regress_poly (degree , data , remove_mean = False , axis = - 1 ):
510
+ def regress_poly (degree , data , remove_mean = True , axis = - 1 ):
513
511
''' returns data with degree polynomial regressed out.
514
512
Be default it is calculated along the last axis (usu. time)
515
513
'''
@@ -525,7 +523,7 @@ def regress_poly(degree, data, remove_mean=False, axis=-1):
525
523
# Generate design matrix
526
524
X = np .ones ((timepoints , 1 ))
527
525
for i in range (degree ):
528
- polynomial_func = legendre (i + 1 )
526
+ polynomial_func = Legendre . basis (i + 1 )
529
527
value_array = np .linspace (- 1 , 1 , timepoints )
530
528
X = np .hstack ((X , polynomial_func (value_array )[:, np .newaxis ]))
531
529
0 commit comments