Skip to content

Commit 132d097

Browse files
author
Benjamin Moody
committed
wr_dat_file: consistently set n_sig and tsamps_per_frame.
Previously the variable "n_sig" was used confusingly to mean different things at different points in the function. Instead, set these variables consistently: n_sig is the number of signals, samps_per_frame is the number of samples per frame of each signal, and tsamps_per_frame is the sum of samps_per_frame (which is also the number of columns of the reshaped d_signal array.)
1 parent 13b7633 commit 132d097

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

wfdb/io/_signal.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,9 +2303,13 @@ def wr_dat_file(
23032303
# Create a copy to prevent overwrite
23042304
d_signal = d_signal.copy()
23052305

2306-
# This n_sig is used for making list items.
2307-
# Does not necessarily represent number of signals (ie. for expanded=True)
2308-
n_sig = d_signal.shape[1]
2306+
# Non-expanded format always has 1 sample per frame
2307+
n_sig = d_signal.shape[1]
2308+
samps_per_frame = [1] * n_sig
2309+
2310+
# Total number of samples per frame (equal to number of signals if
2311+
# expanded=False, but may be greater for expanded=True)
2312+
tsamps_per_frame = d_signal.shape[1]
23092313

23102314
if fmt == "80":
23112315
# convert to 8 bit offset binary form
@@ -2363,8 +2367,8 @@ def wr_dat_file(
23632367
# convert to 16 bit two's complement
23642368
d_signal[d_signal < 0] = d_signal[d_signal < 0] + 65536
23652369
# Split samples into separate bytes using binary masks
2366-
b1 = d_signal & [255] * n_sig
2367-
b2 = (d_signal & [65280] * n_sig) >> 8
2370+
b1 = d_signal & [255] * tsamps_per_frame
2371+
b2 = (d_signal & [65280] * tsamps_per_frame) >> 8
23682372
# Interweave the bytes so that the same samples' bytes are consecutive
23692373
b1 = b1.reshape((-1, 1))
23702374
b2 = b2.reshape((-1, 1))
@@ -2376,9 +2380,9 @@ def wr_dat_file(
23762380
# convert to 24 bit two's complement
23772381
d_signal[d_signal < 0] = d_signal[d_signal < 0] + 16777216
23782382
# Split samples into separate bytes using binary masks
2379-
b1 = d_signal & [255] * n_sig
2380-
b2 = (d_signal & [65280] * n_sig) >> 8
2381-
b3 = (d_signal & [16711680] * n_sig) >> 16
2383+
b1 = d_signal & [255] * tsamps_per_frame
2384+
b2 = (d_signal & [65280] * tsamps_per_frame) >> 8
2385+
b3 = (d_signal & [16711680] * tsamps_per_frame) >> 16
23822386
# Interweave the bytes so that the same samples' bytes are consecutive
23832387
b1 = b1.reshape((-1, 1))
23842388
b2 = b2.reshape((-1, 1))
@@ -2392,10 +2396,10 @@ def wr_dat_file(
23922396
# convert to 32 bit two's complement
23932397
d_signal[d_signal < 0] = d_signal[d_signal < 0] + 4294967296
23942398
# Split samples into separate bytes using binary masks
2395-
b1 = d_signal & [255] * n_sig
2396-
b2 = (d_signal & [65280] * n_sig) >> 8
2397-
b3 = (d_signal & [16711680] * n_sig) >> 16
2398-
b4 = (d_signal & [4278190080] * n_sig) >> 24
2399+
b1 = d_signal & [255] * tsamps_per_frame
2400+
b2 = (d_signal & [65280] * tsamps_per_frame) >> 8
2401+
b3 = (d_signal & [16711680] * tsamps_per_frame) >> 16
2402+
b4 = (d_signal & [4278190080] * tsamps_per_frame) >> 24
23992403
# Interweave the bytes so that the same samples' bytes are consecutive
24002404
b1 = b1.reshape((-1, 1))
24012405
b2 = b2.reshape((-1, 1))

0 commit comments

Comments
 (0)