Skip to content

API Reference

Run the WFDB wqrs detector on one or more ECG leads.

Source code in src/wfdb_qrs_kit/detectors.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def detect_wqrs(
    signal: Any,
    *,
    fs: float | int,
    leads: list[str] | tuple[str, ...] | None = None,
    axis: int = 0,
    executable: str | Path | None = None,
    cache_dir: str | Path | None = None,
    work_dir: str | Path | None = None,
    nan_policy: NanPolicy = "raise",
    record_id: str | None = None,
    timeout_sec: float | None = 60.0,
) -> list[DetectionResult]:
    """Run the WFDB `wqrs` detector on one or more ECG leads."""

    norm = normalize_signal(signal, fs=fs, leads=leads, axis=axis, nan_policy=nan_policy)
    exe = find_executable("wqrs", explicit=executable, cache_dir=cache_dir)
    samples, meta = run_detector_on_record(
        detector_name="wqrs",
        annotator="wqrs",
        executable=exe,
        data=norm.data,
        fs=norm.fs,
        record_id=record_id,
        work_dir=work_dir,
        warmup_sec=0.0,
        timeout_sec=timeout_sec,
    )
    return _result_list(
        samples_by_lead=samples,
        detector="wqrs",
        fs=norm.fs,
        leads=norm.leads,
        base_metadata={
            **norm.metadata,
            **meta,
            "executable": str(exe),
        },
    )

Run the EP Limited / Hamilton detector on one or more ECG leads.

Source code in src/wfdb_qrs_kit/detectors.py
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
def detect_eplimited(
    signal: Any,
    *,
    fs: float | int,
    leads: list[str] | tuple[str, ...] | None = None,
    axis: int = 0,
    executable: str | Path | None = None,
    cache_dir: str | Path | None = None,
    work_dir: str | Path | None = None,
    nan_policy: NanPolicy = "raise",
    record_id: str | None = None,
    warmup_sec: float = 8.0,
    timeout_sec: float | None = 60.0,
) -> list[DetectionResult]:
    """Run the EP Limited / Hamilton detector on one or more ECG leads."""

    norm = normalize_signal(signal, fs=fs, leads=leads, axis=axis, nan_policy=nan_policy)
    exe = find_executable("eplimited", explicit=executable, cache_dir=cache_dir)
    samples, meta = run_detector_on_record(
        detector_name="eplimited",
        annotator="epl",
        executable=exe,
        data=norm.data,
        fs=norm.fs,
        record_id=record_id,
        work_dir=work_dir,
        warmup_sec=warmup_sec,
        timeout_sec=timeout_sec,
    )
    return _result_list(
        samples_by_lead=samples,
        detector="eplimited",
        fs=norm.fs,
        leads=norm.leads,
        base_metadata={
            **norm.metadata,
            **meta,
            "executable": str(exe),
        },
    )

Run both supported paper-era QRS detectors on the same ECG signal.

Source code in src/wfdb_qrs_kit/detectors.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
def detect_both(
    signal: Any,
    *,
    fs: float | int,
    leads: list[str] | tuple[str, ...] | None = None,
    axis: int = 0,
    wqrs_executable: str | Path | None = None,
    eplimited_executable: str | Path | None = None,
    cache_dir: str | Path | None = None,
    work_dir: str | Path | None = None,
    nan_policy: NanPolicy = "raise",
    record_id: str | None = None,
    eplimited_warmup_sec: float = 8.0,
    timeout_sec: float | None = 60.0,
) -> dict[str, list[DetectionResult]]:
    """Run both supported paper-era QRS detectors on the same ECG signal."""

    return {
        "wqrs": detect_wqrs(
            signal,
            fs=fs,
            leads=leads,
            axis=axis,
            executable=wqrs_executable,
            cache_dir=cache_dir,
            work_dir=work_dir,
            nan_policy=nan_policy,
            record_id=record_id,
            timeout_sec=timeout_sec,
        ),
        "eplimited": detect_eplimited(
            signal,
            fs=fs,
            leads=leads,
            axis=axis,
            executable=eplimited_executable,
            cache_dir=cache_dir,
            work_dir=work_dir,
            nan_policy=nan_policy,
            record_id=record_id,
            warmup_sec=eplimited_warmup_sec,
            timeout_sec=timeout_sec,
        ),
    }

Run an ordered collection of detector names and return results by detector.

Source code in src/wfdb_qrs_kit/detectors.py
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
def detect_many(
    signal: Any,
    *,
    fs: float | int,
    detectors: Iterable[DetectorName] = ("wqrs", "eplimited"),
    leads: list[str] | tuple[str, ...] | None = None,
    axis: int = 0,
    executables: dict[str, str | Path] | None = None,
    cache_dir: str | Path | None = None,
    work_dir: str | Path | None = None,
    nan_policy: NanPolicy = "raise",
    record_id: str | None = None,
    eplimited_warmup_sec: float = 8.0,
    timeout_sec: float | None = 60.0,
) -> dict[str, list[DetectionResult]]:
    """Run an ordered collection of detector names and return results by detector."""

    exe = executables or {}
    out: dict[str, list[DetectionResult]] = {}
    for detector in detectors:
        if detector == "wqrs":
            out["wqrs"] = detect_wqrs(
                signal,
                fs=fs,
                leads=leads,
                axis=axis,
                executable=exe.get("wqrs"),
                cache_dir=cache_dir,
                work_dir=work_dir,
                nan_policy=nan_policy,
                record_id=record_id,
                timeout_sec=timeout_sec,
            )
        elif detector == "eplimited":
            out["eplimited"] = detect_eplimited(
                signal,
                fs=fs,
                leads=leads,
                axis=axis,
                executable=exe.get("eplimited"),
                cache_dir=cache_dir,
                work_dir=work_dir,
                nan_policy=nan_policy,
                record_id=record_id,
                warmup_sec=eplimited_warmup_sec,
                timeout_sec=timeout_sec,
            )
        else:
            raise ValueError(f"unsupported detector: {detector!r}")
    return out

Detected QRS sample indices for one detector on one lead.

Source code in src/wfdb_qrs_kit/types.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
@dataclass(frozen=True)
class DetectionResult:
    """Detected QRS sample indices for one detector on one lead."""

    samples: np.ndarray
    detector: str
    fs: float
    lead_name: str
    metadata: Mapping[str, Any] = field(default_factory=dict)

    @property
    def count(self) -> int:
        return len(self.samples)

    @property
    def times_sec(self) -> np.ndarray:
        return self.samples.astype(np.float64) / float(self.fs)