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
spiketrain in a list and run time_histogram([spiketrain], output='rate').
- Compare the results; the correct output is produced only when
spiketrain is wrapped in a list.
Description
When using
time_histogramwithoutput='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_histogramshould yield the same result, regardless of whether a singlespiketrainor a list of onespiketrainis 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. Whenspiketrainsis 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
spiketrainsis always treated as a list, even if it contains only one unit. This can be done by wrappingspiketrainin 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.spiketrainin a list and runtime_histogram([spiketrain], output='rate').spiketrainis wrapped in a list.