Skip to content

Commit 7ed6c24

Browse files
committed
Adjusts variable names, adds -p option
1 parent d93b8dc commit 7ed6c24

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

wfdb/io/record.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4097,8 +4097,8 @@ def wfdbtime(record_name, input_times, pn_dir=None):
40974097

40984098

40994099
def sigavg(record_name, extension, pn_dir=None, return_df=False,
4100-
start_range=-0.05, stop_range=0.05, time_start=0, time_stop=-1,
4101-
verbose=False):
4100+
start_range=-0.05, stop_range=0.05, ann_type='all', start_time=0,
4101+
stop_time=-1, verbose=False):
41024102
"""
41034103
A common problem in signal processing is to determine the shape of a
41044104
recurring waveform in the presence of noise. If the waveform recurs
@@ -4139,10 +4139,14 @@ def sigavg(record_name, extension, pn_dir=None, return_df=False,
41394139
Set the measurement window relative to QRS annotations. Negative
41404140
values correspond to offsets that precede the annotations. The default
41414141
is 0.05 seconds.
4142-
time_start : float, int, optional
4142+
ann_type : list[str], str, optional
4143+
Include annotations of the specified types only (i.e. 'N'). Multiple
4144+
types are also accepted (i.e. ['V','N']). The default is 'all' which
4145+
means to include all QRS annotations.
4146+
start_time : float, int, optional
41434147
Begin at the specified time in record. The default is 0 which denotes
41444148
the start of the record.
4145-
time_stop : float, int, optional
4149+
stop_time : float, int, optional
41464150
Process until the specified time in record. The default is -1 which
41474151
denotes the end of the record.
41484152
verbose : bool, optional
@@ -4158,14 +4162,14 @@ def sigavg(record_name, extension, pn_dir=None, return_df=False,
41584162
"""
41594163
if start_range >= stop_range:
41604164
raise Exception('`start_range` must be less than `stop_range`')
4161-
if time_start == time_stop:
4162-
raise Exception('`time_start` must be different than `time_stop`')
4163-
if (time_stop != -1) and (time_start >= time_stop):
4164-
raise Exception('`time_start` must be less than `time_stop`')
4165-
if time_start < 0:
4166-
raise Exception('`time_start` must be at least 0')
4167-
if (time_stop != -1) and (time_stop <= 0):
4168-
raise Exception('`time_stop` must be at least greater than 0')
4165+
if start_time == stop_time:
4166+
raise Exception('`start_time` must be different than `stop_time`')
4167+
if (stop_time != -1) and (start_time >= stop_time):
4168+
raise Exception('`start_time` must be less than `stop_time`')
4169+
if start_time < 0:
4170+
raise Exception('`start_time` must be at least 0')
4171+
if (stop_time != -1) and (stop_time <= 0):
4172+
raise Exception('`stop_time` must be at least greater than 0')
41694173

41704174
if (pn_dir is not None) and ('.' not in pn_dir):
41714175
dir_list = pn_dir.split('/')
@@ -4175,10 +4179,10 @@ def sigavg(record_name, extension, pn_dir=None, return_df=False,
41754179
rec = rdrecord(record_name, pn_dir=pn_dir, physical=False)
41764180
ann = annotation.rdann(record_name, extension)
41774181

4178-
if time_stop == -1:
4179-
time_stop = max(ann.sample) / ann.fs
4180-
samp_start = int(time_start * ann.fs)
4181-
samp_stop = int(time_stop * ann.fs)
4182+
if stop_time == -1:
4183+
stop_time = max(ann.sample) / ann.fs
4184+
samp_start = int(start_time * ann.fs)
4185+
samp_stop = int(stop_time * ann.fs)
41824186
filtered_samples = ann.sample[(ann.sample>=samp_start) & (ann.sample<=samp_stop)]
41834187

41844188
times = np.arange(int(start_range*rec.fs) / rec.fs,
@@ -4188,12 +4192,16 @@ def sigavg(record_name, extension, pn_dir=None, return_df=False,
41884192

41894193
n_beats = 0
41904194
initial_sig_avgs = np.zeros((times.shape[0],rec.n_sig))
4195+
all_symbols = [a.symbol for a in annotation.ann_labels]
4196+
41914197
for samp in filtered_samples:
41924198
samp_i = np.where(ann.sample==samp)[0][0]
4193-
4194-
all_symbols = [a.symbol for a in annotation.ann_labels]
4199+
current_ann = ann.symbol[samp_i]
4200+
if (ann_type != 'all') and (((type(ann_type) is str) and (current_ann != ann_type)) or
4201+
((type(ann_type) is list) and (current_ann not in ann_type))):
4202+
continue
41954203
try:
4196-
if not annotation.is_qrs[all_symbols.index(ann.symbol[samp_i])]:
4204+
if not annotation.is_qrs[all_symbols.index(current_ann)]:
41974205
continue
41984206
except ValueError:
41994207
continue

0 commit comments

Comments
 (0)