LUDB

class torch_ecg.databases.LUDB(db_dir: str | bytes | PathLike | None = None, working_dir: str | bytes | PathLike | None = None, verbose: int = 1, **kwargs: Any)[source]

Bases: PhysioNetDataBase

Lobachevsky University Electrocardiography Database

ABOUT

  1. consist of 200 10-second conventional 12-lead (i, ii, iii, avr, avl, avf, v1, v2, v3, v4, v5, v6) ECG signal records, with sampling frequency 500 Hz

  2. boundaries of P, T waves and QRS complexes were manually annotated by cardiologists, and with the corresponding diagnosis

  3. annotated are 16797 P waves, 21966 QRS complexes, 19666 T waves (in total, 58429 annotated waves)

  4. distributions of data:

    • rhythm distribution:

      Rhythms

      Number of ECGs

      Sinus rhythm

      143

      Sinus tachycardia

      4

      Sinus bradycardia

      25

      Sinus arrhythmia

      8

      Irregular sinus rhythm

      2

      Abnormal rhythm

      19

    • electrical axis distribution:

      Heart electric axis

      Number of ECGs

      Normal

      75

      Left axis deviation (LAD)

      66

      Vertical

      26

      Horizontal

      20

      Right axis deviation (RAD)

      3

      Undetermined

      10

    • distribution of records with conduction abnomalities (totally 79):

      Conduction abnormalities

      Number of ECGs

      Sinoatrial blockade, undetermined

      1

      I degree AV block

      10

      III degree AV-block

      5

      Incomplete right bundle branch block

      29

      Incomplete left bundle branch block

      6

      Left anterior hemiblock

      16

      Complete right bundle branch block

      4

      Complete left bundle branch block

      4

      Non-specific intravintricular conduction delay

      4

    • distribution of records with extrasystoles (totally 35):

      Extrasystoles

      Number of ECGs

      Atrial extrasystole, undetermined

      2

      Atrial extrasystole, low atrial

      1

      Atrial extrasystole, left atrial

      2

      Atrial extrasystole, SA-nodal extrasystole

      3

      Atrial extrasystole, type: single PAC

      4

      Atrial extrasystole, type: bigemini

      1

      Atrial extrasystole, type: quadrigemini

      1

      Atrial extrasystole, type: allorhythmic pattern

      1

      Ventricular extrasystole, morphology: polymorphic

      2

      Ventricular extrasystole, localisation: RVOT, anterior wall

      3

      Ventricular extrasystole, localisation: RVOT, antero-septal part

      1

      Ventricular extrasystole, localisation: IVS, middle part

      1

      Ventricular extrasystole, localisation: LVOT, LVS

      2

      Ventricular extrasystole, localisation: LV, undefined

      1

      Ventricular extrasystole, type: single PVC

      6

      Ventricular extrasystole, type: intercalary PVC

      2

      Ventricular extrasystole, type: couplet

      2

    • distribution of records with hypertrophies (totally 253):

      Hypertrophies

      Number of ECGs

      Right atrial hypertrophy

      1

      Left atrial hypertrophy

      102

      Right atrial overload

      17

      Left atrial overload

      11

      Left ventricular hypertrophy

      108

      Right ventricular hypertrophy

      3

      Left ventricular overload

      11

    • distribution of records of pacing rhythms (totally 12):

      Cardiac pacing

      Number of ECGs

      UNIpolar atrial pacing

      1

      UNIpolar ventricular pacing

      6

      BIpolar ventricular pacing

      2

      Biventricular pacing

      1

      P-synchrony

      2

    • distribution of records with ischemia (totally 141):

      Ischemia

      Number of ECGs

      STEMI: anterior wall

      8

      STEMI: lateral wall

      7

      STEMI: septal

      8

      STEMI: inferior wall

      1

      STEMI: apical

      5

      Ischemia: anterior wall

      5

      Ischemia: lateral wall

      8

      Ischemia: septal

      4

      Ischemia: inferior wall

      10

      Ischemia: posterior wall

      2

      Ischemia: apical

      6

      Scar formation: lateral wall

      3

      Scar formation: septal

      9

      Scar formation: inferior wall

      3

      Scar formation: posterior wall

      6

      Scar formation: apical

      5

      Undefined ischemia/scar/supp.NSTEMI: anterior wall

      12

      Undefined ischemia/scar/supp.NSTEMI: lateral wall

      16

      Undefined ischemia/scar/supp.NSTEMI: septal

      5

      Undefined ischemia/scar/supp.NSTEMI: inferior wall

      3

      Undefined ischemia/scar/supp.NSTEMI: posterior wall

      4

      Undefined ischemia/scar/supp.NSTEMI: apical

      11

    • distribution of records with non-specific repolarization abnormalities (totally 85):

      Non-specific repolarization abnormalities

      Number of ECGs

      Anterior wall

      18

      Lateral wall

      13

      Septal

      15

      Inferior wall

      19

      Posterior wall

      9

      Apical

      11

    • there are also 9 records with early repolarization syndrome

    there might well be records with multiple conditions.

  5. ludb.csv stores information about the subjects (gender, age, rhythm type, direction of the electrical axis of the heart, the presence of a cardiac pacemaker, etc.)

  6. Webpage of the database on PhysioNet [1]. Paper describing the database [2].

