SpikeInterface / spikeinterface

A Python-based module for creating flexible and robust spike sorting pipelines.
https://spikeinterface.readthedocs.io
MIT License
500 stars 187 forks source link

Question about the detection threshold #2758

Open Antho2422 opened 5 months ago

Antho2422 commented 5 months ago

Hi all,

I have a question concerning the detection threshold. I am trying to add an horizontal line to my plot of detected spikes on traces.

To get the y value of the line I do : threshold_value * noise_levels (that I got from the sorting analyzer extension) and this is the result I get :

image

This is a noise cluster so do not mind the quality of the detection. The issue here is that some of the detected events seems to be below the line of threshold and I do not know exactly why ?

I remember that Pierre told me someday that there was a 0.67 factor on the traces and I would like to know if I should take it into account or if this can be coming from something else ?

Thanks, Anthony

zm711 commented 5 months ago

@yger, seems like you discussed this. I haven't looked in the widgets for this so would you mind answering this one?

yger commented 5 months ago

If you are getting the noise levels from the sorting analyzer, then the internal multiplication by 0.67 (to get the MAD) is automatically handled, and you should just do detect_threshold noise_levels to understand how the peaks were detected. The point I mentionned before was that, if you want to have a detection threshold at 6 MAD, then you should provide detect_threshold=4 because internally, SI will do (4/0.67) MAD

yger commented 5 months ago

However, be careful because si.get_noise_levels() has a default mode with return_scaled=True. So if your data have a scaling, be cautious: detect_peaks internally deals with unscaled data. So do not detect noise levels yourself with return_scaled=True, and provide them to detect_peaks that way

Antho2422 commented 5 months ago

Thanks for the answer. I did not detect the peaks manually, this was the results of peaks detected using SC2. I just wanted to visually inspect what was detected on the raw traces using the appropriated plot function from SI and then plotting on top of that a line corresponding to the threshold + the noise level