Skip to content

Commit 76ea740

Browse files
committed
ENH: DCT xor Legendre; FIX: pass cutoff properly
1 parent c737435 commit 76ea740

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

nipype/algorithms/confounds.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class CompCorInputSpec(BaseInterfaceInputSpec):
325325
components_file = traits.Str('components_file.txt', usedefault=True,
326326
desc='Filename to store physiological components')
327327
num_components = traits.Int(6, usedefault=True) # 6 for BOLD, 4 for ASL
328-
use_regress_poly = traits.Bool(True, usedefault=True,
328+
use_regress_poly = traits.Bool(True, usedefault=True, xor=['high_pass_filter'],
329329
desc=('use polynomial regression '
330330
'pre-component extraction'))
331331
regress_poly_degree = traits.Range(low=1, default=1, usedefault=True,
@@ -334,7 +334,7 @@ class CompCorInputSpec(BaseInterfaceInputSpec):
334334
'file (one column). If undefined, will '
335335
'default to "CompCor"'))
336336
high_pass_filter = traits.Bool(
337-
False, usedefault=True,
337+
False, xor=['use_regress_poly'],
338338
desc='Use cosine basis to remove low-frequency trends pre-component '
339339
'extraction')
340340
high_pass_cutoff = traits.Float(
@@ -437,7 +437,8 @@ def _run_interface(self, runtime):
437437

438438
components, hpf_basis = compute_noise_components(
439439
imgseries.get_data(), mask_images, degree,
440-
self.inputs.num_components, self.inputs.high_pass_filter, TR)
440+
self.inputs.num_components, self.inputs.high_pass_filter,
441+
self.inputs.high_pass_cutoff, TR)
441442

442443
components_file = os.path.join(os.getcwd(), self.inputs.components_file)
443444
np.savetxt(components_file, components, fmt=b"%.10f", delimiter='\t',
@@ -838,7 +839,7 @@ def is_outlier(points, thresh=3.5):
838839
return timepoints_to_discard
839840

840841

841-
def cosine_filter(data, timestep, period_cut, remove_mean=False, axis=-1):
842+
def cosine_filter(data, timestep, period_cut, remove_mean=True, axis=-1):
842843
datashape = data.shape
843844
timepoints = datashape[axis]
844845

@@ -952,7 +953,8 @@ def combine_mask_files(mask_files, mask_method=None, mask_index=None):
952953

953954

954955
def compute_noise_components(imgseries, mask_images, degree, num_components,
955-
high_pass_filter=False, repetition_time=0):
956+
high_pass_filter=False, period_cut=128,
957+
repetition_time=0):
956958
"""Compute the noise components from the imgseries for each mask
957959
958960
imgseries: a nibabel img
@@ -966,6 +968,7 @@ def compute_noise_components(imgseries, mask_images, degree, num_components,
966968
returns:
967969
968970
components: a numpy array
971+
hpf_basis: a numpy array, if high_pass_filter is True, else None
969972
970973
"""
971974
components = None
@@ -983,16 +986,14 @@ def compute_noise_components(imgseries, mask_images, degree, num_components,
983986
# Zero-out any bad values
984987
voxel_timecourses[np.isnan(np.sum(voxel_timecourses, axis=1)), :] = 0
985988

989+
# Use either cosine or Legendre-polynomial detrending
986990
if high_pass_filter:
987-
# If degree == 0, remove mean in same pass
988991
voxel_timecourses, hpf_basis = cosine_filter(
989-
voxel_timecourses, repetition_time,
990-
self.inputs.high_pass_cutoff, remove_mean=(degree == 0))
991-
992-
# from paper:
993-
# "The constant and linear trends of the columns in the matrix M were
994-
# removed [prior to ...]"
995-
if degree > 0 or not high_pass_filter:
992+
voxel_timecourses, repetition_time, period_cut)
993+
else:
994+
# from paper:
995+
# "The constant and linear trends of the columns in the matrix M were
996+
# removed [prior to ...]"
996997
voxel_timecourses = regress_poly(degree, voxel_timecourses)
997998

998999
# "Voxel time series from the noise ROI (either anatomical or tSTD) were

0 commit comments

Comments
 (0)