Skip to content

Commit da3bce5

Browse files
author
Benjamin Moody
committed
New internal function _expand_signal.
This function accepts either None, a one-dimensional array, a two-dimensional array, or a list (or other non-numpy sequence) of one-dimensional arrays, and converts the result to list of one-dimensional arrays (where each element represents one channel.) This will be used by various plotting functions to accept "non-smooth" signal data as the 'signal' argument while keeping backward compatibility.
1 parent 5fb38c1 commit da3bce5

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

wfdb/plot/plot.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,43 @@
88
from wfdb.io.annotation import Annotation
99

1010

11+
def _expand_channels(signal):
12+
"""
13+
Convert application-specified signal data to a list.
14+
15+
Parameters
16+
----------
17+
signal : 1d or 2d numpy array or list or None
18+
The uniformly sampled signal or signals to be plotted. If signal
19+
is a one-dimensional array, it is assumed to represent a single
20+
channel. If it is a two-dimensional array, axes 0 and 1 must
21+
represent time and channel number respectively. Otherwise it must
22+
be a list of one-dimensional arrays (one for each channel.)
23+
24+
Returns
25+
-------
26+
signal : list
27+
A list of one-dimensional arrays (one for each channel.)
28+
29+
"""
30+
if signal is None:
31+
return []
32+
elif hasattr(signal, 'ndim'):
33+
if signal.ndim == 1:
34+
return [signal]
35+
elif signal.ndim == 2:
36+
return list(signal.transpose())
37+
else:
38+
raise ValueError('invalid shape for signal array: {}'.format(
39+
signal.shape))
40+
else:
41+
signal = list(signal)
42+
if any(s.ndim != 1 for s in signal):
43+
raise ValueError('invalid shape for signal array(s): {}'.format(
44+
[s.shape for s in signal]))
45+
return signal
46+
47+
1148
def _get_sampling_freq(sampling_freq, n_sig, frame_freq):
1249
"""
1350
Convert application-specified sampling frequency to a list.

0 commit comments

Comments
 (0)