Skip to content

Commit

Permalink
fixed bug in wrong t_start and t_stop in spike_contrast (NeuralEnsemb…
Browse files Browse the repository at this point in the history
  • Loading branch information
dizcza committed Oct 26, 2020
1 parent 07c3826 commit bb83045
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
7 changes: 4 additions & 3 deletions elephant/spike_train_synchrony.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,12 @@ def spike_contrast(spiketrains, t_start=None, t_stop=None,
active_spiketrains = []
synchrony_curve = []

# Set new time boundaries
t_start = t_start - isi_min
t_stop = t_stop + isi_min

bin_size = bin_max
while bin_size >= bin_min:
# Set new time boundaries
t_start = -isi_min
t_stop = duration + isi_min
# Calculate Theta and n
theta_k, n_k = _get_theta_and_n_per_bin(spiketrains,
t_start=t_start,
Expand Down
21 changes: 21 additions & 0 deletions elephant/test/test_spike_train_synchrony.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,27 @@ def test_invalid_data(self):
self.assertRaises(TypeError, spc.spike_contrast, spiketrains,
min_bin=0.01)

def test_t_start_agnostic(self):
np.random.seed(15)
t_stop = 10 * second
spike_train_1 = stgen.homogeneous_poisson_process(rate=10 * Hz,
t_stop=t_stop)
spike_train_2 = stgen.homogeneous_poisson_process(rate=10 * Hz,
t_stop=t_stop)
spiketrains = [spike_train_1, spike_train_2]
synchrony_target = spc.spike_contrast(spiketrains)
# a check for developer: test meaningful result
assert synchrony_target > 0
t_shift = 20 * second
spiketrains_shifted = [
neo.SpikeTrain(st.times + t_shift,
t_start=t_shift,
t_stop=t_stop + t_shift)
for st in spiketrains
]
synchrony = spc.spike_contrast(spiketrains_shifted)
self.assertAlmostEqual(synchrony, synchrony_target)

def test_get_theta_and_n_per_bin(self):
spike_trains = [
[1, 2, 3, 9],
Expand Down

0 comments on commit bb83045

Please sign in to comment.