Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
data = wfdb.rdrecord(subject[0][:-4], sampto=sampto)
annotation = wfdb.rdann(subject[1][:-4], 'atr',
sampfrom=sampfrom,
sampto=sampto)
sfreq = data.fs
ecg = data.p_signal[:, 0]
manupeaks = annotation.sample
#algopeaks = peaks_signal(ecg, sfreq)
algopeaks = rpeaks(ecg, sfreq)
# tolerance for match between algorithmic and manual annotation (in sec)
tolerance = 0.05
comparitor = compare_annotations(manupeaks, algopeaks,
int(np.rint(tolerance * sfreq)))
tp = comparitor.tp
fp = comparitor.fp
fn = comparitor.fn
# plt.figure()
# plt.plot(ecg)
# plt.plot(np.square(ecg))
# plt.plot(np.abs(ecg))
# plt.scatter(manupeaks, ecg[manupeaks], c='m')
# plt.scatter(algopeaks, ecg[algopeaks], c='g', marker='X', s=150)
sensitivity.append(float(tp) / (tp + fn))
precision.append(float(tp) / (tp + fp))
print(sensitivity[-1], precision[-1])
record : 1d array
The raw physiological record.
annotation : 1d array
The manual extrema annotations.
Returns
-------
precision : float
The detectors precision on the record given the tolerance.
sensitivity : float
The detectors sensitivity on the record given the tolerance.
"""
detector_annotation = self.detector(record, self.sfreq)
comparitor = compare_annotations(detector_annotation, annotation,
self.tolerance)
tp = comparitor.tp
fp = comparitor.fp
fn = comparitor.fn
sensitivity = tp / (tp + fn)
precision = tp / (tp + fp)
return precision, sensitivity
Maximum difference in millisecond that is permitted between the manual
annotation and the annotation generated by the detector.
detector : function
A function that takes a physiological record as first positional
argument as well as a `sampling_rate` keyword argument.
Returns
-------
precision : float
The detectors precision on the record given the tolerance.
sensitivity : float
The detectors sensitivity on the record given the tolerance.
"""
detector_annotation = detector(record, sampling_rate=sampling_rate)
comparitor = compare_annotations(detector_annotation, annotation, tolerance)
tp = comparitor.tp
fp = comparitor.fp
fn = comparitor.fn
sensitivity = tp / (tp + fn)
precision = tp / (tp + fp)
return precision, sensitivity