Skip to content

Commit

Permalink
Merge branch 'burst_analysis' of https://github.com/Gauravu2/MiV-OS i…
Browse files Browse the repository at this point in the history
…nto burst_analysis
  • Loading branch information
skim0119 committed Jun 26, 2022
2 parents 996de5f + fd187a2 commit 82a669b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
4 changes: 1 addition & 3 deletions miv/statistics/burst.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def burst(spiketrains: SpikestampsType, channel: float, min_isi: float, min_len:
"""
Calculates parameters critical to characterize bursting phenomenon on a single channel
Bursting is defined as the occurence of a specified number of spikes (usually >10), with a small interspike interval (usually < 100ms) [1]_, [2]_
Parameters
----------
spikes : SpikestampsType
Expand All @@ -22,7 +21,6 @@ def burst(spiketrains: SpikestampsType, channel: float, min_isi: float, min_len:
Minimum Interspike Interval (in seconds) to be considered as bursting [standard = 0.1]
min_len : float
Minimum number of simultaneous spikes to be considered as bursting [standard = 10]
Returns
-------
start_time: float
Expand All @@ -38,10 +36,10 @@ def burst(spiketrains: SpikestampsType, channel: float, min_isi: float, min_len:
in cortical networks of neurons." Neurocomputing 65 (2005): 653-662.
.. [2] Eisenman, Lawrence N., et al. "Quantification of bursting and synchrony in cultured
hippocampal neurons." Journal of neurophysiology 114.2 (2015): 1059-1071.
"""

spike_interval = interspike_intervals(spiketrains[channel].magnitude)
assert spike_interval.all() > 0, "Inter Spike Interval cannot be zero"
burst_spike = (spike_interval <= min_isi).astype(
np.bool_
) # Only spikes within specified min ISI are 1 otherwise 0 and are stored
Expand Down
38 changes: 38 additions & 0 deletions tests/test_burst.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import numpy as np
import pytest
from neo.core import AnalogSignal, Segment, SpikeTrain

# Test set For Burst Module


def test_burst_analysis_output():
from miv.statistics import burst

# Initialize the spiketrain as below
seg = Segment(index=1)
train0 = SpikeTrain(
times=[0.1, 1.2, 1.3, 1.4, 1.5, 1.6, 4, 5, 5.1, 5.2, 8, 9.5],
units="sec",
t_stop=10,
)
# train0 = SpikeTrain(times=[0.1,4,5,5.1,5.2,9.5], units='sec', t_stop=10)
seg.spiketrains.append(train0)

output = burst(seg.spiketrains, 0, 0.2, 2)
# The function above should return two burst events from 1.2 (duration 0.4, length 5, rate 12.5 )
# and 5(duration 0.2, length 3, rate 15)
np.testing.assert_allclose(output[0], [1.2, 5])
np.testing.assert_allclose(output[1], [0.4, 0.2])
np.testing.assert_allclose(output[2], [5, 3])
np.testing.assert_allclose(output[3], [12.5, 15])

seg1 = Segment(index=1)
train1 = SpikeTrain(
times=[0.1, 1.2, 1.2, 1.2, 5, 6],
units="sec",
t_stop=10,
)
seg1.spiketrains.append(train1)
with np.testing.assert_raises(AssertionError):
output = burst(seg1.spiketrains, 0, 0.2, 2)
# The function above should throw an error since the rate will become 1/0

0 comments on commit 82a669b

Please sign in to comment.