QTDB

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

Bases: PhysioNetDataBase

QT Database

ABOUT

  1. The QT Database includes ECGs which were chosen to represent a wide variety of QRS and ST-T morphologies

  2. Recordings were chosen chosen from the MIT-BIH Arrhythmia Database (MITDB), the European Society of Cardiology ST-T Database (EDB), and several other ECG databases collected at Boston’s Beth Israel Deaconess Medical Center (MIT-BIH ST Change Database, MIT-BIH Supraventricular Arrhythmia Database, MIT-BIH Normal Sinus Rhythm Database, MIT-BIH Long-Term ECG Database, “sudden death” patients from BIH)

  3. Contains 105 fifteen-minute two-lead ECG recordings

  4. Contains onset, peak, and end markers for P, QRS, T, and (where present) U waves of from 30 to 50 selected beats in each recording

  5. Annotation file table:

    Suffix

    Meaning

    .atr

    reference beat annotations from original database (not available for the 24 sudden death records)

    .man:

    reference beat annotations for selected beats only

    .q1c:

    manually determined waveform boundary measurements for selected beats (annotator 1 only – second pass)

    .q2c:

    manually determined waveform boundary measurements for selected beats (annotator 2 only – second pass; available for only 11 records)

    .qt1:

    manually determined waveform boundary measurements for selected beats (annotator 1 only – first pass)

    .qt2:

    manually determined waveform boundary measurements for selected beats (annotator 2 only – first pass; available for only 11 records)

    .pu:

    automatically determined waveform boundary measurements for all beats (based on both signals)

    .pu0:

    automatically determined waveform boundary measurements for all beats (based on signal 0 only)

    .pu1:

    automatically determined waveform boundary measurements for all beats (based on signal 1 only)

  6. A part of the recordings have rhythm annotations, ST change (elevation or depression) annotations, all of which have .atr annotation files. These annotations are provided in the aux_note attribute of the annotation object.

  7. In the first pass manual wave delineation annotation files (.qt1, .qt2 files), fiducial points were marked by a “|” symbol, along with beat annotations (one of “A”, “B”, “N”, “Q”, “V”) inherited from corresponding .man files.

  8. In the second pass manual wave delineation annotation files (.q1c, .q2c files), the final manual annotations are recorded, with the regular annotation symbols “(” ,”)”, “t”, “p”, and “u”, and with annotations inherited from the .qt1, .qt2 files.

  9. The .pu0, .pu1 files contain the automatic waveform onsets and ends in signals 0 and 1 respectively, as detected using the differentiated threshold method by ecgpuwave. In the num fields of the pu* annotations, ecgpuwave classifies the T waves as normal (0), inverted (1), only upwards (2), only downwards (3), biphasic negative-positive (4), or biphasic positive-negative (5). Waveform onset (and offset) annotations specify the waveform type in their num fields (0 for a P-wave, 1 for a QRS complex, 2 for a T wave, or 3 for a U-wave).

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

Usage

  1. ECG wave delineation

  2. ST segment

Issues

  1. According to the paper of the database, there should be .ari files containing QRS annotations obtained automatically by ARISTOTLE, which however are not available in the database.

  2. A large proportion of the wave delineation annotations lack onset indices (the T waves and U waves).

References

Citation

10.1109/cic.1997.648140 10.13026/C24K53

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.

all_extensions

reference beat annotations from original database (not available in all cases) 2. .man: reference beat annotations for selected beats only 3. .q1c: manually determined waveform boundary measurements for selected beats (annotator 1 only – second pass) 4. .q2c: manually determined waveform boundary measurements for selected beats (annotator 2 only – second pass; available for only 11 records) 5. .q1t: manually determined waveform boundary measurements for selected beats (annotator 1 only – first pass) 6. .q2t: manually determined waveform boundary measurements for selected beats (annotator 2 only – first pass; available for only 11 records) 7. .pu: automatically determined waveform boundary measurements for all beats (based on both signals) 8. .pu0: automatically determined waveform boundary measurements for all beats (based on signal 0 only) 9. .pu1: automatically determined waveform boundary measurements for all beats (based on signal 1 only)

Type:
  1. .atr

property database_info: DataBaseInfo

The DataBaseInfo object of the database.

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

Get the lead names of the record.

Parameters:

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

Returns:

List of the lead names of the record.

Return type:

List[str]

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, sampfrom: int | None = None, sampto: int | None = None, keep_original: bool = False, ignore_beat_types: bool = True, extension: str = 'q1c') List[ECGWaveForm][source]

Load the wave delineation annotations of the record.

The wave delineation annotations are returned in the form of list of ECGWaveForm.

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

  • sampfrom (int, optional) – Start index of the annotations to be loaded.

  • sampto (int, optional) – End index of the annotations to be loaded.

  • keep_original (bool, default False) – If True, indices will keep the same with the annotation file, otherwise subtract sampfrom if specified.

  • ignore_beat_types (bool, default True) – If True, the beat types will be ignored (all converted to “N”).

  • extension (str, default "q1c") – Extension of the wave delineation file to use.

Returns:

wave_list – The list of wave delineation in the form of ECGWaveForm.

Return type:

List[ECGWaveForm]

