`interpolate_motion` loses `interpolation_time_bin_size_s` when the recording is rebuilt from its kwargs

オープン 初心者向け
#4,998 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
84/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

sortingcomponents/motion/motion_interpolation.pyから始め、InterpolateMotionRecordingが_kwargsから再構築される際に、補間時間ビンの設定をどのように保存して使用するかを調べてください。提示された例を使って、clone()と並列のsave()の回帰テストを追加してください。ビンサイズと境界を指定したとき、再構築された両方の記録が元の記録と同一のトレースを返せば完了です。

索引モデルが issue の本文から書いたものです。

説明

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

InterpolateMotionRecording._kwargs does not store interpolation_time_bin_size_s, and the stored interpolation_time_bin_centers_s is None in that case. A recording rebuilt from _kwargs (clone(), or the workers of save(n_jobs=2) on Windows, where they are started with spawn) therefore returns different traces, without an error. Reading the code, it falls back to the time bins of the motion.

import tempfile

import numpy as np
from spikeinterface.core import generate_recording
from spikeinterface.core.motion import Motion
from spikeinterface.sortingcomponents.motion import interpolate_motion

if __name__ == "__main__":
    recording = generate_recording(num_channels=32, durations=[10.0], seed=0)
    motion = Motion([np.linspace(0, 100, 5)[:, None]], [np.arange(5) * 2.0 + 1.0], np.array([100.0]))
    corrected = interpolate_motion(
        recording, motion, border_mode="force_extrapolate", interpolation_time_bin_size_s=0.1
    )
    traces = corrected.get_traces()
    print("in _kwargs:", "interpolation_time_bin_size_s" in corrected._kwargs)
    print("signal std:", traces.std())
    print("clone, max abs diff:", np.abs(corrected.clone().get_traces() - traces).max())
    with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as folder:
        saved = corrected.save(folder=folder + "/saved", n_jobs=2, chunk_duration="1s", progress_bar=False)
        print("save(n_jobs=2), max abs diff:", np.abs(saved.get_traces() - traces).max())
        del saved

# Output on current main (Windows):
# in _kwargs: False
# signal std: 0.8311724
# clone, max abs diff: 4.6557436
# save(n_jobs=2), max abs diff: 4.6557436
# Expected: both differences equal to 0

Fix: store interpolation_time_bin_size_s and interpolation_time_bin_edges_s in _kwargs, with the values given by the user. Reading the code, interpolation_time_bin_edges_s has the same problem: only the centers are stored and the edges are recomputed from them.

I can open a PR with a test if you agree.

主要言語
Python
スター
883
フォーク
291
平均マージ
3日 17時間
マージ済み PR(30日)
40

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

SpikeInterface/spikeinterface のほかの issue

SpikeInterface/spikeinterface の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。