mhhennig / HS2

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

Localization difference between BioCam and RecordingExtractor objects #61

Closed b-grimaud closed 9 months ago

b-grimaud commented 2 years ago

Hi, I'm trying to run Herding Spikes on an object that is then compatible with SpikeInterface and/or Neo objects. Ideally, I would be able to have the flexibility of using standalone Herding Spikes while still being able to interact with a SpikeInterface pipeline.

My issue was intially detailed here.

Essentially, running HSDetection on the same file with the same parameters results in different outputs depending on wether I use HS2's BioCam object or SI's read_biocam then feed it through hs.probe.RecordingExtractor, as illustrated here.

It seems to boil down to BioCam and RecordingExtractor having different default parameters for inner_radius, neighbor_radius and masked_channels, and using different files for position and neighbor coordinates.

As detailed here, the neighbormatrix_spikeextractor generated when using RecordingExtractor is very different from the default neighbormatrix_biocam used with BioCam, and as a result the max_neighbors property is different.

From what I've been able to understand, it might be caused by how channel positions are obtained here.

mhhennig commented 2 years ago

Indeed, the parameters set in the probe differ. It's been the plan for some time to only use SpikeImterface objects, but progress has been a bit slow to implement this. Do you think you can adjust the parameters to get the same behaviour? I'll take a closer look asap!

b-grimaud commented 2 years ago

I have already tried passing the arguments with Probe = hs.probe.RecordingExtractor(recording,noise_amp_percent=1,inner_radius=1.75,neighbor_radius=None, masked_channels=[0]), but the max_neighbors property remains different because BioCam uses preset file for its neighbors matrix, while RecordingExtractor generates a new file on the go that is very different from the base BioCam neighbors matrix (see attached file here).

b-grimaud commented 2 years ago

I compared results from the same file, using the same parameters, with the only difference being that one is loaded through Probe = BioCam(file_path) and the other through SpikeInterface's read_biocam, as recording = read_biocam(file_path) then Probe = hs.probe.RecordingExtractor(recording).

Sorting and clustering are then performed with the exact same parameters.

The first obvious difference is when using H.PlotTracesChannel : Through HS : HS2_PlotTracesChannel Through SI : SI2_PlotTracesChannel

Then, with H.PlotAll : Through HS : HS2_PlotAll Through SI : SI2_PlotAll

The main difference is that it's rotated and mirrored, but there's also slightly fewer spikes detected : 59742 spikes through HS and 60990 spikes through SI. Again, all of the detection parameters are exactly the same, the only difference is the Probe object.

This is also the case after clustering, with C.PlotAll : Through HS : HS2_C_PlotAll Through SI : SI2_C_PlotAll

The axis labels are also incorrect when going through SI's reader.

From what I can tell, it seems to stem from BioCam Probe objects getting their positions and neighbours coordinates from positions_biocam and neighbormatrix_biocam, respectively, while the RecordingExtractor Probe object uses positions_spikeextractor and neighbormatrix_spikeextractor, which seem quite different.

@mhhennig Is there a reason why those objects need to use different coordinate files ?

b-grimaud commented 9 months ago

See #70