Skip to content
This repository has been archived by the owner on Feb 6, 2021. It is now read-only.

Commit

Permalink
Allow for precomputed highpass filter matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaskom committed Jan 16, 2014
1 parent 4911f6b commit 2fc9a7b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 10 additions & 2 deletions moss/glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class DesignMatrix(object):
"""
def __init__(self, design, hrf_model, ntp, regressors=None, confounds=None,
artifacts=None, condition_names=None, confound_pca=False,
tr=2, hpf_cutoff=128, oversampling=16):
tr=2, hpf_cutoff=128, hpf_kernel=None, oversampling=16):
"""Initialize the design matrix object.
Parameters
Expand Down Expand Up @@ -197,6 +197,9 @@ def __init__(self, design, hrf_model, ntp, regressors=None, confounds=None,
sampling interval (in seconds) of the data/design
hpf_cutoff : float
filter cutoff (in seconds), or None to skip the filter
hpf_kernel : ntp x ntp array
precomputed matrix to implement the highpass filter; overrides the
hpf_cutoff (i.e. it is not checked if they match).
oversampling : float
construction of the condition evs and convolution
are performed on high-resolution data with this oversampling
Expand Down Expand Up @@ -232,6 +235,8 @@ def __init__(self, design, hrf_model, ntp, regressors=None, confounds=None,
conditions = self._subsample_condition_matrix()
conditions -= conditions.mean()
pp_heights = (conditions.max() - conditions.min()).tolist()
if hpf_kernel is not None:
hpf_cutoff = hpf_kernel
if hpf_cutoff is not None:
conditions = self._highpass_filter(conditions, hpf_cutoff)

Expand Down Expand Up @@ -402,7 +407,10 @@ def _validate_component(self, comp, name_base):

def _highpass_filter(self, mat, cutoff):
"""Highpass-filter each column in mat."""
F = fsl_highpass_matrix(self._ntp, cutoff, self.tr)
if np.isscalar(cutoff):
F = fsl_highpass_matrix(self._ntp, cutoff, self.tr)
else:
F = cutoff
for key, vals in mat.iteritems():
mat[key] = np.dot(F, vals)
return mat
Expand Down
14 changes: 14 additions & 0 deletions moss/tests/test_glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,20 @@ def test_design_matrix_confound_pca():
nt.assert_equal(n_confounds, good_dims)


def test_design_matrix_precomputed_kernel():
"""Test that we can use a precomputed highpass filter matrix."""
F = glm.fsl_highpass_matrix(20, 8, 2)
hrf = glm.GammaDifferenceHRF()

design = pd.DataFrame(dict(condition=["one", "two"],
onset=[5, 20]))
regressors = rs.randn(20, 2)

X_1 = glm.DesignMatrix(design, hrf, 20, regressors=regressors, hpf_cutoff=8)
X_2 = glm.DesignMatrix(design, hrf, 20, regressors=regressors, hpf_kernel=F)

npt.assert_array_equal(X_1.design_matrix, X_2.design_matrix)

def test_highpass_matrix_shape():
"""Test the filter matrix is the right shape."""
for n_tp in 10, 100:
Expand Down

0 comments on commit 2fc9a7b

Please sign in to comment.