summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarokem <arokem@berkeley.edu>2011-07-26 10:15:13 -0700
committerarokem <arokem@berkeley.edu>2011-07-26 10:15:13 -0700
commitb99baaaa391c490a9b8fc3f70b5e0d4b9df68782 (patch)
tree2dea5cac28202aab5600e88a0837aba0d7f5bd4f
parent6a00c5dd34d288dad4c28417df847c659073cdda (diff)
BF: SeedCoherenceAnalyze inherits from object.
See discussion here: http://mail.scipy.org/pipermail/nipy-devel/2011-July/006551.html
-rw-r--r--nitime/analysis/coherence.py13
-rw-r--r--nitime/analysis/tests/test_coherence.py21
2 files changed, 29 insertions, 5 deletions
diff --git a/nitime/analysis/coherence.py b/nitime/analysis/coherence.py
index 9b7646c..60ee2d6 100644
--- a/nitime/analysis/coherence.py
+++ b/nitime/analysis/coherence.py
@@ -515,7 +515,7 @@ class SparseCoherenceAnalyzer(BaseAnalyzer):
return freqs[lb_idx:ub_idx]
-class SeedCoherenceAnalyzer(BaseAnalyzer):
+class SeedCoherenceAnalyzer(object):
"""
This analyzer takes two time-series. The first is designated as a
time-series of seeds. The other is designated as a time-series of targets.
@@ -556,11 +556,15 @@ class SeedCoherenceAnalyzer(BaseAnalyzer):
"""
- BaseAnalyzer.__init__(self, seed_time_series)
-
self.seed = seed_time_series
self.target = target_time_series
+ # Check that the seed and the target have the same sampling rate:
+ if self.seed.sampling_rate != self.target.sampling_rate:
+ e_s = "The sampling rate for the seed time-series and the target"
+ e_s += " time-series need to be identical."
+ raise ValueError(e_s)
+
#Set the variables for spectral estimation (can also be entered by
#user):
if method is None:
@@ -595,7 +599,8 @@ class SeedCoherenceAnalyzer(BaseAnalyzer):
"""Get the central frequencies for the frequency bands, given the
method of estimating the spectrum """
- self.method['Fs'] = self.method.get('Fs', self.input.sampling_rate)
+ # Get the sampling rate from the seed time-series:
+ self.method['Fs'] = self.method.get('Fs', self.seed.sampling_rate)
NFFT = self.method.get('NFFT', 64)
Fs = self.method.get('Fs')
freqs = tsu.get_freqs(Fs, NFFT)
diff --git a/nitime/analysis/tests/test_coherence.py b/nitime/analysis/tests/test_coherence.py
index 6620dd1..d5691d4 100644
--- a/nitime/analysis/tests/test_coherence.py
+++ b/nitime/analysis/tests/test_coherence.py
@@ -137,5 +137,24 @@ def test_SeedCoherenceAnalyzer():
npt.assert_almost_equal(C1.delay[0, 1], C2.delay[1])
else:
- npt.assert_raises(ValueError,nta.SeedCoherenceAnalyzer, T_seed1,
+ npt.assert_raises(ValueError, nta.SeedCoherenceAnalyzer, T_seed1,
T_target, this_method)
+
+def test_SeedCoherenceAnalyzer_same_Fs():
+ """
+
+ Providing two time-series with different sampling rates throws an error
+
+ """
+
+ Fs1 = np.pi
+ Fs2 = 2 * np.pi
+ t = np.arange(256)
+
+ T1 = ts.TimeSeries(np.random.rand(t.shape[-1]),
+ sampling_rate=Fs1)
+
+ T2 = ts.TimeSeries(np.random.rand(t.shape[-1]),
+ sampling_rate=Fs2)
+
+ npt.assert_raises(ValueError, nta.SeedCoherenceAnalyzer, T1, T2)