`make_residual_recording` subtracts templates in uV from traces in raw units

未关闭 适合新手
#5,005 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
83/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
data

调研方向

从 benchmark/residual_analysis.py 开始并检查 make_residual_recording,然后追踪当通道增益不等于 1 时 analyzer 模板和录制轨迹的表示方式。复现提供的增益用例,并添加回归测试,以证明残差标准差(单位为 uV)在各种增益下保持一致。三个用例中的残差都符合预期的 5.05 uV 时,即为完成。

由索引模型根据 Issue 内容生成。

描述

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

make_residual_recording takes the templates from the analyzer, in uV by default, and injects them with a negative sign into analyzer.recording, whose traces are in raw units. When the gain is not 1, the residual is wrong, without an error. In the example below the traces in uV are the same for the three gains.

from spikeinterface.core import generate_ground_truth_recording, create_sorting_analyzer
from spikeinterface.preprocessing import scale
from spikeinterface.benchmark import make_residual_recording

recording, sorting = generate_ground_truth_recording(durations=[10.0], num_channels=8, num_units=4, seed=0)
print(f"recording std {recording.get_traces(return_in_uV=True).std():.2f} uV")

for gain in (1.0, 0.195, 2.34):
    # same traces in uV, stored in raw units (uV / gain)
    raw = scale(recording, gain=1 / gain, dtype="float32")
    raw.set_channel_gains(gain)
    raw.set_channel_offsets(0.0)
    analyzer = create_sorting_analyzer(sorting, raw, sparse=False)
    analyzer.compute(["random_spikes", "templates", "noise_levels"])
    analyzer.compute("amplitude_scalings", handle_collisions=False)
    residual = make_residual_recording(analyzer)
    print(f"gain {gain}: residual std {residual.get_traces(return_in_uV=True).std():.2f} uV")

# Output on current main:
# recording std 7.17 uV
# gain 1.0: residual std 5.05 uV
# gain 0.195: residual std 6.48 uV
# gain 2.34: residual std 8.91 uV
# Expected: 5.05 uV for the three gains

With create_sorting_analyzer(..., return_in_uV=False), the residual std is 5.05 uV for the three gains.

Fix: divide the templates by the channel gains before injecting them when they are in uV, or inject them into scale_to_uV(analyzer.recording). The second option changes the dtype and units of the residual, so I leave the choice to you.

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 摘要。