LTAFDB¶
- class torch_ecg.databases.LTAFDB(db_dir: Optional[Union[str, pathlib.Path]] = None, working_dir: Optional[Union[str, pathlib.Path]] = None, verbose: int = 1, **kwargs: Any)[source]¶
Bases:
torch_ecg.databases.base.PhysioNetDataBase
Long Term AF Database
ABOUT
contains 84 long-term ECG recordings of subjects with paroxysmal or sustained atrial fibrillation
each record contains two simultaneously recorded ECG signals digitized at 128 Hz
records have duration 24 - 25 hours
qrs annotations (.qrs files) were produced by an automated QRS detector, in which detected beats (including occasional ventricular ectopic beats) are labelled “N”, detected artifacts are labelled “|”, and AF terminations are labelled “T” (inserted manually)
atr annotations (.atr files) were obtained by manual review of the output of an automated ECG analysis system; in these annotation files, all detected beats are labelled by type (‘”’, “+”, “A”, “N”, “Q”, “V”), and rhythm changes (“ Aux”, “(AB”, “(AFIB”, “(B”, “(IVR”, “(N”, “(SBR”, “(SVTA”, “(T”, “(VT”, “M”, “MB”, “MISSB”, “PSE”) are also annotated
Webpage of the database on PhysioNet 1. Paper describing the database 2.
Note
both channels of the signals have name “ECG”
the automatically generated qrs annotations (.qrs files) contains NO rhythm annotations
aux_note of .atr files of all but one (“64”) record start with valid rhythms, all but one end with “” (“30” ends with “ Aux”)
for more statistics on the whole database, see [ref 3](#ref3)
Usage
Atrial fibrillation (AF) detection
(3 or 4) beat type classification
Rhythm classification
References
- 1
- 2
Petrutiu S, Sahakian AV, Swiryn S. Abrupt changes in fibrillatory wave characteristics at the termination of paroxysmal atrial fibrillation in humans. Europace 9:466-470 (2007).
Citation
10.1093/europace/eum096 10.13026/C2QG6Q
- Parameters
db_dir (str or pathlib.Path, optional) – Storage path of the database. If not specified, data will be fetched from Physionet.
working_dir (str, 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: torch_ecg.databases.base.DataBaseInfo¶
The
DataBaseInfo
object of the database.
- load_ann(rec: Union[str, int], sampfrom: Optional[int] = None, sampto: Optional[int] = None, rhythm_format: str = 'interval', beat_format: str = 'beat', keep_original: bool = False) dict [source]¶
Load rhythm and beat annotations of the record.
Rhythm and beat annotations are stored in the aux_note, symbol attributes of corresponding annotation files. NOTE that qrs annotations (.qrs files) do NOT contain any rhythm annotations.
- 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 ({"interval", "mask"}, optional) – Format of returned annotation, by default “interval”, case insensitive.
beat_format ({"beat", "dict"}, optional) – Format of returned annotation, by default “beat”, case insensitive.
keep_original (bool, default False) – If True, indices will keep the same with the annotation file, otherwise subtract sampfrom if specified.
- Returns
ann – The annotations of
rhythm
andbeat
, withrhythm
annotatoins in the format of intervals, or mask;beat
annotations in the format of dict orBeatAnn
.- Return type
Note
At head and tail of the record, segments named “NOISE” were added.
- load_beat_ann(rec: Union[str, int], sampfrom: Optional[int] = None, sampto: Optional[int] = None, beat_format: str = 'beat', keep_original: bool = False) Union[Dict[str, numpy.ndarray], List[torch_ecg.databases.base.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.
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 all the beat types (“A”, “N”, “Q”, “V”).
- Return type
- load_data(rec: Union[str, int], leads: Optional[Union[int, List[int]]] = None, sampfrom: Optional[int] = None, sampto: Optional[int] = None, data_format: str = 'channel_first', units: str = 'mV', fs: Optional[numbers.Real] = None, return_fs: bool = False) Union[numpy.ndarray, Tuple[numpy.ndarray, numbers.Real]] [source]¶
Load physical (converted from digital) ECG data, which is more understandable for humans; or load digital signal directly.
- Parameters
rec (str or int) – Record name or index of the record in
all_records
.leads (str or int or Sequence[str] or Sequence[int], optional) – The leads of the ECG data to load. None or “all” for all leads.
sampfrom (int, optional) – Start index of the data to be loaded.
sampto (int, optional) – End index of the data to be loaded.
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”) which is valid only when leads is a single lead
units (str or None, default "mV") – Units of the output signal, can also be “μV” (aliases “uV”, “muV”). None for digital data, without digital-to-physical conversion.
fs (numbers.Real, optional) – Sampling frequency of the output signal. If not None, the loaded data will be resampled to this frequency; if None, self.fs will be used if available and not None; 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 ECG data loaded from the record, with given units and data_format.
data_fs (numbers.Real, optional) – Sampling frequency of the output signal. Returned if return_fs is True.
- load_rhythm_ann(rec: Union[str, int], sampfrom: Optional[int] = None, sampto: Optional[int] = None, rhythm_format: str = 'interval', keep_original: bool = False) Union[Dict[str, list], numpy.ndarray] [source]¶
Load rhythm annotations of the record.
Rhythm annotations are stored in the aux_note attribute of corresponding annotation files. NOTE that qrs annotations (.qrs files) do NOT contain any rhythm annotations.
- 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 ({"interval", "mask"}, optional) – Format of returned annotation, by default “interval”, case insensitive.
keep_original (bool, default False) – If True, indices will keep the same with the annotation file, otherwise subtract sampfrom if specified.
- Returns
ann – Annotations in the format of intervals or mask.
- Return type
Note
At head and tail of the record, segments named “NOISE” were added.
- load_rpeak_indices(rec: Union[str, int], sampfrom: Optional[int] = None, sampto: Optional[int] = None, use_manual: bool = True, keep_original: bool = False) numpy.ndarray [source]¶
Load rpeak indices of the record.
Rpeak indices, or equivalently qrs complex locations, 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.
use_manual (bool, default True) – If True, manually annotated beat annotations (qrs) will be used, 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
rpeak_inds – Locations (indices) of the all the rpeaks (qrs complexes).
- Return type
- plot(rec: Union[str, int], data: Optional[numpy.ndarray] = None, ann: Optional[Dict[str, numpy.ndarray]] = None, beat_ann: Optional[Dict[str, numpy.ndarray]] = None, rpeak_inds: Optional[Union[Sequence[int], numpy.ndarray]] = None, ticks_granularity: int = 0, leads: Optional[Union[int, List[int]]] = None, sampfrom: Optional[int] = None, sampto: Optional[int] = 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 is not None, data of rec will not be used. This is useful when plotting filtered data.
ann (dict, optional) – Rhythm annotations for data, covering those from annotation files, in the form of
{k: l_itv, ...}
, wherek
are listed in self.rhythm_types_map, andl_itv
are of the form of[[a, b], ...]
. Ignored if data is Nonebeat_ann (dict, optional) – Beat annotations for data, covering those from annotation files, in the form of
{k: l_inds, ...}
, wherek
are listed in self.beat_types, and l_inds are array of indices. 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 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 (int or List[int], optional,) – The lead number(s) of the data 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, all leads are forced to have the same y range.
kwargs (dict, optional) – Additional arguments to be passed to matplotlib.pyplot.plot, etc.