`tridesclous2` puts the spikes of all segments into segment 0 before estimating templates

未關閉
#5,000 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 2 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
72/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
data

研究方向

Start with sorters/internal/tridesclous2.py, especially the sorting_pre_peeler construction and sparsity code identified in the report. Trace how peaks and labels are ordered across segments, then check the lupin.py construction for the same pattern. Done when template spikes retain their segment indices and sparsity uses peaks and labels in matching order; the report offers a two-segment example to verify this.

由索引模型根據 Issue 內容生成。

描述

I found this while reading sorters/internal/tridesclous2.py, not in my own analyses, so this is a "for the sake of improvement" report.

Tridesclous2Sorter has handle_multi_segment = True, but sorting_pre_peeler is built from one array, NumpySorting.from_samples_and_labels(kept_peaks["sample_index"], ...) (lines 278-283), so it has a single segment. The templates are then estimated on segment 0 at the sample indices of the spikes of all segments. lupin.py builds it the same way (lines 332-337); I could not run lupin here (no torch).

The example wraps estimate_templates_with_accumulator to count the segments of the spikes it receives:

import tempfile
from pathlib import Path

import numpy as np

from spikeinterface.core import generate_ground_truth_recording
from spikeinterface.sorters import run_sorter
import spikeinterface.sorters.internal.tridesclous2 as tdc2

seen = {}
original = tdc2.estimate_templates_with_accumulator


def spy(recording, spikes, *args, **kwargs):
    # record which segments the spikes used for the templates belong to
    segments, counts = np.unique(spikes["segment_index"], return_counts=True)
    seen["spikes_per_segment"] = dict(zip(segments.tolist(), counts.tolist()))
    return original(recording, spikes, *args, **kwargs)


if __name__ == "__main__":
    tdc2.estimate_templates_with_accumulator = spy
    recording, gt = generate_ground_truth_recording(num_channels=8, durations=[10.0, 10.0], num_units=4, seed=0)
    # on Windows the saved traces file can still be open when the folder is removed
    with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmp:
        recording = recording.save(folder=Path(tmp) / "recording", progress_bar=False)
        run_sorter("tridesclous2", recording, folder=Path(tmp) / "tdc2", apply_preprocessing=False, seed=0)
    gt_counts = {seg: sum(gt.get_unit_spike_train(u, segment_index=seg).size for u in gt.unit_ids) for seg in (0, 1)}
    print("ground-truth spikes per segment:", gt_counts)
    print("spikes used for templates, per segment:", seen["spikes_per_segment"])

# Output:
# ground-truth spikes per segment: {0: 576, 1: 592}
# spikes used for templates, per segment: {0: 1073}
# Expected: spikes from both segments.

Reading the code, the sparsity (lines 295-298) also pairs kept_peaks, ordered by segment, with labels re-sorted by sample index.

Fix: pass one array per segment to from_samples_and_labels, and take peaks and labels in the same order for the sparsity.

I can open a PR with a test if you agree.

主要語言
Python
星號
883
分支
291
平均合併
3 天 17 小時
30 天內合併 PR
40

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

SpikeInterface/spikeinterface 的其他 Issue

查看 SpikeInterface/spikeinterface 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。