MIT-LCP / wfdb-python

Native Python WFDB package
MIT License
747 stars 302 forks source link

Resampling the auxiliary note creates an issue #289

Closed MishalJasmine closed 3 years ago

MishalJasmine commented 3 years ago

I extracted the ECG signal and the annotations including the auxiliary note from the MIT BIH database. I resampled the database record to 125Hz using the function resample_singlechan. After resampling I observed that the length of the qrs peaks and the labels match but the length of the auxiliary notes is different. The number of auxiliary notes is the same as prior resampling.

    record_path = os.path.join('/home/dell/data/mitbih',108)
    record = wfdb.rdrecord('/home/dell/data/mitbih/108', channels=[0])
    fs = record.fs
    sig = record.p_signal[:,0]

    ann_ref= wfdb.rdann(record_path, 'atr')
    print("{} {} {} {}".format(108,len(ann_ref.sample),len(ann_ref.symbol),len(ann_ref.aux_note)))

    resam_sig, resamp_ann = processing.resample_singlechan(sig,ann_ref,fs,125) 
    print("{} {} {} {}".format(108,len(resamp_ann.sample),len(resamp_ann.symbol),len(resamp_ann.aux_note)))
Lucas-Mc commented 3 years ago

Hey @MishalJasmine, I'm kind of confused by your question because resampling shouldn't truncate any annotations, just move them to a new sample number so the lengths should all be the same as before the resampling. The only difference is with ann.sample:

>>> import wfdb
>>> from wfdb import processing
>>>
>>> sig, fields = wfdb.rdsamp('sample-data/100')
>>> ann = wfdb.rdann('100', 'atr', pn_dir='mitdb')
>>> new_sig, new_ann = processing.resample_singlechan(sig[:, 0], ann, fields['fs'], 125)
>>>
>>> ann.sample[:10]
array([  18,   77,  370,  662,  946, 1231, 1515, 1809, 2044, 2402])
>>> new_ann.sample[:10]
array([  6,  27, 128, 230, 328, 427, 526, 628, 710, 834])
>>> # Note 18 = 6 * (360 / 125)
>>>
>>> ann.symbol[:10]
['+', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'A', 'N']
>>> new_ann.symbol[:10]
['+', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'A', 'N']
>>>
>>> ann.aux_note[:10]
['(N\x00', '', '', '', '', '', '', '', '', '']
>>> new_ann.aux_note[:10]
['(N\x00', '', '', '', '', '', '', '', '', '']
>>>
>>> len(ann.sample)
2274
>>> len(new_ann.sample)
2274
>>> len(ann.symbol)
2274
>>> len(new_ann.symbol)
2274
>>> len(ann.aux_note)
2274
>>> len(new_ann.aux_note)
2274
MishalJasmine commented 3 years ago

@Lucas-Mc, Thanks for the code snippet. Looks like I had done a mistake in the script. My bad. Please close this issue.