MIT-LCP / MIT-LCP/wfdb-python

wrsamp incorrectly saves samps_per_frame when expanded=False

Aperta
#333 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Jupyter Notebook
Stelle
853
Fork
322
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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)

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con Record.wrsamp e confronta il modo in cui i percorsi expanded=True e expanded=False gestiscono samps_per_frame. Riproduci il problema usando rdrecord con il record MIMIC mostrato, quindi esamina il percorso di lettura in wfdb/io/_signal.py. Il lavoro è completato quando un record a frequenza singola scritto con expanded=False può essere riletto senza l’impostazione errata del frame, mentre il comportamento di expanded=True rimane valido.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
data
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.