173
189
spikes = mininet(SpikeGeneratorGroup, 2, spiketimes)
192
# spike generator with list (already sorted so pass sort=False)
193
spiketimes = [(0, 0 * msecond), (1, 1 * msecond), (0, 2 * msecond), (1, 3 * msecond), (0, 4 * msecond) ]
194
spikes = mininet(SpikeGeneratorGroup, 2, spiketimes, sort=False)
197
# spike generator with unsorted (inversely sorted) list (sort=True is default)
198
spiketimes = [(0, 4 * msecond), (1, 3 * msecond), (0, 2 * msecond), (1, 1 * msecond), (0, 0 * msecond) ]
199
spikes = mininet(SpikeGeneratorGroup, 2, spiketimes)
176
202
# check that it works with a clock
177
203
def testwithclock():
178
204
spikes = mininet(SpikeGeneratorGroup, 2, spiketimes, clock=Clock(dt=0.1 * msecond))
184
210
assert is_approx_equal(s1 * msecond, s2) # the firing times are (0,2,2,4,4)ms
213
# spike generator with a function returning a list
215
return [(0, 0 * msecond), (1, 1 * msecond), (0, 2 * msecond),
216
(1, 3 * msecond), (0, 4 * msecond) ]
218
spikes = mininet(SpikeGeneratorGroup, 2, return_spikes)
221
# spike generator with a list of spikes with simultaneous spikes across neurons
222
spiketimes = [(0, 0 * msecond), (1, 0 * msecond), (0, 2 * msecond),
223
(1, 2 * msecond), (0, 4 * msecond), (1, 4 * msecond) ]
225
assert len(spikes) == 6
226
#check both neurons spiked at the correct times
227
for neuron in [0, 1]:
228
for s1, s2 in zip([0, 2, 4], [t for i, t in spikes if i==neuron]):
229
assert is_approx_equal(s1 * msecond, s2)
231
spikes = mininet(SpikeGeneratorGroup, 2, spiketimes)
234
# same but using the gather=True option
235
spikes = mininet(SpikeGeneratorGroup, 2, spiketimes, gather=True)
238
# same but with index arrays instead of single neuron indices
239
spiketimes = [([0, 1], 0 * msecond), ([0, 1], 2 * msecond),
240
([0, 1], 4 * msecond)]
241
spikes = mininet(SpikeGeneratorGroup, 2, spiketimes)
244
# spike generator with single indices and index arrays of varying length
245
spiketimes = [([0, 1], 0 * msecond), (0, 1 * msecond), (1, 2 * msecond), ([0], 3 * msecond) ]
246
spikes = mininet(SpikeGeneratorGroup, 2, spiketimes)
248
assert len(spikes) == 5
249
#check both neurons spiked at the correct times
250
for s1, s2 in zip([0, 1, 3], [t for i, t in spikes if i==0]):
251
assert is_approx_equal(s1 * msecond, s2)
252
for s1, s2 in zip([0, 2], [t for i, t in spikes if i==1]):
253
assert is_approx_equal(s1 * msecond, s2)
256
# spike generator with an array of (non-simultaneous) spikes
257
# NOTE: For an array, the times have to be in seconds and sorted
258
spiketimes = array([[0, 0.0], [1, 0.001], [0, 0.002], [1, 0.003], [0, 0.004]])
259
spikes = mininet(SpikeGeneratorGroup, 2, spiketimes)
262
# spike generator with an array of (simultaneous) spikes
263
spiketimes = array([[0, 0.0], [1, 0.0], [0, 0.002], [1, 0.002], [0, 0.004], [1, 0.004]])
264
spikes = mininet(SpikeGeneratorGroup, 2, spiketimes)
267
# spike generator with an array of (simultaneous) spikes, using gather=True
268
spiketimes = array([[0, 0.0], [1, 0.0], [0, 0.002], [1, 0.002], [0, 0.004], [1, 0.004]])
269
spikes = mininet(SpikeGeneratorGroup, 2, spiketimes, gather=True)
272
# test the handling of an empty initialization and direct setting of spiketimes
273
def test_attribute_setting():
274
reinit_default_clock()
275
G = SpikeGeneratorGroup(2, [])
276
M = SpikeMonitor(G, True)
279
assert len(M.spikes) == 0
280
reinit_default_clock()
282
G.spiketimes = [(0, 0 * msecond), (1, 1 * msecond), (0, 2 * msecond),
283
(1, 3 * msecond), (0, 4 * msecond)]
286
test_attribute_setting()
288
# tests a subtle difficulty when setting spiketimes and using a subgroup
289
def test_attribute_setting_subgroup():
290
reinit_default_clock()
291
G = SpikeGeneratorGroup(2, [])
293
M = SpikeMonitor(subG, True)
294
G.spiketimes = [(0, 0 * msecond), (1, 1 * msecond), (0, 2 * msecond),
295
(1, 3 * msecond), (0, 4 * msecond)]
296
G.spiketimes = [(0, 0 * msecond), (1, 1 * msecond), (0, 2 * msecond),
297
(1, 3 * msecond), (0, 4 * msecond)]
301
test_attribute_setting_subgroup()
187
303
# spike generator with generator
189
305
yield (0, 0 * msecond)