EnnyvanBeest / UnitMatch

Ephys toolbox to match single units (electrophysiology) either within the same day (over splits) or across two days
Other
42 stars 9 forks source link

Error in filling channel position on python version #63

Closed lrfreeman closed 1 month ago

lrfreeman commented 3 months ago

Hey!

I'm getting an error with channel position:

image

Which is leading to a (I assume) errors down the line

image

Any advice?

Sam-Dodgson commented 3 months ago

Hi,

Unit match require that the channel_positions cover the full probe (as we use all of the channel in the calculations) however some spike sorters occasionally omit some inactive channel, we try to fix this my estimating the missing channel positions. I will look into the estimation to see if I can improve it, however if you could send me the channel_positions.npy and channel_map.npy files, and give me how many channels was recorded for this session it would be very helpful for spotting and fixing this issue.

best, Sam

lrfreeman commented 3 months ago

Ok great - Maybe I can try and manually fill the channel positions that are missing then and see if that fixes the error? Some things to note:

We don't load the sync channel when using spike interface because that prevents channel map plotting in their library:

image

We also remove bad channels through spike interface although I'm not sure this would effect channel_postions and channel_map files:

image

In terms of the error I'm having now it's this:

image

Where:

And when I print ChannelPos I get nans:

image

Here are the files:

files.zip

I appriciate your help on this!

Sam-Dodgson commented 3 months ago

With the data you sent I am not seeing any issues (both the channel_map and channel_positions seem full) image Could you look to see if:

  1. It is the data from the other session which has bad channels
  2. If the RawWaveform folder is the problem (how did you extract the raw waveforms? do what is there shape?). The spike interface method is not as well tested, and it may be the case that it does not extract all the channels for the RawWaveform input?

What the code is doing is to check that the channel_positions have the same number of channels as the extracted raw waveforms, if they don't the fill_missing_pos function will run and attempt to fill in the missing positions. I think your raw waveforms have a missing channel (one less than the channel_positions.npy and channel_map.npy files) which will cause this issue.

lrfreeman commented 3 months ago

To check whether the raw waveforms have been generated wrong I reran them with these parameters:

image

I previously had nChannels at 384 and moved it to 383. Not sure exactly why I have 383 I would expect 384 if spike interface only removes the sync channel. This helped with the missing channel errors. Now it runs clean.

image

However I get a new error when running the next block:

image

With the error being:

image

Sam-Dodgson commented 3 months ago

Okay, I have encountered a similar issue before and I will look into it. If you could send the RawWaveform folder and the good units .tsv , then I will be able to test the fix on applicable data.

I would recommend looking at the two problematic units (plt.plot(waveform[unit, :, :, 1]) to see how the units look, as they are likely bad units, a temp fix would be to maually label them as mua in your good units .tsv file. (Note you have to use ClusInfo['OriginalID'][unit] to go back to the proper unit ID, where unit is 56 and 214)

lrfreeman commented 3 months ago

Sure - here is one of the sessions the other seems to big to zip and send across but i can send via email?. I will try and manually remove these clusters and see what happens. Thanks 25th.zip

Sam-Dodgson commented 3 months ago

Hi, When running the data you sent I didn't have nay problems (even on the old version), however I have updated the code (PyPi and WIP branch) to refactor and fix some bugs. I believe this should fix you issue., if it doesn't I would recommend checking if those units are very bad (noise/artefact units can break the code).

please let me know if the issue remains.