If there are less than 32 clusters, the template_feature_ind.npy matrix that's used to translate template_feature.npy data from sparse into full has repeated rows. This makes it so that the assignment here is messed up. It seems to only happen if splitAllClusters.m in Kilosort 2 or 2.5 is run. I didn't get to the bottom of why that is. Something to do with the template projections not getting recomputed I guess.
But in any case I think it's easily fixed by adding some logic on line 119 of model.py:
if n_channels_loc > n_channels:
# If there are fewer templates (n_channels here) than the number of
# mapping indicies (32 for template projections by KiloSort),
# limit the indexing to avoid an incorrect mapping
out[x[:, :n_channels, ...], cols_loc[:, :n_channels, ...], ...] = data[:, :n_channels, ...]
else:
out[x, cols_loc, ...] = data
Not really sure what else this thing does so I didn't want to put in a pull request.
Here's what it looks like before the fix. You can see cluster 9 is overlapped with the noise cluster.
If there are less than 32 clusters, the template_feature_ind.npy matrix that's used to translate template_feature.npy data from sparse into full has repeated rows. This makes it so that the assignment here is messed up. It seems to only happen if splitAllClusters.m in Kilosort 2 or 2.5 is run. I didn't get to the bottom of why that is. Something to do with the template projections not getting recomputed I guess.
But in any case I think it's easily fixed by adding some logic on line 119 of model.py:
Not really sure what else this thing does so I didn't want to put in a pull request.
Here's what it looks like before the fix. You can see cluster 9 is overlapped with the noise cluster.
Here's after the fix: