Skip to content

Report unevaluable clusters as fully contaminated, not ContamPct 0 - #1045

Open
cindykrafft wants to merge 1 commit into
MouseLand:mainfrom
cindykrafft:fix/refract-contam-default
Open

Report unevaluable clusters as fully contaminated, not ContamPct 0#1045
cindykrafft wants to merge 1 commit into
MouseLand:mainfrom
cindykrafft:fix/refract-contam-default

Conversation

@cindykrafft

@cindykrafft cindykrafft commented Sep 1, 2026

Copy link
Copy Markdown

Fixes #1044

CCG.refract initialized R12 (est_contam_rate) to zeros and only computed it for clusters with more than 10 spikes and a nonzero time span, so such clusters were exported by io.save_to_phy with ContamPct = 0.0 — the best possible score. Downstream selections of the form "ContamPct < x" without a minimum-spike-count criterion silently admit every such cluster.

This PR initializes R12 to ones so unevaluable clusters export as ContamPct = 100, matching the Kilosort 2.5/3 convention (set_cutoff.m defaulted est_contam_rate to 1). is_refractory is unchanged (these clusters were already labeled mua).

Verification on 4.1.7 + this patch: a 5000-spike uniform-Poisson unit exports ContamPct 93.9 (unchanged), an 8-spike junk cluster exports 100.0 (previously 0.0). If you would rather export NaN for "not evaluated", I am happy to change the default — the important part is that it not be 0.

Reproduction script: https://github.com/cindykrafft/research-software-audit/blob/main/audits/kilosort/verify/kl2_contampct.py

🤖 Generated with Claude Code

https://claude.ai/code/session_012d2sJAD5EUp4GqAStqoBX7

CCG.refract initialized est_contam_rate (R12) to zeros and only computed it
for clusters with more than 10 spikes and a nonzero time span. Clusters
below that floor were therefore exported by io.save_to_phy with
ContamPct = 0.0 - the best possible score - indistinguishable from a
genuinely clean unit. Any downstream selection of the form
'ContamPct < x' without an additional minimum-spike-count criterion
silently admits every such cluster.

Initialize R12 to ones instead, so unevaluable clusters export as
ContamPct = 100. This restores the Kilosort 2.5/3 convention
(set_cutoff.m defaulted est_contam_rate to 1). is_refractory is unchanged
(such clusters were already labeled mua).

Demonstration on kilosort 4.1.7: a uniform-Poisson unit with 5000 spikes
exports ContamPct 93.9 while an 8-spike junk cluster exports 0.0; with
this change the junk cluster exports 100.0.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012d2sJAD5EUp4GqAStqoBX7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: clusters with <=10 spikes export ContamPct = 0.0, the best possible score

2 participants