Kilosort wrappers reuse a binary file with a header without its file_offset
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
sorters/external/kilosortbase.py、kilosort4.py、pykilosort.pyのバイナリ互換性チェックを読み、klusta.pyのfile_offset=0チェックと比較してください。ヘッダー付きの記録を使ったテストを追加し、ラッパーが元のファイルを再利用せずローカルコピーを書き込むことを確認してください。完了条件は、影響を受ける各ラッパーがオフセットを安全に処理することです。
索引モデルが issue の本文から書いたものです。
説明
I found this while reading sorters/external/kilosortbase.py, kilosort4.py and pykilosort.py, not in my own analyses, so this is a "for the sake of improvement" report.
Before passing the recording file to the sorter without a copy, these wrappers call binary_compatible_with(...) without file_offset=0 (kilosortbase.py l. 149, kilosort4.py l. 138, 234 and 251, pykilosort.py l. 143 and 157). A binary file with a header is then given as is, and the offset is not passed on, so the sorter would read the header as samples: traces shifted by one sample here, or channels permuted when the header is not a multiple of one frame. klusta.py already checks file_offset=0.
import tempfile
from pathlib import Path
import numpy as np
import scipy.io
from probeinterface import generate_linear_probe
from spikeinterface.core import read_binary
from spikeinterface.sorters.external.kilosort2_5 import Kilosort2_5Sorter
if __name__ == "__main__":
with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmp:
tmp = Path(tmp)
traces = np.random.default_rng(0).integers(-100, 100, size=(1000, 4), dtype="int16")
raw_file = tmp / "with_header.bin"
raw_file.write_bytes(b"\x01" * 8 + traces.tobytes()) # 8-byte header, then the samples
recording = read_binary(raw_file, sampling_frequency=30000.0, dtype="int16", num_channels=4, file_offset=8)
probe = generate_linear_probe(num_elec=4)
probe.set_device_channel_indices(np.arange(4))
recording.set_probe(probe)
print(np.array_equal(recording.get_traces(), traces)) # True
# Only the wrapper's setup step: it writes ops.mat, Kilosort itself is not run.
out = tmp / "ks"
out.mkdir()
params = Kilosort2_5Sorter._check_params(recording, out, Kilosort2_5Sorter.default_params())
Kilosort2_5Sorter._setup_recording(recording, out, params, verbose=False)
ops = scipy.io.loadmat(out / "ops.mat", simplify_cells=True)["ops"]
print(Path(ops["fbinary"]).name, (out / "recording.dat").exists()) # with_header.bin False
print([key for key in ops if "offset" in key.lower()]) # []
# What a reader without offset gets from ops["fbinary"] (NchanTOT=4)
seen = np.fromfile(ops["fbinary"], dtype="int16").reshape(-1, 4)
print(seen.shape, seen[0], np.array_equal(seen[1:], traces)) # (1001, 4) [257 257 257 257] True
# Condition used by kilosort4.py and pykilosort.py before reusing the file
print(recording.binary_compatible_with(time_axis=0, file_paths_length=1)) # True
del recording, seen
No sorter was run; Kilosort 4 and pykilosort were checked by reading the code.
Fix: add file_offset=0 to these checks, so that a local copy is written when the file has a header.
I can open a PR with a test if you agree.
- 主要言語
- 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 日以内に返信