load_beat_ann(rec: str | int, sampfrom: int | None = None, sampto: int | None = None, beat_format: str = 'beat', beat_types: Sequence[str] | None = None, keep_original: bool = False, extension: str = 'atr') Dict[str, ndarray] | List[BeatAnn][source]

Load beat annotations of the record.

Beat annotations are stored in the symbol attribute of corresponding annotation files.

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

  • sampfrom (int, optional) – Start index of the annotations to be loaded.

  • sampto (int, optional) – End index of the annotations to be loaded.

  • beat_format ({"beat", "dict"}, optional) – Format of returned annotation, by default “beat”, case insensitive.

  • beat_types (List[str], optional) – The beat types to be loaded, defaults to self.beat_types. If is not None, only the beat annotations with the specified types will be returned.

  • keep_original (bool, default False) – If True, indices will keep the same with the annotation file, otherwise subtract sampfrom if specified.

  • extension ({"atr", "man"}, optional) – Extension of the annotation file, by default “atr”, case insensitive.

Returns:

beat_ann – Locations (indices) of the the given beat types.

Return type:

dict or list

load_rhythm_ann(rec: str | int, sampfrom: int | None = None, sampto: int | None = None, rhythm_format: str = 'intervals', rhythm_types: Sequence[str] | None = None, keep_original: bool = False, extension: str = 'atr') Dict[str, list] | ndarray[source]

Load rhythm annotations of a record.

Rhythm annotations are stored in the aux_note attribute of corresponding annotation files.

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

  • sampfrom (int, optional) – Start index of the annotations to be loaded.

  • sampto (int, optional) – End index of the annotations to be loaded.

  • rhythm_format ({"intervals", "mask"}, optional) – Format of returned annotation, by default “intervals”, case insensitive.

  • rhythm_types (List[str], optional) – The rhythm types to be loaded, defaults to self.rhythm_types. If is not None, only the rhythm annotations with the specified types will be returned.

  • keep_original (bool, default False) – If True, indices will keep the same with the annotation file, otherwise subtract sampfrom if specified.

  • extension (str, default "atr") – Extension of the annotation file to use. Has to be “atr”, since “man” files has no rhythm annotation.

Returns:

the annotations in the format of intervals, or in the format of mask

Return type:

ann, dict or ndarray,

load_rpeak_indices(rec: str | int, sampfrom: int | None = None, sampto: int | None = None, keep_original: bool = False, extension: str = 'atr') ndarray[source]

Load rpeak indices of the record.

Rpeak indices, or equivalently qrs complex locations, which are stored in the symbol attribute of corresponding annotation files, regardless of their beat types.

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

  • sampfrom (int, optional) – Start index of the annotations to be loaded.

  • sampto (int, optional) – End index of the annotations to be loaded.

  • keep_original (bool, default False) – If True, indices will keep the same with the annotation file, otherwise subtract sampfrom if specified.

  • extension ({"atr", "man"}, optional) – Extension of the annotation file, by default “atr”, case insensitive.

Returns:

rpeak_inds – Locations (indices) of the all the rpeaks (qrs complexes).

Return type:

numpy.ndarray

load_wave_ann(rec: str | int, sampfrom: int | None = None, sampto: int | None = None, keep_original: bool = False, ignore_beat_types: bool = True, extension: str = 'q1c') ndarray[source]

Load the wave delineation annotations of the record.

The wave delineation annotations are returned in the form of list of ECGWaveForm.

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

  • sampfrom (int, optional) – Start index of the annotations to be loaded.

  • sampto (int, optional) – End index of the annotations to be loaded.

  • keep_original (bool, default False) – If True, indices will keep the same with the annotation file, otherwise subtract sampfrom if specified.

  • ignore_beat_types (bool, default True) – If True, the beat types will be ignored (all converted to “N”).

  • extension (str, default "q1c") – Extension of the wave delineation file to use.

Returns:

wave_list – The list of wave delineation in the form of ECGWaveForm.

Return type:

List[ECGWaveForm]

load_wave_masks(rec: str | int, sampfrom: int | None = None, sampto: int | None = None, mask_format: str = 'channel_first', class_map: Dict[str, int] | None = None, extension: str = 'q1c') 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.

  • sampfrom (int, optional) – Start index of the annotations to be loaded.

  • sampto (int, optional) – End index of the annotations 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) – A custom class map. If is None, self.class_map will be used.

  • extension (str, default "q1c") – Extension of the wave delineation file to use.

Returns:

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

Return type:

numpy.ndarray

plot(rec: str | int, data: ndarray | None = None, ticks_granularity: int = 0, leads: str | int | List[str] | List[int] | None = None, sampfrom: int | None = None, sampto: int | None = None, same_range: bool = False, waves: ECGWaveForm | None = None, beat_ann: Dict[str, ndarray] | None = None, rpeak_inds: Sequence[int] | ndarray | 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) – The signals 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 record to plot.

  • sampfrom (int, optional) – Start index of the record to plot.

  • sampto (int, optional) – End index of the record 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, etc.).

  • beat_ann (dict, optional) – The beat annotations.

  • rpeak_inds (numpy.ndarray or List[int], optional) – The rpeak indices.

  • 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