Skip to content

Commit be23d6a

Browse files
author
Benjamin Moody
committed
get_plot_dims: accept non-smooth signal data as input.
When plotting signals, in addition to allowing the signal argument to be a one-dimensional or two-dimensional array, allow it to be a list of one-dimensional arrays (so that each channel can have a different length.) Using _expand_channels here, as in plot_annotation, allows the logic to be simplified. The sig_len return value makes no sense if the channels have different lengths; this return value is now marked as deprecated, and will be set to None if the channel lengths differ.
1 parent 1dc98ed commit be23d6a

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

wfdb/plot/plot.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,12 @@ def get_plot_dims(signal, ann_samp):
275275
276276
Parameters
277277
----------
278-
signal : 1d or 2d numpy array, optional
279-
The uniformly sampled signal to be plotted. If signal.ndim is 1, it is
280-
assumed to be a one channel signal. If it is 2, axes 0 and 1, must
281-
represent time and channel number respectively.
278+
signal : 1d or 2d numpy array or list, optional
279+
The uniformly sampled signal or signals to be plotted. If signal
280+
is a one-dimensional array, it is assumed to represent a single
281+
channel. If it is a two-dimensional array, axes 0 and 1 must
282+
represent time and channel number respectively. Otherwise it must
283+
be a list of one-dimensional arrays (one for each channel).
282284
ann_samp: list, optional
283285
A list of annotation locations to plot, with each list item
284286
corresponding to a different channel. List items may be:
@@ -297,7 +299,7 @@ def get_plot_dims(signal, ann_samp):
297299
Returns
298300
-------
299301
sig_len : int
300-
The signal length (per channel) of the dat file.
302+
The signal length (per channel) of the dat file. Deprecated.
301303
n_sig : int
302304
The number of signals contained in the dat file.
303305
n_annot : int
@@ -306,13 +308,14 @@ def get_plot_dims(signal, ann_samp):
306308
The max between number of signals and annotations.
307309
308310
"""
309-
if signal is not None:
310-
if signal.ndim == 1:
311-
sig_len = len(signal)
312-
n_sig = 1
313-
else:
314-
sig_len = signal.shape[0]
315-
n_sig = signal.shape[1]
311+
# Convert signal to a list if needed
312+
signal = _expand_channels(signal)
313+
314+
if signal:
315+
n_sig = len(signal)
316+
sig_len = len(signal[0])
317+
if any(len(s) != sig_len for s in signal):
318+
sig_len = None
316319
else:
317320
sig_len = 0
318321
n_sig = 0

0 commit comments

Comments
 (0)