cortex-lab / cortex-lab/phylib

TemplateFeature sparse->full transform messed up if there are < 32 clusters

Open
#31 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
16
Forks
30
PR merge metrics
No merged PRs in 30d

Description

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.
2021-04-08_14h04_48

Here's after the fix:
2021-04-08_14h29_48

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at phylib/io/model.py line 119 and inspect how template_feature_ind.npy maps sparse data into the full matrix. Reproduce with data from Kilosort 2 or 2.5 splitAllClusters.m containing fewer than 32 clusters, then verify that the mapping has no repeated rows or overlapping clusters. Confirm the fix preserves the existing path when there are at least 32 channels or templates.

Written by the indexing model from the issue text.

Assessment

Tech stack
matlab, python
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.