From 7c3a37624ee66e1e86acec579ce2dd7daa6d9f6c Mon Sep 17 00:00:00 2001 From: Gauravu2 <89496329+Gauravu2@users.noreply.github.com> Date: Fri, 24 Jun 2022 12:34:56 -0500 Subject: [PATCH 1/2] Updated to assert error --- miv/statistics/burst.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/miv/statistics/burst.py b/miv/statistics/burst.py index b046ff6e..4a1cbb33 100644 --- a/miv/statistics/burst.py +++ b/miv/statistics/burst.py @@ -10,7 +10,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 @@ -21,7 +20,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 @@ -32,17 +30,16 @@ def burst(spiketrains: SpikestampsType, channel: float, min_isi: float, min_len: Number of spikes in a particular burst burst_rate: float firing rates corresponding to particular bursts - .. [1] Chiappalone, Michela, et al. "Burst detection algorithms for the analysis of spatio-temporal patterns 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 = np.diff( spiketrains[channel].magnitude ) # Calculate Inter Spike Interval (ISI) + assert spike_interval.all() > 0, "Inter Spike Interval cannot be zero" burst_spike = (spike_interval <= min_isi).astype( np.int32 ) # Only spikes within specified min ISI are 1 otherwise 0 and are stored From fd187a2c4b92c85b400360c608dd45ad26b9bae6 Mon Sep 17 00:00:00 2001 From: Gauravu2 <89496329+Gauravu2@users.noreply.github.com> Date: Fri, 24 Jun 2022 12:35:31 -0500 Subject: [PATCH 2/2] Updated test case --- tests/test_burst.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/test_burst.py diff --git a/tests/test_burst.py b/tests/test_burst.py new file mode 100644 index 00000000..61428f1b --- /dev/null +++ b/tests/test_burst.py @@ -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