-
Notifications
You must be signed in to change notification settings - Fork 95
Description
Description
When using time_histogram with output='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 single spiketrain or a list of one spiketrain is provided.
Actual Behavior
time_histogram(spiketrain, output='rate') produces an incorrect result, whereas time_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, where len(spiketrains) is used. When spiketrains 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 wrapping spiketrain in a list if it is not already, ensuring consistent behavior for both single and multiple spike train inputs.
Steps to Reproduce
- Create a single spike train,
spiketrain. - Run
time_histogram(spiketrain, output='rate')and observe the incorrect result. - Wrap
spiketrainin a list and runtime_histogram([spiketrain], output='rate'). - Compare the results; the correct output is produced only when
spiketrainis wrapped in a list.