Skip to content

Instantly share code, notes, and snippets.

@dilawar
Created June 23, 2015 07:44
Show Gist options
  • Save dilawar/a81226c7d7526e587752 to your computer and use it in GitHub Desktop.
Save dilawar/a81226c7d7526e587752 to your computer and use it in GitHub Desktop.
count spikes in a list.
def count_spikes(tables, threshold):
'''Count the number of spikes, also pupulate the spikeTables '''
nSpikes = 0
spikeBegin = False
spikeEnds = False
clock = moose.Clock('/clock')
for tname in tables:
t = tables[tname]
dt = clock.currentTime / len(t.vector)
spikeList = []
for i, x in enumerate(t.vector):
if x > threshold:
if not spikeBegin:
spikeBegin = True
spikeEnds = False
else: pass
else:
if spikeBegin:
spikeEnds = True
spikeBegin = False
spikeList.append(i*dt)
nSpikes += 1
spikeTables[tname] = spikeList
return nSpikes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment