MIT-LCP / wfdb-python

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

.ecg format File reading error #425

Closed songhat closed 2 years ago

songhat commented 2 years ago

there is my code:

from ishneholterlib import Holter

#Load a file from disk:
x = Holter("./data/chf202.ecg")
x.load_data()

there is error:

C:\Users\songHat\miniconda3\envs\hospital\python.exe D:\all_codes\hospital\mse\mse.py 
Traceback (most recent call last):
  File "D:\all_codes\hospital\mse\mse.py", line 10, in <module>
    x = Holter('./data/chf202.ecg')
  File "C:\Users\songHat\miniconda3\envs\hospital\lib\site-packages\ishneholterlib\__init__.py", line 65, in __init__
    self.load_header()
  File "C:\Users\songHat\miniconda3\envs\hospital\lib\site-packages\ishneholterlib\__init__.py", line 123, in load_header
    self.var_block = get_val(filename, 522, 'a'+str(self.var_block_size)).split(b'\x00')[0]
  File "C:\Users\songHat\miniconda3\envs\hospital\lib\site-packages\ishneholterlib\__init__.py", line 20, in get_val
    val = val[0]
IndexError: index 0 is out of bounds for axis 0 with size 0
songhat commented 2 years ago

can anyone help me? really appreciate !

songhat commented 2 years ago

there is data congestive-heart-failure-rr-interval-database-1.0.0.zip

briangow commented 2 years ago

@1358467720 , have you attempted to use the WFDB toolbox? In the Python version of the toolbox you can read this annotation file directly from the PhysioNet servers with:

import wfdb
ann = wfdb.rdann('chf202', 'ecg', pn_dir='chf2db')
songhat commented 2 years ago

@briangow really thank your help! but in this data, I want to read the data with code:

import wfdb

record = wfdb.rdrecord('chf202', pn_dir='chf2db')
print(record.record_name)

I get a error here:

Traceback (most recent call last):
  File "D:\all_codes\EEG\数据分析\mse\mse.py", line 9, in <module>
    record = wfdb.rdrecord('chf202', pn_dir='chf2db')
  File "C:\Users\songHat\miniconda3\envs\EEG\lib\site-packages\wfdb\io\record.py", line 2039, in rdrecord
    record.check_read_inputs(
  File "C:\Users\songHat\miniconda3\envs\EEG\lib\site-packages\wfdb\io\record.py", line 620, in check_read_inputs
    raise ValueError("sampto must be greater than sampfrom")
ValueError: sampto must be greater than sampfrom

Process finished with exit code 1

how to fix it? thank you!

briangow commented 2 years ago

@1358467720 my understanding from the project description for chf2db (https://physionet.org/content/chf2db/1.0.0/) is that the ECG waveform samples are not available - only the annotations are available. As mentioned in the project description you might want to take a look at this project if you need the waveforms + annotations: https://physionet.org/content/chfdb/1.0.0/ .

songhat commented 2 years ago

@briangow really appreciate you, but I find the two data is different. I am confused and don't konw why.

briangow commented 2 years ago

@1358467720 , yes, these appear to be two independent projects. If you need waveform signals + annotations you will have to use the https://physionet.org/content/chfdb/1.0.0/ project.

songhat commented 2 years ago

thank you again. But other data is not suitable for me