Skip to content

Commit f3be3ee

Browse files
committed
RF: refactor cosine basis to use dct-ii function
Use dedicated function for _cosine basis. This refactoring will require continuous times, otherwise it will raise an error. In any case, I believe that the values returned when times are not continuous are not valid: a) The current function assumes that all differences in volume times are equal to the difference in the first two volume times, and; b) The DCT values should (I believe) reflect the number of `dt` intervals, not the index into the time vector, as currently.
1 parent 2230072 commit f3be3ee

File tree

1 file changed

+2
-31
lines changed

1 file changed

+2
-31
lines changed

nipy/modalities/fmri/design_matrix.py

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from ...utils.compat3 import open4csv
3232

3333
from .hemodynamic_models import compute_regressor, _orthogonalize
34+
from .realfuncs import dct_ii_cut_basis
3435

3536

3637
######################################################################
@@ -63,37 +64,7 @@ def _poly_drift(order, frametimes):
6364

6465

6566
def _cosine_drift(period_cut, frametimes):
66-
"""Create a cosine drift matrix with periods greater or equals to period_cut
67-
68-
Parameters
69-
----------
70-
period_cut: float
71-
Cut period of the low-pass filter (in sec)
72-
frametimes: array of shape(nscans)
73-
The sampling times (in sec)
74-
75-
Returns
76-
-------
77-
cdrift: array of shape(n_scans, n_drifts)
78-
cosin drifts plus a constant regressor at cdrift[:,0]
79-
80-
Ref: http://en.wikipedia.org/wiki/Discrete_cosine_transform DCT-II
81-
"""
82-
len_tim = len(frametimes)
83-
n_times = np.arange(len_tim)
84-
hfcut = 1./ period_cut # input parameter is the period
85-
86-
dt = frametimes[1] - frametimes[0] # frametimes.max() should be (len_tim-1)*dt
87-
order = int(np.floor(2*len_tim*hfcut*dt)) # s.t. hfcut = 1/(2*dt) yields len_tim
88-
cdrift = np.zeros((len_tim, order))
89-
nfct = np.sqrt(2.0/len_tim)
90-
91-
for k in range(1, order):
92-
cdrift[:,k-1] = nfct * np.cos((np.pi/len_tim)*(n_times + .5)*k)
93-
94-
cdrift[:,order-1] = 1. # or 1./sqrt(len_tim) to normalize
95-
return cdrift
96-
67+
return dct_ii_cut_basis(frametimes, period_cut)
9768

9869

9970
def _blank_drift(frametimes):

0 commit comments

Comments
 (0)