mhhennig / HS2

Software for high density electrophysiology
GNU General Public License v3.0
26 stars 17 forks source link

HerdingSpike through SpikeInterface wrongly scales waveform. #70

Closed b-grimaud closed 10 months ago

b-grimaud commented 1 year ago

As originally pointed out in this issue, running HerdingSpikes through SpikeInterface then accessing the resulting HSDetection object results in incorrect plots using PlotTracesChannels.

Turns out the localization is fine (assuming the correct electrode width and pitch were passed during probe initialization), it's the trace itself that is wrong.

In hs2.py on line 316 :

plt.plot(
  pos[event.ch][0] + trange_bluered,
  pos[event.ch][1] + event.Shape * scale,
  "r"
   ) 

where pos[event.ch][1] is the y-axis coordinate of the spike, and event.Shape is the waveform as, I'm assuming, a list of deviation from the spike's Amplitude. This is unlike the rest of the waveform plots :

plt.plot(
  pos[n][0] + trange_bluered,
  pos[n][1] + data[start_bluered : start_bluered + cutlen, n] * scale,
  col
  )

where the actual raw data is plotted.

This works fine when running only through HerdingSpikes, where the Shape list on my own data typically looks something like : [ 3 -2 -2 2 15 -9 -13 8 -5 11 2 12 3 2 1 -5]. However, through SpikeInterface, it's closer to this : [2094 2088 2022 2010 2032 2028 2041 2030 2032 2022 2031 2031 2032 2028 2027 2022 2027 2026 2043 2024], which shifts the waveform up.

From my very empirical attempt at matching the waveform with the raw trace it seems there's a shift of about +2300 µV in Shape values. I tried digging into the code to find where that list is being populated but I'm not familiar with C.

My first assumption would be that the problem comes from using RecordingExtractor instead of BioCam for the probe, but as pointed out before the raw data seems just fine. Do you have any idea what could be the cause ?

On a related note, I'm also not sure what the probe parameters of inner_radius and neighbor_radius refer to, and why they are so different based on the type of probe object. Is it because SpikeInterface uses microns for coordinates instead of "pixels" for BioCam ?

b-grimaud commented 10 months ago

neo-related issue, see NeuralEnsemble/python-neo#1348, NeuralEnsemble/python-neo#1347, NeuralEnsemble/python-neo#1326.