Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into eph/format
Browse files Browse the repository at this point in the history
  • Loading branch information
ericphanson committed Oct 17, 2023
2 parents a66f1c9 + e657170 commit 4083868
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
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
4 changes: 4 additions & 0 deletions src/export_edf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ 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 max to min + 1
if smin == smax
smax = smin + one(smax)
end

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

Expand Down
18 changes: 18 additions & 0 deletions test/export.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,22 @@
@test EDF.decode(signal) == vec(decode(samples).data)
end
end

@testset "`reencode_samples` edge case: constant data" begin
# 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) .+ 0x02
samples = Samples(data, info, false)
samples_reenc = OndaEDF.reencode_samples(samples)
@test samples_reenc isa Samples
@test decode(samples_reenc).data == data
end

end

0 comments on commit 4083868

Please sign in to comment.