CPSC2019¶
- class torch_ecg.databases.CPSC2019(db_dir: str | bytes | PathLike | None = None, working_dir: str | bytes | PathLike | None = None, verbose: int = 1, **kwargs: Any)[source]¶
Bases:
CPSCDataBase
The 2nd China Physiological Signal Challenge (CPSC 2019): Challenging QRS Detection and Heart Rate Estimation from Single-Lead ECG Recordings
ABOUT
Training data consists of 2,000 single-lead ECG recordings collected from patients with cardiovascular disease (CVD)
Each of the recording last for 10 s
Sampling rate = 500 Hz
Challenge official website [1].
Usage
ECG wave delineation
Issues
- there’re 13 records with unusual large values (> 20 mV):
data_00098, data_00167, data_00173, data_00223, data_00224, data_00245, data_00813, data_00814, data_00815, data_00833, data_00841, data_00949, data_00950.
>>> for rec in dr.all_records: >>> data = dr.load_data(rec) >>> if np.max(data) > 20: >>> print(f"{rec} has max value ({np.max(data)} mV) > 20 mV") data_00173 has max value (32.72031811111111 mV) > 20 mV data_00223 has max value (32.75516713333333 mV) > 20 mV data_00224 has max value (32.7519272 mV) > 20 mV data_00245 has max value (32.75305293939394 mV) > 20 mV data_00813 has max value (32.75865595876289 mV) > 20 mV data_00814 has max value (32.75865595876289 mV) > 20 mV data_00815 has max value (32.75558282474227 mV) > 20 mV data_00833 has max value (32.76330123809524 mV) > 20 mV data_00841 has max value (32.727626558139534 mV) > 20 mV data_00949 has max value (32.75699667692308 mV) > 20 mV data_00950 has max value (32.769551661538465 mV) > 20 mV
rpeak references (annotations) loaded from files has dtype = uint16, which would produce unexpected large positive values when subtracting values larger than it, rather than the correct negative value. This might cause confusion in computing metrics when using annotations subtracting (instead of being subtracted by) predictions.
official scoring function has errors, which would falsely omit the interval between the 0-th and the 1-st ref rpeaks, thus potentially missing false positive
References
Citation
10.1166/jmihi.2019.2800
- Parameters:
db_dir (path-like, optional) – Storage path of the database. If not specified, data will be fetched from Physionet.
working_dir (path-like, optional) – Working directory, to store intermediate files and log files.
verbose (int, default 1) – Level of logging verbosity.
kwargs (dict, optional) – Auxilliary key word arguments.
- property database_info: DataBaseInfo¶
The
DataBaseInfo
object of the database.
- get_absolute_path(rec: str | int, extension: str | None = None, ann: bool = False) Path [source]¶
Get the absolute path of the record rec.
- Parameters:
- Returns:
Absolute path of the file.
- Return type:
Path
- load_ann(rec: int | str) ndarray [source]¶
Load the annotations (indices of R peaks) of the record rec.
- load_data(rec: int | str, data_format: str = 'channel_first', units: str = 'mV', fs: Real | None = None, return_fs: bool = False) ndarray | Tuple[ndarray, Real] [source]¶
Load the ECG data of the record rec.
- Parameters:
rec (str or int) – Record name or index of the record in
all_records
.data_format (str, default "channel_first") – Format of the ECG data, “channel_last” (alias “lead_last”), or “channel_first” (alias “lead_first”), or “flat” (alias “plain”).
units (str or None, default "mV") – Units of the output signal, can also be “μV” (with aliases “uV”, “muV”).
fs (numbers.Real, optional) – If provided, the loaded data will be resampled to this frequency, otherwise the original sampling frequency will be used.
return_fs (bool, default False) – Whether to return the sampling frequency of the output signal.
- Returns:
data (numpy.ndarray,) – The loaded ECG data.
data_fs (numbers.Real, optional) – Sampling frequency of the output signal. Returned if return_fs is True.
- load_rpeak_indices(rec: int | str) ndarray [source]¶
Load the annotations (indices of R peaks) of the record rec.
- load_rpeaks(rec: int | str) ndarray [source]¶
Load the annotations (indices of R peaks) of the record rec.
- plot(rec: int | str, data: ndarray | None = None, ann: ndarray | None = None, ticks_granularity: int = 0, **kwargs: Any) None [source]¶
Plot the ECG data of the record rec.
- Parameters:
rec (str or int) – Record name or index of the record in
all_records
.data (numpy.ndarray, optional) – ECG signal to plot. If provided, data of rec will not be used, which is useful when plotting filtered data.
ann (numpy.ndarray, optional) – Annotations (rpeak indices) for data. Ignored if data is None.
ticks_granularity (int, default 0) – Granularity to plot axis ticks, the higher the more ticks. 0 (no ticks) –> 1 (major ticks) –> 2 (major + minor ticks)