Usage

  1. ECG wave delineation

  2. ECG arrhythmia classification

Issues

  1. (version 1.0.0, fixed in version 1.0.1) ADC gain might be wrong, either units should be μV, or adc_gain should be 1000 times larger

References

Citation

10.1109/ACCESS.2020.3029211 10.13026/eegm-h675

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.

from_masks(masks: ndarray, mask_format: str = 'channel_first', leads: str | int | Sequence[int | str] | None = None, class_map: Dict[str, int] | None = None, fs: Real | None = None) Dict[str, List[ECGWaveForm]][source]

Convert masks into lists of waveforms.

Parameters:
  • masks (numpy.ndarray) – Wave delineation in the form of masks, of shape (n_leads, seq_len) or (seq_len,).

  • mask_format (str, default "channel_first") – Format of the mask, used only when masks.ndim = 2. One of “channel_last” (alias “lead_last”), or “channel_first” (alias “lead_first”).

  • leads (str or int or List[str] or List[int], optional) – The leads of the wave delineation to be loaded.

  • class_map (dict, optional) – Custom class map. If not set, self.class_map will be used.

  • fs (numbers.Real, optional) – Sampling frequency of the signal corresponding to the masks, If is None, self.fs will be used, to compute duration of the ECG waveforms.

Returns:

waves – The wave delineation annotations of the record. Each item value of the dict is a list containing the ECGWaveForm corr. to the lead (item key).

Return type:

dict

get_absolute_path(rec: str | int, extension: str | None = None) Path[source]

Get the absolute path of the record.

Parameters:
  • rec (str or int) – Record name or index of the record in all_records.

  • extension (str, optional) – Extension of the file.

Returns:

Absolute path of the file.

Return type:

pathlib.Path

get_subject_id(rec: str | int) int[source]

Attach a unique subject ID for the record.

Parameters:

rec (str or int) – Record name or index of the record in all_records.

Returns:

Subject ID associated with the record.

Return type:

int

load_ann(rec: str | int, leads: str | int | Sequence[int | str] | None = None, metadata: bool = False) dict[source]

Load the wave delineation, along with metadata if specified.

Parameters:
  • rec (str or int) – Record name or index of the record in all_records.

  • leads (str or int or List[str] or List[int], optional) – The leads of the wave delineation to be loaded.

  • metadata (bool, default False) – If True, metadata will be loaded from corresponding head file.

Returns:

ann_dict – The wave delineation annotations.

Return type:

dict

load_diagnoses(rec: str | int) List[str][source]

Load diagnoses of the record.

Parameters:

rec (str or int) – Record name or index of the record in all_records.

Returns:

diagnoses – List of diagnoses of the record.

Return type:

List[str]

load_masks(rec: str | int, leads: str | int | Sequence[int | str] | None = None, mask_format: str = 'channel_first', class_map: Dict[str, int] | None = None) ndarray[source]

Load the wave delineation in the form of masks.

Parameters:
  • rec (str or int) – Record name or index of the record in all_records.

  • leads (str or int or List[str] or List[int], optional) – The leads of the wave delineation to be loaded.

  • mask_format (str, default "channel_first") – Format of the mask, “channel_last” (alias “lead_last”), or “channel_first” (alias “lead_first”).

  • class_map (dict, optional) – Custom class map. If not set, self.class_map will be used.

Returns:

masks – The masks corresponding to the wave delineation annotations of the record.

Return type:

numpy.ndarray

load_subject_info(rec: str | int, fields: str | Sequence[str] | None = None) dict | str[source]

Load subject info of a record.

Parameters:
  • rec (str or int) – Record name or index of the record in all_records.

  • fields (str or Sequence[str], optional) – Field(s) of the subject info of record. If not specified, all fields of the subject info will be loaded.

Returns:

info – Subject info of the given fields of the record.

Return type:

dict or str

plot(rec: str | int, data: ndarray | None = None, ticks_granularity: int = 0, leads: str | int | Sequence[int | str] | None = None, same_range: bool = False, waves: ECGWaveForm | None = None, **kwargs: Any) None[source]

Plot the signals of a record or external signals (units in μV), with metadata (fs, labels, tranche, etc.), possibly also along with wave delineations.

Parameters:
  • rec (str or int) – Record name or index of the record in all_records.

  • data (numpy.ndarray, optional) – 12-lead ECG signal to plot. If is not None, data of rec will not be used. This is useful when plotting filtered data

  • 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)

  • leads (str or int or List[str] or List[int], optional) – The leads of the ECG signal to plot.

  • same_range (bool, default False) – If True, all leads are forced to have the same y range.

  • waves (ECGWaveForm, optional) – The waves (p waves, t waves, qrs complexes) to plot.

  • kwargs (dict, optional) – Additional keyword arguments to pass to matplotlib.pyplot.plot().

TODO

  1. Slice too long records, and plot separately for each segment.

  2. Plot waves using matplotlib.pyplot.axvspan().

Note

Locator of plt has default MAXTICKS of 1000. If not modifying this number, at most 40 seconds of signal could be plotted once.

Contributors: Jeethan, and WEN Hao