Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions elephant/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,14 +760,13 @@ def instantaneous_rate(spiketrains, sampling_period, kernel='auto',
TypeError
* If `spiketrain` is not an instance of :class:`neo.core.SpikeTrain`.
* If `sampling_period` is not a `pq.Quantity`.
* If `sampling_period` is not larger than zero.
* If `kernel` is neither instance of :mod:`elephant.kernels` nor string
'auto'.
* If `cutoff` is neither `float` nor `int`.
* If `t_start` and `t_stop` are neither None nor a `pq.Quantity`.
* If `trim` is not `bool`.
ValueError
* If `sampling_period` is smaller than zero.
* If `sampling_period` is not larger than zero.
* If `kernel` is 'auto' and the function was unable to calculate
optimal kernel width for instantaneous rate from input data.
* If `kernel` length is larger than binned spiketrain length
Expand Down Expand Up @@ -987,9 +986,9 @@ def optimal_kernel(st):
raise TypeError(f"The 'sampling_period' must be a time Quantity."
f"Found: {type(sampling_period)}")

if sampling_period.magnitude < 0:
if sampling_period.magnitude <= 0:
raise ValueError(f"The 'sampling_period' ({sampling_period}) "
f"must be non-negative.")
f"must be larger than zero.")

if not (isinstance(kernel, kernels.Kernel) or kernel == 'auto'):
raise TypeError(f"'kernel' must be instance of class "
Expand Down
10 changes: 10 additions & 0 deletions elephant/test/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,16 @@ def test_instantaneous_rate_errors(self):
ValueError, statistics.instantaneous_rate,
spiketrains=self.spike_train, kernel=self.kernel,
sampling_period=-0.01 * pq.ms)
self.assertRaisesRegex( # sampling period is == 0
ValueError, r"must be larger than zero",
statistics.instantaneous_rate,
spiketrains=self.spike_train, kernel=self.kernel,
sampling_period=0 * pq.ms)
self.assertRaisesRegex( # sampling period is == 0, list input
ValueError, r"must be larger than zero",
statistics.instantaneous_rate,
spiketrains=[self.spike_train, self.spike_train],
kernel=self.kernel, sampling_period=0 * pq.s)
self.assertRaises( # no kernel or kernel='auto'
TypeError, statistics.instantaneous_rate,
spiketrains=self.spike_train, sampling_period=0.01 * pq.ms,
Expand Down
Loading