[Bug] Incorrect Output in time_histogram
for Single Unit Spike Train with output='rate'
#648
Labels
bug
Indicates an unexpected problem or unintended behavior
enhancement
Editing an existing module, improving something
Description
When using
time_histogram
withoutput='rate'
, the result differs between using a single spike train (time_histogram(spiketrain, output='rate')
) and wrapping it in a list (time_histogram([spiketrain], output='rate')
). The correct result is obtained with the latter (time_histogram([spiketrain], output='rate')
), but this discrepancy is confusing when we want to calculate the firing rate for each unit.Expected Behavior
Both calls to
time_histogram
should yield the same result, regardless of whether a singlespiketrain
or a list of onespiketrain
is provided.Actual Behavior
time_histogram(spiketrain, output='rate')
produces an incorrect result, whereastime_histogram([spiketrain], output='rate')
provides the correct output. This discrepancy is due to how the function calculates the sample length based on the input type.Cause
This issue arises from a condition in
statistics.py
, line 1191, wherelen(spiketrains)
is used. Whenspiketrains
is not provided as a list,len(spiketrains)
mistakenly returns the length of the spike train sample rather than counting the number of spike trains, leading to an incorrect rate calculation.Suggested Solution
To fix this issue, modify the code to ensure that
spiketrains
is always treated as a list, even if it contains only one unit. This can be done by wrappingspiketrain
in a list if it is not already, ensuring consistent behavior for both single and multiple spike train inputs.Steps to Reproduce
spiketrain
.time_histogram(spiketrain, output='rate')
and observe the incorrect result.spiketrain
in a list and runtime_histogram([spiketrain], output='rate')
.spiketrain
is wrapped in a list.The text was updated successfully, but these errors were encountered: