Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change in type promotion. Fixes to _signal.py #507

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions wfdb/io/_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2319,11 +2319,10 @@ def wr_dat_file(

if fmt == "80":
# convert to 8 bit offset binary form
d_signal = d_signal + 128
# Concatenate into 1D
d_signal = d_signal.reshape(-1)
# Convert to un_signed 8 bit dtype to write
b_write = d_signal.astype("uint8")
d_signal += 128

# Convert to unsigned 8 bit dtype to write (and flatten if necessary)
b_write = d_signal.astype("uint8").reshape(-1)

elif fmt == "212":
# Each sample is represented by a 12 bit two's complement
Expand All @@ -2336,7 +2335,7 @@ def wr_dat_file(
# repeated for each successive pair of samples.

# convert to 12 bit two's complement
d_signal[d_signal < 0] = d_signal[d_signal < 0] + 4096
d_signal[d_signal < 0] += 4096

# Concatenate into 1D
d_signal = d_signal.reshape(-1)
Expand Down Expand Up @@ -2371,7 +2370,8 @@ def wr_dat_file(

elif fmt == "16":
# convert to 16 bit two's complement
d_signal[d_signal < 0] = d_signal[d_signal < 0] + 65536
d_signal = d_signal.astype(np.uint16)

# Split samples into separate bytes using binary masks
b1 = d_signal & [255] * tsamps_per_frame
b2 = (d_signal & [65280] * tsamps_per_frame) >> 8
Expand All @@ -2383,8 +2383,8 @@ def wr_dat_file(
# Convert to un_signed 8 bit dtype to write
b_write = b_write.astype("uint8")
elif fmt == "24":
# convert to 24 bit two's complement
d_signal[d_signal < 0] = d_signal[d_signal < 0] + 16777216
# convert to 32 bit two's complement (as int24 not an option)
d_signal = d_signal.astype(np.uint32)
# Split samples into separate bytes using binary masks
b1 = d_signal & [255] * tsamps_per_frame
b2 = (d_signal & [65280] * tsamps_per_frame) >> 8
Expand All @@ -2400,7 +2400,8 @@ def wr_dat_file(

elif fmt == "32":
# convert to 32 bit two's complement
d_signal[d_signal < 0] = d_signal[d_signal < 0] + 4294967296
d_signal = d_signal.astype(np.uint32)

# Split samples into separate bytes using binary masks
b1 = d_signal & [255] * tsamps_per_frame
b2 = (d_signal & [65280] * tsamps_per_frame) >> 8
Expand Down
Loading