Skip to content

Commit 0cdc971

Browse files
committed
FIX: Incomplete conversion, update docs
1 parent 71dff51 commit 0cdc971

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

nipype/algorithms/confounds.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def _run_interface(self, runtime):
420420
mask_images = self._process_masks(mask_images, imgseries.get_data())
421421

422422
TR = 0
423-
if self.inputs.high_pass_filter:
423+
if self.inputs.pre_filter == 'cosine':
424424
if isdefined(self.inputs.repetition_time):
425425
TR = self.inputs.repetition_time
426426
else:
@@ -965,27 +965,34 @@ def compute_noise_components(imgseries, mask_images, num_components,
965965
966966
imgseries: a nibabel img
967967
mask_images: a list of nibabel images
968-
degree: order of polynomial used to remove trends from the timeseries
969968
num_components: number of noise components to return
970-
high_pass_filter: high-pass-filter data with discrete cosine basis
971-
(run before polynomial detrend)
969+
filter_type: type off filter to apply to time series before computing
970+
noise components.
971+
'polynomial' - Legendre polynomial basis
972+
'cosine' - Discrete cosine (DCT) basis
973+
False - None (mean-removal only)
974+
975+
Filter options:
976+
977+
degree: order of polynomial used to remove trends from the timeseries
978+
period_cut: minimum period (in sec) for DCT high-pass filter
972979
repetition_time: time (in sec) between volume acquisitions
973980
974981
returns:
975982
976983
components: a numpy array
977-
hpf_basis: a numpy array, if high_pass_filter is True, else None
984+
basis: a numpy array containing the (non-constant) filter regressors
978985
979986
"""
980987
components = None
981-
basis = None
988+
basis = np.array([])
982989
for img in mask_images:
983990
mask = img.get_data().astype(np.bool)
984991
if imgseries.shape[:3] != mask.shape:
985-
raise ValueError('Inputs for CompCor, timeseries and mask, '
986-
'do not have matching spatial dimensions '
987-
'({} and {}, respectively)'.format(
988-
imgseries.shape[:3], mask.shape))
992+
raise ValueError(
993+
'Inputs for CompCor, timeseries and mask, do not have '
994+
'matching spatial dimensions ({} and {}, respectively)'.format(
995+
imgseries.shape[:3], mask.shape))
989996

990997
voxel_timecourses = imgseries[mask, :]
991998

@@ -1035,6 +1042,7 @@ def _compute_tSTD(M, x, axis=0):
10351042
# _cosine_drift and _full_rank copied from nipy/modalities/fmri/design_matrix
10361043
#
10371044
# Nipy release: 0.4.1
1045+
# Modified for smooth integration in CompCor classes
10381046

10391047
def _cosine_drift(period_cut, frametimes):
10401048
"""Create a cosine drift matrix with periods greater or equals to period_cut
@@ -1055,22 +1063,23 @@ def _cosine_drift(period_cut, frametimes):
10551063
"""
10561064
len_tim = len(frametimes)
10571065
n_times = np.arange(len_tim)
1058-
hfcut = 1./ period_cut # input parameter is the period
1066+
hfcut = 1. / period_cut # input parameter is the period
10591067

1060-
dt = frametimes[1] - frametimes[0] # frametimes.max() should be (len_tim-1)*dt
1068+
# frametimes.max() should be (len_tim-1)*dt
1069+
dt = frametimes[1] - frametimes[0]
1070+
# hfcut = 1/(2*dt) yields len_time
10611071
# If series is too short, return constant regressor
1062-
order = max(int(np.floor(2*len_tim*hfcut*dt)), 1) # s.t. hfcut = 1/(2*dt) yields len_tim
1072+
order = max(int(np.floor(2*len_tim*hfcut*dt)), 1)
10631073
cdrift = np.zeros((len_tim, order))
10641074
nfct = np.sqrt(2.0/len_tim)
10651075

10661076
for k in range(1, order):
1067-
cdrift[:,k-1] = nfct * np.cos((np.pi/len_tim)*(n_times + .5)*k)
1077+
cdrift[:, k-1] = nfct * np.cos((np.pi / len_tim) * (n_times + .5) * k)
10681078

1069-
cdrift[:,order-1] = 1. # or 1./sqrt(len_tim) to normalize
1079+
cdrift[:, order-1] = 1. # or 1./sqrt(len_tim) to normalize
10701080
return cdrift
10711081

10721082

1073-
10741083
def _full_rank(X, cmax=1e15):
10751084
"""
10761085
This function possibly adds a scalar matrix to X
@@ -1091,7 +1100,7 @@ def _full_rank(X, cmax=1e15):
10911100
c = smax / smin
10921101
if c < cmax:
10931102
return X, c
1094-
warn('Matrix is singular at working precision, regularizing...')
1103+
IFLOG.warn('Matrix is singular at working precision, regularizing...')
10951104
lda = (smax - cmax * smin) / (cmax - 1)
10961105
s = s + lda
10971106
X = np.dot(U, np.dot(np.diag(s), V))

0 commit comments

Comments
 (0)