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

handle edge case in reencode_samples #88

Merged
merged 7 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OndaEDF"
uuid = "e3ed2cd1-99bf-415e-bb8f-38f4b42a544e"
authors = ["Beacon Biosignals, Inc."]
version = "0.12.2"
version = "0.12.3"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down
5 changes: 5 additions & 0 deletions src/export_edf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ function reencode_samples(samples::Samples, sample_type::Type{<:Integer}=Int16)
# maximize the dynamic range of Int16 encoding.
samples = decode(samples)
smin, smax = extrema(samples.data)
# If the input is flat, normalize to zero and one
ericphanson marked this conversation as resolved.
Show resolved Hide resolved
if smin == smax
smax = one(smax)
smin = zero(smin)
end
ericphanson marked this conversation as resolved.
Show resolved Hide resolved

emin, emax = typemin(sample_type), typemax(sample_type)

Expand Down
15 changes: 15 additions & 0 deletions test/export.jl
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,19 @@
end
end

@testset "`reencode_samples` edge case" begin
ericphanson marked this conversation as resolved.
Show resolved Hide resolved
# Weird encoding
info = SamplesInfoV2(; sensor_type="x",
channels=["x"],
sample_unit="microvolt",
sample_resolution_in_unit=0.001,
sample_offset_in_unit=0,
sample_type=Float64,
sample_rate=1)

data = zeros(UInt64, 1, 2)
samples = Samples(data, info, false)
@test OndaEDF.reencode_samples(samples) isa Samples
ericphanson marked this conversation as resolved.
Show resolved Hide resolved
end

end
Loading