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

Expose dither_storage as kwarg #72

Merged
merged 7 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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.11.4"
version = "0.11.5"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down
18 changes: 12 additions & 6 deletions src/import_edf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`. `dither_storage=nothing` disables dithering.
"""
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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -605,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.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wordsmithing welcome here too


!!! note

Expand All @@ -620,7 +626,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)
kimlaberinto marked this conversation as resolved.
Show resolved Hide resolved
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])
Expand All @@ -639,7 +645,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,
kimlaberinto marked this conversation as resolved.
Show resolved Hide resolved
missing)
dither_storage)
kimlaberinto marked this conversation as resolved.
Show resolved Hide resolved
else
encoded_samples = edf_signal.samples
end
Expand Down