Skip to content

Commit 697445a

Browse files
committed
change minor typos
1 parent c965792 commit 697445a

File tree

4 files changed

+54
-62
lines changed

4 files changed

+54
-62
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ ecg_aligned_80hz = normalizer.transform(ecg)
4747
* `template`: A template ECG created with `create_template()` method. This template is
4848
used as a reference for aligning R-peaks in the ECG signals.
4949

50-
* `select_lead`: Specifies the lead (e.g., 'Lead II', 'Lead V1') for R-peak
51-
and QRST point detection. Different leads can provide varying levels of
50+
* `select_lead`: Specifies the lead (e.g., 'Lead II', 'Lead V1') for R-peak detection. Different leads can provide varying levels of
5251
clarity for these features. Selection via channel numbers 0,1,... .
5352

5453
* `num_workers`: Determines the number of CPU cores to be utilized for
@@ -74,6 +73,8 @@ ecg_aligned_80hz = normalizer.transform(ecg)
7473
* `median_beat`: Calculates the median from a set of aligned beats
7574
and returns a single, representative beat.
7675

76+
* `silent`: Disable all warnings.
77+
7778
## Citation
7879
Please use the following citation:
7980

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ requires = [
1313
name='rlign'
1414
version='1.0'
1515
description='Beat normalization for ecg data.'
16+
readme = "README.md"
1617
requires-python = ">=3.11"
1718
authors=[
1819
{name="Lucas Bickmann"},
@@ -35,4 +36,4 @@ classifiers=[
3536
]
3637

3738
[project.optional-dependencies]
38-
docs = ["sphinx"]
39+
docs = ["sphinx"]

rlign/rlign.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,6 @@ def _normalize_interval(
145145
# switch to defined resample method
146146
match scale_method:
147147
case 'linear':
148-
# limit number of peaks
149-
#source_rpeaks = source_rpeaks[:-1]
150-
151148
medians = []
152149
# iterate over all peaks
153150
for idx, (source_st, source_fs) in enumerate(zip(source_rpeaks, source_rpeaks_intervals)):
@@ -166,7 +163,6 @@ def _normalize_interval(
166163
target_fs
167164
).transpose(1, 0)
168165

169-
170166
if self.median_beat:
171167
if (template_starts[idx] - int(self.template.intervals[0] / 3) < 0 or
172168
template_starts[idx] + self.template.intervals[0] - int(self.template.intervals[0] / 3) > len(
@@ -304,9 +300,7 @@ def _template_transform(
304300
return None, 1
305301

306302
try:
307-
#hr = ecg_process(ecg_lead, sampling_rate=self.sampling_rate)[0]["ECG_Rate"].mean()
308-
309-
# just some basic approximation
303+
# just some basic heart rate approximation
310304
min_factor = 60 / (ecg.shape[1] / self.sampling_rate)
311305
hr = int(len(rpeaks) * min_factor)
312306
except:
@@ -319,8 +313,7 @@ def _template_transform(
319313

320314
return ecg, 1
321315

322-
323-
# limit number of rpeaks to the targets
316+
# limit number of R-peaks to the targets
324317
rpeaks = rpeaks[: len(self.template.rpeaks+1)]
325318

326319
# get the interval lengths of found rpeaks

rlign/utils.py

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import numpy as np
88
import pandas as pd
99

10-
from typing import Optional, Tuple
10+
from typing import Tuple
1111
from scipy.signal import resample
1212
from sklearn.utils import check_array
1313
from neurokit2 import ecg_clean, ecg_peaks
@@ -66,53 +66,52 @@ def find_rpeaks(
6666
ecg_lead: np.ndarray,
6767
sampling_rate: int,
6868
neurokit_method: str = "neurokit",
69-
correct_artifacts: bool = True
70-
) -> Tuple[np.ndarray, dict]:
71-
'''
72-
Internal function which calls neurokit for rpeak and qrs-complex computation.
69+
correct_artifacts: bool = True) -> Tuple[np.ndarray, dict]:
70+
"""
71+
Internal function which calls neurokit for rpeak and qrs-complex computation.
7372
74-
Parameters:
75-
ecg_lead: An array representing a single-lead ECG signal. The input is
76-
expected to be a one-dimensional array of voltage values over time, representing
77-
the electrical activity of the heart as captured by a specific ECG lead.
78-
79-
sampling_rate: Defines the sampling rate for all ECG recordings.
80-
81-
neurokit_method: Chooses the algorithm for R-peak detection from the
82-
NeuroKit package. Different algorithms may offer varying performance
83-
based on the ECG signal characteristics.
84-
85-
correct_artifacts: If set to True, artifact correction is applied
86-
exclusively for R-peak detections, enhancing the accuracy of peak
87-
identification in noisy signals.
88-
89-
Returns:
90-
(rpeaks, qrs_epochs): A pair of elements (rpeaks, qrs_epochs) representing
91-
the outcomes of the R-peak detection and QRS complex computation processes,
92-
respectively. If an error occurs during the processing, the function
93-
returns (None, None), indicating a failure in signal analysis.
94-
'''
95-
try:
96-
# clean the ecg as recommended by neurokit
97-
data_ = ecg_clean(
98-
ecg_lead,
99-
sampling_rate=sampling_rate
100-
)
101-
102-
# caluclate rpeaks
103-
_, r_peaks = ecg_peaks(
104-
data_,
105-
sampling_rate=sampling_rate,
106-
method=neurokit_method,
107-
correct_artifacts=correct_artifacts
108-
)
109-
rpeaks = r_peaks['ECG_R_Peaks'].astype(np.int32)
110-
111-
except Exception as e:
112-
logging.warning(f'Failure in neurokit: {e}\n')
113-
return None, None
114-
115-
return rpeaks
73+
Parameters:
74+
ecg_lead: An array representing a single-lead ECG signal. The input is
75+
expected to be a one-dimensional array of voltage values over time, representing
76+
the electrical activity of the heart as captured by a specific ECG lead.
77+
78+
sampling_rate: Defines the sampling rate for all ECG recordings.
79+
80+
neurokit_method: Chooses the algorithm for R-peak detection from the
81+
NeuroKit package. Different algorithms may offer varying performance
82+
based on the ECG signal characteristics.
83+
84+
correct_artifacts: If set to True, artifact correction is applied
85+
exclusively for R-peak detections, enhancing the accuracy of peak
86+
identification in noisy signals.
87+
88+
Returns:
89+
(rpeaks, qrs_epochs): A pair of elements (rpeaks, qrs_epochs) representing
90+
the outcomes of the R-peak detection and QRS complex computation processes,
91+
respectively. If an error occurs during the processing, the function
92+
returns (None, None), indicating a failure in signal analysis.
93+
"""
94+
try:
95+
# clean the ecg as recommended by neurokit
96+
data_ = ecg_clean(
97+
ecg_lead,
98+
sampling_rate=sampling_rate
99+
)
100+
101+
# caluclate rpeaks
102+
_, r_peaks = ecg_peaks(
103+
data_,
104+
sampling_rate=sampling_rate,
105+
method=neurokit_method,
106+
correct_artifacts=correct_artifacts
107+
)
108+
rpeaks = r_peaks['ECG_R_Peaks'].astype(np.int32)
109+
110+
except Exception as e:
111+
logging.warning(f'Failure in neurokit: {e}\n')
112+
return None, None
113+
114+
return rpeaks
116115

117116

118117
def _resample_multichannel(xs, fs, fs_target):
@@ -160,8 +159,6 @@ def _resample_signal(x, fs, fs_target):
160159
Note:
161160
The method have been modified from wfdbs resample_multichan and resample_sig.
162161
"""
163-
#t = np.arange(x.shape[0]).astype("float64")
164-
165162
if fs == fs_target:
166163
return x
167164

@@ -181,4 +178,4 @@ def _check_3d_array(X):
181178
X = check_array(X, ensure_2d=False, allow_nd=True)
182179
if X.ndim != 3:
183180
raise ValueError(f"X must be 3-dimensional (got {X.ndim}).")
184-
return X
181+
return X

0 commit comments

Comments
 (0)