BaseSorting.select_periods() drops properties, annotations and the registered recording
维护者通常 1 天内回复
评估
调研方向
The issue points to src/spikeinterface/core/sorting_tools.py around select_sorting_periods and describes a reproduction using BaseSorting.select_periods(). Read that function and the related tests in test_basesorting.py; verify that the selected sorting retains properties, annotations, its registered recording, and correct returned spike times. An open pull request, #4921, is already linked to this issue.
由索引模型根据 Issue 内容生成。
描述
select_sorting_periods overwrites sorting with the new object, then copies the metadata from this object onto itself:
sorting = NumpySorting(
sliced_spike_vector, sampling_frequency=sorting.sampling_frequency, unit_ids=sorting.unit_ids
)
sorting.copy_metadata(sorting)
return sorting
So after select_periods, all properties and annotations are lost. The recording is also no longer registered, so get_unit_spike_train(..., return_times=True) ignores the start time or time vector of the recording.
Reproduction
main at 9ef464e66, Linux (WSL Ubuntu 24.04), Python 3.12.3, numpy 2.5.4:
import numpy as np
import spikeinterface.core as sc
from spikeinterface.core.base import unit_period_dtype
fs = 1000.0
rec = sc.generate_recording(num_channels=2, sampling_frequency=fs, durations=[10.0], seed=0)
rec.shift_times(500.0) # the recording starts at t = 500 s
sorting = sc.NumpySorting.from_unit_dict(
{"a": np.array([10, 2000, 5000]), "b": np.array([30, 3000])}, sampling_frequency=fs
)
sorting.set_property("quality", np.array(["good", "mua"]))
sorting.annotate(probe_name="NP2.0")
sorting.register_recording(rec)
periods = np.array([(0, 0, 4000, 0), (0, 0, 4000, 1)], dtype=unit_period_dtype)
selected = sorting.select_periods(periods)
print("properties: ", sorting.get_property_keys(), "->", selected.get_property_keys())
print("annotations: ", sorting.get_annotation_keys(), "->", selected.get_annotation_keys())
print("has_recording:", sorting.has_recording(), "->", selected.has_recording())
print("spike times of 'a' (s):", sorting.get_unit_spike_train("a", return_times=True)[:2],
"->", selected.get_unit_spike_train("a", return_times=True))
properties: ['quality'] -> []
annotations: ['probe_name'] -> []
has_recording: True -> False
spike times of 'a' (s): [500.01 502. ] -> [0.01 2. ]
The spike times are off by 500 s.
Possible fix
- sorting = NumpySorting(
+ new_sorting = NumpySorting(
sliced_spike_vector, sampling_frequency=sorting.sampling_frequency, unit_ids=sorting.unit_ids
)
- sorting.copy_metadata(sorting)
- return sorting
+ sorting.copy_metadata(new_sorting)
+ if sorting.has_recording():
+ new_sorting.register_recording(sorting._recording)
+ return new_sorting
With this, the properties, annotations and spike times are preserved in the example above. test_basesorting.py, test_baserecording.py, test_binaryfolder.py, test_binaryrecordingextractor.py and test_numpy_extractors.py still pass (33 tests).
I found no existing report, and no open PR changes this line. It comes from #4316. #4796 fixed a similar loss of start times in NumpySorting.from_sorting. I can open a PR with this change and a test.
- 主要语言
- Python
- 星标
- 870
- 派生
- 284
- 平均合并
- 3 天 1 小时
- 30 天内合并 PR
- 41
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
SpikeInterface/spikeinterface 的其他 Issue
-
Saving a multi-segment recording fails when only some segments have a t_start可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭core
难度 2/5 1-3 小时 新手友好度 84/100
SpikeInterface/spikeinterface#4914 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
SpikeInterface/spikeinterface#4842 · 3 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 72/100
SpikeInterface/spikeinterface#4510 · 2 条评论 ·
维护者通常 1 天内回复
-
MountainSort5: expose `pca_seed` / `random_seed` sorter param (pair with MS5 configurable PCA seed)未关闭
难度 4/5 3-5 天 新手友好度 43/100
SpikeInterface/spikeinterface#4919 ·
维护者通常 1 天内回复
-
Optional dependencies don't participate in extension invalidation可能已有人在做 @alejoe91 于 1 天前认领。 未关闭bug core
难度 4/5 3-5 天 新手友好度 25/100
SpikeInterface/spikeinterface#4912 ·
维护者通常 1 天内回复
查看 SpikeInterface/spikeinterface 的全部 Issue
相似的 Issue
-
难度 1/5 1-3 小时 新手友好度 88/100
aws-samples/sample-per-model-bedrock#782 ·
维护者通常 1 天内回复
-
Google text documents are base64-encoded twice可能已有人在做 @feiiiiii5 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
coveragepy/coveragepy#2364 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 72/100