MIT-LCP / MIT-LCP/wfdb-python

wrsamp incorrectly saves samps_per_frame when expanded=False

オープン
#333 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

主要言語
Jupyter Notebook
スター
853
フォーク
322
PR マージ指標
30日以内にマージされた PR はありません

説明

When writing a record (header + signal file) using Record.wrsamp, the signal data may either be single-frequency (d_signal) or multi-frequency (e_d_signal).

If expanded=True, then wrsamp takes the data from e_d_signal (ignoring d_signal) and writes one or more multi-frequency signal files. In this case the record must also have a samps_per_frame attribute, and this attribute is written to the header file.

If expanded=False (default), then wrsamp takes the data from d_signal (ignoring e_d_signal) and writes one or more single-frequency signal files. In this case the samps_per_frame attribute is still written to the header file, which is completely incorrect.

Why would you have a Record that is single-frequency yet has samps_per_frame not equal to 1? Because that's what rdrecord does by default when you read a multi-frequency record.

So:

>>> import wfdb
>>> r = wfdb.rdrecord('43700001', pn_dir='mimicdb/437', sampto=10, physical=0)
>>> r.wrsamp()
>>> wfdb.rdrecord('43700001')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/benjamin/wfdb-python/wfdb/io/record.py", line 3542, in rdrecord
    return_res=return_res)
  File "/home/benjamin/wfdb-python/wfdb/io/_signal.py", line 1010, in _rd_segment
    sampfrom, sampto, smooth_frames)[:, r_w_channel[fn]]
  File "/home/benjamin/wfdb-python/wfdb/io/_signal.py", line 1151, in _rd_dat_signals
    sig_data = _blocks_to_samples(sig_data, total_process_samples, fmt)
  File "/home/benjamin/wfdb-python/wfdb/io/_signal.py", line 1460, in _blocks_to_samples
    sig[0::2] = sig_data[0::3] + 256 * np.bitwise_and(sig_data[1::3], 0x0f)
ValueError: could not broadcast input array from shape (30) into shape (75)

(Arguably it's wrong for rdrecord to set samps_per_frame when smooth_frames=True, but changing that behavior would be hard to reconcile with rdheader, and would prevent implementing automatic frame-smoothing as I suggested in https://github.com/MIT-LCP/wfdb-python/pull/313#issuecomment-952033980)

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

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

調査の方向性

Record.wrsamp から始め、expanded=True と expanded=False の各パスが samps_per_frame をどのように処理するか比較してください。示されている MIMIC レコードに対して rdrecord を使用して問題を再現し、その後 wfdb/io/_signal.py の読み取りパスを調べてください。expanded=False で書き込まれた単一周波数のレコードを、誤ったフレーム設定なしで読み戻せ、かつ expanded=True の動作が引き続き有効であれば完了です。

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

評価

技術スタック
python
領域
data
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

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

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