From 6ca3cf092b3c89cc26ff5d1f36c9de398e120ac6 Mon Sep 17 00:00:00 2001 From: mstimberg Date: Tue, 23 Jul 2013 23:08:48 +0200 Subject: [PATCH] More tests for the monitors --- brian2/monitors/statemonitor.py | 3 --- brian2/tests/test_monitor.py | 23 ++++++++++++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/brian2/monitors/statemonitor.py b/brian2/monitors/statemonitor.py index e6cb2525b..c9b876fa5 100644 --- a/brian2/monitors/statemonitor.py +++ b/brian2/monitors/statemonitor.py @@ -83,9 +83,6 @@ def __init__(self, source, variables, record=None, when=None, variables = [variables] self.variables = variables - if len(self.variables) == 0: - raise ValueError('No variables to record') - # record should always be an array of ints self.record_all = False if record is None or record is False: diff --git a/brian2/tests/test_monitor.py b/brian2/tests/test_monitor.py index 073c0a4af..0cf5effe6 100644 --- a/brian2/tests/test_monitor.py +++ b/brian2/tests/test_monitor.py @@ -30,8 +30,17 @@ def test_spike_monitor(): assert_allclose(mon.t[mon.i == 0], [9.9]*ms) assert_allclose(mon.t[mon.i == 1], np.arange(10)*ms + 0.9*ms) + assert_allclose(mon.t_[mon.i == 0], np.array([9.9*float(ms)])) + assert_allclose(mon.t_[mon.i == 1], (np.arange(10) + 0.9)*float(ms)) assert_equal(mon.count, np.array([1, 10])) + i, t = mon.it + i_, t_ = mon.it_ + assert_equal(i, mon.i) + assert_equal(i, i_) + assert_equal(t, mon.t) + assert_equal(t_, mon.t_) + brian_prefs.codegen.target = language_before @@ -48,6 +57,10 @@ def test_state_monitor(): G.rate = [100, 1000] * Hz G.v = 1 + # A bit peculiar, but in principle one should be allowed to record + # nothing except for the time + nothing_mon = StateMonitor(G, [], record=True) + # Use a single StateMonitor v_mon = StateMonitor(G, 'v', record=True) v_mon1 = StateMonitor(G, 'v', record=[1]) @@ -56,10 +69,18 @@ def test_state_monitor(): multi_mon = StateMonitor(G, ['v', 'f', 'rate'], record=True) multi_mon1 = StateMonitor(G, ['v', 'f', 'rate'], record=[1]) - net = Network(G, v_mon, v_mon1, + net = Network(G, nothing_mon, + v_mon, v_mon1, multi_mon, multi_mon1) net.run(10*ms) + # Check time recordings + assert_equal(nothing_mon.t, v_mon.t) + assert_equal(nothing_mon.t_, np.asarray(nothing_mon.t)) + assert_equal(nothing_mon.t_, v_mon.t_) + assert_allclose(nothing_mon.t, + np.arange(len(nothing_mon.t)) * defaultclock.dt) + # Check v recording assert_allclose(v_mon.v, np.exp(np.tile(-v_mon.t - defaultclock.dt, (2, 1)).T / (10*ms)))