You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
nwbwidgets.analysis.spikes.compute_smoothed_firing_rate currently uses np.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:
ufunc.at(a, indices, b=None, /)
Performs unbuffered in place operation on operand ‘a’ for elements specified by ‘indices’. For addition ufunc, this method is equivalent to a[indices] += b, except that results are accumulated for elements that are indexed more than once. For example, a[[0,0]] += 1 will only increment the first element once because of buffering, whereas add.at(a, [0,0], 1) will increment the first element twice.
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 from np.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 set side='right' in np.searchsorted instead of the default side='left'.
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
The text was updated successfully, but these errors were encountered: