From 049b34a7d9d0ef58f7887b1637217e7fa6da6bc4 Mon Sep 17 00:00:00 2001 From: Kim Laberinto Date: Thu, 11 May 2023 14:45:14 -0500 Subject: [PATCH 1/7] Expose dither_storage as kwarg --- src/import_edf.jl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/import_edf.jl b/src/import_edf.jl index b8510f0..4de4950 100644 --- a/src/import_edf.jl +++ b/src/import_edf.jl @@ -485,7 +485,7 @@ grouper(var::Symbol) = grouper((var, )) # return Samples for each :onda_signal_index """ - edf_to_onda_samples(edf::EDF.File, plan_table; validate=true) + edf_to_onda_samples(edf::EDF.File, plan_table; validate=true, dither_storage=missing) Convert Signals found in an EDF File to `Onda.Samples` according to the plan specified in `plan_table` (e.g., as generated by [`plan_edf_to_onda_samples`](@ref)), returning an @@ -507,8 +507,11 @@ not be matched or otherwise caused an error during execution are not returned. If `validate=true` (the default), the plan is validated against the [`FilePlanV2`](@ref) schema, and the signal headers in the `EDF.File`. + +If `dither_storage=missing` (the default), dither storage is allocated automatically +as specified in the docstring for `Onda.encode`. """ -function edf_to_onda_samples(edf::EDF.File, plan_table; validate=true) +function edf_to_onda_samples(edf::EDF.File, plan_table; validate=true, dither_storage=missing) true_signals = filter(x -> isa(x, EDF.Signal), edf.signals) @@ -539,7 +542,7 @@ function edf_to_onda_samples(edf::EDF.File, plan_table; validate=true) else signals = [true_signals[row.edf_signal_index] for row in rows] samples = onda_samples_from_edf_signals(SamplesInfoV2(info), signals, - edf.header.seconds_per_record) + edf.header.seconds_per_record; dither_storage) end return (; idx, samples, plan_rows=rows) catch e @@ -620,7 +623,7 @@ a signal, its encoded (usually `Int16`) data is copied directly into the """ function onda_samples_from_edf_signals(target::SamplesInfoV2, edf_signals, - edf_seconds_per_record) + edf_seconds_per_record; dither_storage) sample_count = length(first(edf_signals).samples) if !all(length(s.samples) == sample_count for s in edf_signals) error("mismatched sample counts between `EDF.Signal`s: ", [length(s.samples) for s in edf_signals]) @@ -639,7 +642,7 @@ function onda_samples_from_edf_signals(target::SamplesInfoV2, edf_signals, edf_signal.samples) encoded_samples = Onda.encode(sample_type(target), target.sample_resolution_in_unit, target.sample_offset_in_unit, decoded_samples, - missing) + dither_storage) else encoded_samples = edf_signal.samples end From 095aeb201131d595395392dee6815f1934c90285 Mon Sep 17 00:00:00 2001 From: Kim Laberinto Date: Thu, 11 May 2023 14:51:13 -0500 Subject: [PATCH 2/7] Add mention of `dither_storage` in docstring --- src/import_edf.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/import_edf.jl b/src/import_edf.jl index 4de4950..dd66830 100644 --- a/src/import_edf.jl +++ b/src/import_edf.jl @@ -608,13 +608,16 @@ end """ OndaEDF.onda_samples_from_edf_signals(target::Onda.SamplesInfo, edf_signals, - edf_seconds_per_record) + edf_seconds_per_record; dither_storage) Generate an `Onda.Samples` struct from an iterable of `EDF.Signal`s, based on the `Onda.SamplesInfo` in `target`. This checks for matching sample rates in the source signals. If the encoding of `target` is the same as the encoding in a signal, its encoded (usually `Int16`) data is copied directly into the `Samples` data matrix; otherwise it is re-encoded. + +`dither_storage` keyword argument is used for `Onda.encode`. See `Onda.encode`'s +docstring for more details. !!! note From 04321505e265c9a8255ce1616af1cbc8c5de9361 Mon Sep 17 00:00:00 2001 From: Kim Laberinto Date: Thu, 11 May 2023 14:56:13 -0500 Subject: [PATCH 3/7] Add `dither_storage=nothing` sentence Co-authored-by: Phillip Alday --- src/import_edf.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/import_edf.jl b/src/import_edf.jl index dd66830..999d1fe 100644 --- a/src/import_edf.jl +++ b/src/import_edf.jl @@ -509,7 +509,7 @@ If `validate=true` (the default), the plan is validated against the [`FilePlanV2`](@ref) schema, and the signal headers in the `EDF.File`. If `dither_storage=missing` (the default), dither storage is allocated automatically -as specified in the docstring for `Onda.encode`. +as specified in the docstring for `Onda.encode`. `dither_storage=nothing` disables dithering. """ function edf_to_onda_samples(edf::EDF.File, plan_table; validate=true, dither_storage=missing) From 4d49f9564c7c7fcd6a16ba5120949e1965331052 Mon Sep 17 00:00:00 2001 From: Kim Laberinto Date: Thu, 11 May 2023 14:57:04 -0500 Subject: [PATCH 4/7] Bump patch --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index d008362..7192528 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "OndaEDF" uuid = "e3ed2cd1-99bf-415e-bb8f-38f4b42a544e" authors = ["Beacon Biosignals, Inc."] -version = "0.11.4" +version = "0.11.5" [deps] Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" From b90e4b782e9803b33fd48ec16ffda1edc0e10bc7 Mon Sep 17 00:00:00 2001 From: Kim Laberinto Date: Thu, 11 May 2023 15:11:49 -0500 Subject: [PATCH 5/7] Set default kwarg in OndaEDF.onda_samples_from_edf_signals --- src/import_edf.jl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/import_edf.jl b/src/import_edf.jl index 999d1fe..5c41567 100644 --- a/src/import_edf.jl +++ b/src/import_edf.jl @@ -608,7 +608,7 @@ end """ OndaEDF.onda_samples_from_edf_signals(target::Onda.SamplesInfo, edf_signals, - edf_seconds_per_record; dither_storage) + edf_seconds_per_record; dither_storage=missing) Generate an `Onda.Samples` struct from an iterable of `EDF.Signal`s, based on the `Onda.SamplesInfo` in `target`. This checks for matching sample rates in @@ -616,8 +616,9 @@ the source signals. If the encoding of `target` is the same as the encoding in a signal, its encoded (usually `Int16`) data is copied directly into the `Samples` data matrix; otherwise it is re-encoded. -`dither_storage` keyword argument is used for `Onda.encode`. See `Onda.encode`'s -docstring for more details. +If `dither_storage=missing` (the default), dither storage is allocated automatically +as specified in the docstring for `Onda.encode`. `dither_storage=nothing` disables dithering. +See `Onda.encode`'s docstring for more details. !!! note @@ -626,7 +627,7 @@ docstring for more details. """ function onda_samples_from_edf_signals(target::SamplesInfoV2, edf_signals, - edf_seconds_per_record; dither_storage) + edf_seconds_per_record; dither_storage=missing) sample_count = length(first(edf_signals).samples) if !all(length(s.samples) == sample_count for s in edf_signals) error("mismatched sample counts between `EDF.Signal`s: ", [length(s.samples) for s in edf_signals]) From 0dc2e78d63fb7c887e37a98490eef69c909048cc Mon Sep 17 00:00:00 2001 From: Kim Laberinto Date: Thu, 11 May 2023 15:33:16 -0500 Subject: [PATCH 6/7] Add try Co-authored-by: Dave Kleinschmidt --- src/import_edf.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/import_edf.jl b/src/import_edf.jl index 5c41567..e4774b6 100644 --- a/src/import_edf.jl +++ b/src/import_edf.jl @@ -644,8 +644,9 @@ function onda_samples_from_edf_signals(target::SamplesInfoV2, edf_signals, decoded_samples = Onda.decode(edf_encoding.sample_resolution_in_unit, edf_encoding.sample_offset_in_unit, edf_signal.samples) - encoded_samples = Onda.encode(sample_type(target), target.sample_resolution_in_unit, - target.sample_offset_in_unit, decoded_samples, + encoded_samples = try + Onda.encode(sample_type(target), target.sample_resolution_in_unit, + target.sample_offset_in_unit, decoded_samples, dither_storage) else encoded_samples = edf_signal.samples From 729778d510863e4521b6c5ae6720591a159e1ef5 Mon Sep 17 00:00:00 2001 From: Kim Laberinto Date: Thu, 11 May 2023 15:33:24 -0500 Subject: [PATCH 7/7] Add catch Co-authored-by: Dave Kleinschmidt --- src/import_edf.jl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/import_edf.jl b/src/import_edf.jl index e4774b6..b097090 100644 --- a/src/import_edf.jl +++ b/src/import_edf.jl @@ -647,7 +647,13 @@ function onda_samples_from_edf_signals(target::SamplesInfoV2, edf_signals, encoded_samples = try Onda.encode(sample_type(target), target.sample_resolution_in_unit, target.sample_offset_in_unit, decoded_samples, - dither_storage) + dither_storage) + catch e + if e isa DomainError + @warn "DomainError during `Onda.encode` can be due to a dithering bug; try calling with `dither_storage=nothing` to disable dithering." + end + rethrow() + end else encoded_samples = edf_signal.samples end