`plot_unit_presence` shows bin indices on the `Time (s)` axis when `time_range` is not given

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

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

从 widgets/unit_presence.py 开始,其中 plot_unit_presence 会计算 bin 计数并调用 imshow。使用 issue 中的两个示例,检查省略 time_range 时的坐标轴范围,以及采样频率为 24414.0625 Hz 时的 IndexError。完成标准是坐标轴显示秒,且 bin 计数使用一致的样本宽度,不会引发索引错误。

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

描述

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

Without time_range, no extent is passed to imshow, so the x axis shows bin indices while it is labelled "Time (s)". With the default 0.05 s bins, the times are 20 times too large, without an error. Also, the bin width in samples is truncated with int(bin_duration_s * fs) while the number of bins is computed in seconds, so some sampling frequencies raise an IndexError.

import matplotlib

matplotlib.use("Agg")
from spikeinterface.core import generate_sorting
from spikeinterface.widgets import plot_unit_presence

sorting = generate_sorting(num_units=4, durations=[10.0], sampling_frequency=30000.0, seed=0)
w = plot_unit_presence(sorting)
print(w.ax.get_xlabel(), [float(x) for x in w.ax.get_xlim()])
# Time (s) [-0.5, 198.5]  expected about [0, 10]

sorting = generate_sorting(num_units=4, durations=[60.0], sampling_frequency=24414.0625, seed=0)
plot_unit_presence(sorting)
# IndexError: index 1200 is out of bounds for axis 1 with size 1200

Fix: always pass an extent in seconds to imshow, and compute the number of bins and the bin indices with the same bin width in samples.

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