MIT-LCP / wfdb-python

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

Error while plotting annotation with signal read only in some area #63

Closed smolendawid closed 7 years ago

smolendawid commented 7 years ago

Code:

import wfdb

db_path = '../databases/mitdb/'
filename = '232'

ecg = wfdb.rdsamp(db_path + filename, sampfrom=45608, sampto=67562)
annotation = wfdb.rdann(db_path + filename, annotator='atr', sampfrom=45608, sampto=67562)
wfdb.plotrec(ecg, annotation=annotation)

File "C:/Users/Oem/Desktop/AnalizaEKG/trunk/database_creator/bad_signal_db.py", line 13, in prepare_sig_wfdb wfdb.plotrec(ecg, annotation=annotation) File "C:\Anaconda3\envs\py35\lib\site-packages\wfdb\plot\plots.py", line 66, in plotrec ax.plot(tann, record.p_signals[annotation.annsamp, ch], 'r+') IndexError: index 45718 is out of bounds for axis 0 with size 21954

You can substract the offset, writing

annotation.annsamp -= 45608 before plotting.

But maybe this could be resolved somehow as a package feature, function argument?

cx1111 commented 7 years ago

I added an option in rdann on the master branch. Not on pypi yet.

cx1111 commented 7 years ago

Now is on pypi. 'shiftsamps' input argument to rdann.