Skip to content

Instantly share code, notes, and snippets.

@mstimberg
Created February 8, 2016 10:10
Show Gist options
  • Save mstimberg/ee11e9cc2307b3afa365 to your computer and use it in GitHub Desktop.
Save mstimberg/ee11e9cc2307b3afa365 to your computer and use it in GitHub Desktop.
Record spikes at a synapse with Brian 2
'''
Record the spikes at a synapse with Brian 2. Note that you cannot use
SpikeMonitor for this task, as it is only meant to record from a NeuronGroup
(or another SpikeSource such as PoissonGroup).
'''
from brian2 import *
# The record_spikes function only works with the numpy target
prefs.codegen.target = 'numpy'
synapse_spikes = []
@check_units(i=1, j=1, k=1, t=second, result=1)
def record_spikes(i, j, k, t):
for i, j, k in zip(i, j, k):
synapse_spikes.append((i, j, k, t/second))
return 0.0 # dummy result
G = NeuronGroup(2, 'dv/dt = 100*Hz : 1', threshold='v>1', reset='v=0')
G.v = [0, 0.5]
G2 = NeuronGroup(2, 'v:1')
S = Synapses(G, G2, pre='dummy=record_spikes(i, j, k, t)',
multisynaptic_index='k')
S.connect('i==j', n=5)
S.delay = 'k*1*ms'
run(20*ms)
# Transform to a 2D array (one row per spike)
synapse_spikes = np.array(synapse_spikes)
print(synapse_spikes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment