AFDB

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

Bases: PhysioNetDataBase

MIT-BIH Atrial Fibrillation Database

ABOUT

  1. contains 25 long-term (each 10 hours) ECG recordings of human subjects with atrial fibrillation (mostly paroxysmal)

  2. 23 records out of 25 include the two ECG signals, the left 2 records 00735 and 03665 are represented only by the rhythm (.atr) and unaudited beat (.qrs) annotation files

  3. signals are sampled at 250 samples per second with 12-bit resolution over a range of ±10 millivolts, with a typical recording bandwidth of approximately 0.1 Hz to 40 Hz

  4. 4 classes of rhythms are annotated:

    • AFIB: atrial fibrillation

    • AFL: atrial flutter

    • J: AV junctional rhythm

    • N: all other rhythms

  5. rhythm annotations almost all start with “(N”, except for 4 which start with ‘(AFIB’, which are all within 1 second (250 samples)

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

Note

  1. beat annotation files (.qrs files) were prepared using an automated detector and have NOT been corrected manually

  2. for some records, manually corrected beat annotation files (.qrsc files) are available

  3. one should never use wfdb.rdann with arguments sampfrom, since one has to know the aux_note (with values in [“(N”, “(J”, “(AFL”, “(AFIB”]) before the index at sampfrom

Usage

  1. Atrial fibrillation (AF) detection

References

Citation

10.13026/C2MW2D

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.

load_ann(rec: str | int, sampfrom: int | None = None, sampto: int | None = None, ann_format: str = 'interval', keep_original: bool = False) Dict[str, list] | ndarray[source]

Load annotations (header) from the .hea 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.

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

  • keep_original (bool, default False) – If True, when ann_format is “interval”, intervals (in the form [a,b]) will keep the same with the annotation file, otherwise subtract sampfrom if specified.

Returns:

ann – The annotations in the format of intervals, or in the format of masks.

Return type:

dict or numpy.ndarray

load_beat_ann(rec: str | int, sampfrom: int | None = None, sampto: int | None = None, use_manual: bool = True, keep_original: bool = False) ndarray[source]

Load beat annotations from 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.

  • use_manual (bool, default True) – If True, use manually annotated beat annotations (qrs), instead of those generated by algorithms.

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

Returns:

ann – Locations (indices) of the qrs complexes.

Return type:

numpy.ndarray

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

Load beat annotations from 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.

  • use_manual (bool, default True) – If True, use manually annotated beat annotations (qrs), instead of those generated by algorithms.

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

Returns:

ann – Locations (indices) of the qrs complexes.

Return type:

numpy.ndarray

plot(rec: str | int, data: ndarray | None = None, ann: Dict[str, ndarray] | None = None, rpeak_inds: Sequence[int] | 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, **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) – (2-lead) ECG signal to plot, should be of the format “channel_first”, and compatible with leads. If given, data of rec will not be used, which is useful when plotting filtered data.

  • ann (dict, optional) – Annotations for data, covering those from annotation files, in the form of {"AFIB":l_itv, "AFL":l_itv, "J":l_itv, "N":l_itv}, where l_itv in the form of [[a, b], ...]. Ignored if data is None.

  • rpeak_inds (array_like, optional) – Indices of R peaks, covering those from annotation files. If data is None, then indices should be the absolute indices in the record.

  • 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 to plot.

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

  • sampto (int, optional) – End index of the data to plot.

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

  • kwargs (dict, optional) – Keyword arguments for matplotlib.pyplot.plot(), etc.