Skip to content

Commit

Permalink
More tests for the monitors
Browse files Browse the repository at this point in the history
  • Loading branch information
mstimberg committed Jul 23, 2013
1 parent b0f3183 commit 6ca3cf0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
3 changes: 0 additions & 3 deletions brian2/monitors/statemonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 22 additions & 1 deletion brian2/tests/test_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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])
Expand All @@ -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)))
Expand Down

0 comments on commit 6ca3cf0

Please sign in to comment.