Skip to content

Commit 5764124

Browse files
author
Benjamin Moody
committed
plot_wfdb: plot non-smooth records.
If a record is loaded in "non-smooth" ("expanded") mode, it can contain signals of different lengths sampled at different frequencies. In such a case, we want to plot each signal at its original frequency in order to see the effect of the sampling and the temporal relationships between the signals. plot_items now allows the signal argument to be either a numpy array (as in p_signal or d_signal, loaded when 'smooth_frames=True') or a list of arrays (as in e_p_signal or e_d_signal, loaded when 'smooth_frames=False'); in the latter case, plot_wfdb has to calculate and provide the correct per-channel sampling frequencies. (The annotation file, if any, may have its own sampling frequency, which may differ from the signal sampling frequencies. The *default*, if the annotation file doesn't specify a frequency, is always the record frame frequency (fs), not the sampling frequency of any particular signal.)
1 parent 0de1a9d commit 5764124

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

wfdb/plot/plot.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,9 @@ def plot_wfdb(record=None, annotation=None, plot_sym=False,
768768
function, while allowing direct input of WFDB objects.
769769
770770
If the record object is input, the function will extract from it:
771-
- signal values, from the `p_signal` (priority) or `d_signal` attribute
772-
- sampling frequency, from the `fs` attribute
771+
- signal values, from the `e_p_signal`, `e_d_signal`, `p_signal`, or
772+
`d_signal` attribute (in that order of priority.)
773+
- frame frequency, from the `fs` attribute
773774
- signal names, from the `sig_name` attribute
774775
- signal units, from the `units` attribute
775776
@@ -836,7 +837,10 @@ def plot_wfdb(record=None, annotation=None, plot_sym=False,
836837
plot_sym=plot_sym)
837838

838839
if record:
839-
sampling_freq = record.fs
840+
if record.e_p_signal is not None or record.e_d_signal is not None:
841+
sampling_freq = [spf * record.fs for spf in record.samps_per_frame]
842+
else:
843+
sampling_freq = record.fs
840844
else:
841845
sampling_freq = None
842846

@@ -913,11 +917,21 @@ def get_wfdb_plot_items(record, annotation, plot_sym):
913917
"""
914918
# Get record attributes
915919
if record:
916-
if record.p_signal is not None:
920+
if record.e_p_signal is not None:
921+
signal = record.e_p_signal
922+
n_sig = len(signal)
923+
physical = True
924+
elif record.e_d_signal is not None:
925+
signal = record.e_d_signal
926+
n_sig = len(signal)
927+
physical = False
928+
elif record.p_signal is not None:
917929
signal = record.p_signal
930+
n_sig = signal.shape[1]
918931
physical = True
919932
elif record.d_signal is not None:
920933
signal = record.d_signal
934+
n_sig = signal.shape[1]
921935
physical = False
922936
else:
923937
raise ValueError('The record has no signal to plot')
@@ -972,7 +986,7 @@ def get_wfdb_plot_items(record, annotation, plot_sym):
972986
# In this case, omit empty middle channels. This function should
973987
# already process labels and arrangements before passing into
974988
# `plot_items`
975-
sig_chans = set(range(signal.shape[1]))
989+
sig_chans = set(range(n_sig))
976990
all_chans = sorted(sig_chans.union(ann_chans))
977991

978992
# Need to update ylabels and annotation values

0 commit comments

Comments
 (0)