Kilosort wrappers reuse a binary file with a header without its file_offset
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Đọc các bước kiểm tra tính tương thích nhị phân trong sorters/external/kilosortbase.py, kilosort4.py và pykilosort.py, sau đó so sánh chúng với bước kiểm tra file_offset=0 trong klusta.py. Thêm một bài kiểm tra sử dụng bản ghi có tiêu đề để xác nhận rằng các wrapper ghi một bản sao cục bộ thay vì tái sử dụng tệp gốc; công việc được xem là hoàn tất khi mỗi wrapper bị ảnh hưởng xử lý offset an toàn.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 883
- Fork
- 291
- Merge trung bình
- 3 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 40
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của SpikeInterface/spikeinterface
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
SpikeInterface/spikeinterface#5008 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
`plot_potential_merges` draws the correlograms of other units when a merge group is not sortedĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
SpikeInterface/spikeinterface#5007 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
`plot_unit_presence` shows bin indices on the `Time (s)` axis when `time_range` is not givenĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
SpikeInterface/spikeinterface#5006 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
SpikeInterface/spikeinterface#5005 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
SpikeInterface/spikeinterface#5004 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của SpikeInterface/spikeinterface
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
available bug good first issue tooling
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Nixitov/Riptide-Native#816 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
teng-lin/notebooklm-py#2593 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
claimed-by:collie role:small-fix status:running
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Beovulfo/herd-sdlc#325 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 94/100
omarelshamy25x/shamy-arabic-nlp#267 ·
Maintainer thường phản hồi trong vòng 1 ngày