diff --git a/elephant/spike_train_synchrony.py b/elephant/spike_train_synchrony.py index 946a24ae2..35c2c370c 100644 --- a/elephant/spike_train_synchrony.py +++ b/elephant/spike_train_synchrony.py @@ -135,12 +135,15 @@ def spike_contrast(spiketrains, t_start=None, t_stop=None, If the input spike trains constist of a single spiketrain. - If all input spike trains contain no more than 1 spike. TypeError If the input spike trains is not a list of `neo.SpikeTrain` objects. If `t_start`, `t_stop`, or `min_bin` are not time quantities. + Warnings + -------- + If all input spike trains contain no more than 1 spike. + Examples -------- >>> import quantities as pq @@ -191,8 +194,12 @@ def spike_contrast(spiketrains, t_start=None, t_stop=None, try: isi_min = min(np.diff(st).min() for st in spiketrains if len(st) > 1) - except TypeError: - raise ValueError("All input spiketrains contain no more than 1 spike.") + except: + # Do not raise an error but just a warning and continue the code which will return nan-values as synchrony. + # This is useful when running spike-contrast in a batch script, where it is necessary + # to get a complete data structure (trace for all bin-sizes) also for empty spike trains. + warnings.warn("All input spiketrains contain no more than 1 spike.") + isi_min = 0 # continue with isi_min = 0, causing to return spike-contrast with nan as synchrony values but bin_min = max(isi_min / 2, min_bin) contrast_list = [] diff --git a/elephant/test/test_spike_train_synchrony.py b/elephant/test/test_spike_train_synchrony.py index 58be525eb..e86a85d31 100644 --- a/elephant/test/test_spike_train_synchrony.py +++ b/elephant/test/test_spike_train_synchrony.py @@ -89,9 +89,12 @@ def test_spike_contrast_trace(self): def test_invalid_data(self): # invalid spiketrains self.assertRaises(TypeError, spike_contrast, [[0, 1], [1.5, 2.3]]) - self.assertRaises(ValueError, spike_contrast, - [neo.SpikeTrain([10] * ms, t_stop=1000 * ms), - neo.SpikeTrain([20] * ms, t_stop=1000 * ms)]) + + # remove the following test of "All input spiketrains contain no more than 1 spike" + # as the ValueError was replaced by a warning: + #self.assertRaises(ValueError, spike_contrast, + # [neo.SpikeTrain([10] * ms, t_stop=1000 * ms), + # neo.SpikeTrain([20] * ms, t_stop=1000 * ms)]) # a single spiketrain spiketrain_valid = neo.SpikeTrain([0, 1000] * ms, t_stop=1000 * ms)