Add time-ordered and unit-grouped spike access to `BaseSorting`
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
調査の方向性
Start by reading BaseSorting in src/spikeinterface/core/basesorting.py, especially to_spike_vector() and to_reordered_spike_vector(), and review the linked discussion in #4683. Check how sorting formats provide spike vectors and how existing computations consume them. Done means the proposed time-ordered and unit-grouped access methods have clear ordering guarantees and work with the relevant formats and computations.
索引モデルが issue の本文から書いたものです。
説明
I started #4817 so the caches inside BaseSorting say which order of spikes they hold. That makes the order explicit internally but the more I think about it I think we should make it explicit in the public API too.
Right now the public method names on BaseSorting do not make the spike order explicit. Most things go through the time-ordered spike vector of to_spike_vector() or through a reordering of it with to_reordered_spike_vector(lexsort=...).
However, the methods in spikeinterface differ in which order works better for them. Some want the spikes grouped by unit, for example:
get_unit_spike_train- the per-unit metrics
And others want them ordered by time, for example:
- waveform extraction
- correlograms
This has two costs:
- Memory: requesting unit-grouped spikes through
to_reordered_spike_vector()first builds the time-ordered vector, even when the format already stores spikes grouped by unit (#4702). Even counting the spikes of a sorting builds it:
https://github.com/SpikeInterface/spikeinterface/blob/7a4fc1dc0ec32b42af5c1ba3c01d56cfa5261576/src/spikeinterface/core/basesorting.py#L718-L730 - Confusion:
to_reordered_spike_vectordoes not say which order it returns either, and #4683 is a whole thread on which orders thelexsortparameter should accept and what each one should return.
The proposal is two methods on BaseSorting, time_ordered_spikes(segment_index: int | None) and unit_grouped_spikes(segment_index: int | None), and a computation declares the order it needs by calling one of them. I first suggested them in #4683:
https://github.com/SpikeInterface/spikeinterface/issues/4683#issuecomment-5026315872
A per-unit computation like the ISI violations wants each unit's spikes together:
spikes = sorting.unit_grouped_spikes()
for unit_index, unit_id in enumerate(sorting.unit_ids):
start, stop = np.searchsorted(spikes["unit_index"], [unit_index, unit_index + 1])
train = spikes[start:stop]
violations[unit_id] = np.sum(np.diff(train["sample_index"]) < refractory_samples)
And population activity in a time window wants every unit's spikes in time order:
spikes = sorting.time_ordered_spikes()
start, stop = np.searchsorted(spikes["sample_index"], [t0, t1])
window = spikes[start:stop]
The order is the guarantee (in the unit-grouped one each unit's spikes are sorted by sample_index). Beyond the order, they support what the spike vector supports: columns (at least sample_index and unit_index) and slicing.
These are new methods and they can start clean without breaking the old ones. As each returns the spikes of a single segment the returned spikes don't need a segment_index field. This will simplify moving forward with #4816. And as they don't promise a numpy array a format can return a lazy view.
The main advantage is that once the order is in the method name, each format can implement each method its own way. The formats we own (zarr and the numpy binary folder) can store both orders internally and serve both methods lazily from disk, instead of reading the whole sorting into memory as we do right now. NWB stores the unit-grouped order today and I am working on storing the time-ordered one in ndx-spikesorting:
https://github.com/catalystneuro/ndx-spikesorting/pull/25
The other formats (neo, phy and the rest) just declare which order they have and the other one is materialized on demand, only when a method asks for it.
to_spike_vector() stays exactly as it is and keeps returning the cached array without a copy. to_reordered_spike_vector() is deprecated toward unit_grouped_spikes() which is way more clear.
@samuelgarcia @alejoe91 @grahamfindlay @chrishalcrow @JoeZiminski what do you think?
- 主要言語
- Python
- スター
- 883
- フォーク
- 291
- 平均マージ
- 3日 17時間
- マージ済み PR(30日)
- 40
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
SpikeInterface/spikeinterface のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
SpikeInterface/spikeinterface#5008 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
SpikeInterface/spikeinterface#5007 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
SpikeInterface/spikeinterface#5006 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
SpikeInterface/spikeinterface#5005 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
SpikeInterface/spikeinterface#5004 ·
メンテナーはふだん 2 日以内に返信
SpikeInterface/spikeinterface の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
daniel-ospina/tortoise#15308 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
difficulty:easy prio:low type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
NatronGitHub/Natron#2405 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
Jstar269/nakagawa-recomp#3746 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信