Open felixp8 opened 11 months ago
happy to fix it myself, but would like confirmation whether the general binning behavior should be fixed as well
also is there a reason why zeros are returned even if there is one spike? based on https://github.com/NeurodataWithoutBorders/nwbwidgets/blob/master/nwbwidgets/analysis/spikes.py#L17
What happened?
nwbwidgets.analysis.spikes.compute_smoothed_firing_rate
currently usesnp.searchsorted
to find bin indices for spike times, and then indexes into a zero array using those bin indices and increments that by one. When there a bin index is repeated, that bin is only incremented once.A simple solution is to use
np.add.at
. From the docs:As a side note,
np.searchsorted
returns the index at which an element should be inserted to preserve order, e.g. if the timestamps are[0.0, 1.0, 2.0]
, a spike time of 0.5 would return 1 fromnp.searchsorted
and be placed in bin 1, although conventional histogram/binning practices would place it in bin 0. If this is unintentional, to fix this we could subtract 1 from all of these indices and setside='right'
innp.searchsorted
instead of the defaultside='left'
.Steps to Reproduce
Traceback
Operating System
Linux
Python Version
3.10
Package Versions
nwbwidgets==0.11.3
Code of Conduct