Skip to content

Commit

Permalink
match units, labels, and encoding independently while planning (#77)
Browse files Browse the repository at this point in the history
* make unit matching independent of label matching

* pull out encoding matching too

* tests

* bump version
  • Loading branch information
kleinschmidt authored Jun 29, 2023
1 parent 64b49c8 commit 9e899b4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
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.6"
version = "0.11.7"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down
13 changes: 10 additions & 3 deletions src/import_edf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,15 @@ function plan_edf_to_onda_samples(header,
row = (; header..., seconds_per_record, error=nothing)

try
# match physical units and encoding first so that we give users better
# feedback about _which_ thing (labels vs. units) didn't match.
#
# still do it in the try/catch in case edf_to_onda_unit or
# edf_signal_encoding throws an error
row = rowmerge(row;
sample_unit=edf_to_onda_unit(header.physical_dimension, units),
edf_signal_encoding(header, seconds_per_record)...)

edf_label = header.label
for (signal_names, channel_names) in labels
# channel names is iterable of channel specs, which are either "channel"
Expand All @@ -374,9 +383,7 @@ function plan_edf_to_onda_samples(header,
row = rowmerge(row;
channel=matched,
sensor_type=first(signal_names),
sensor_label=first(signal_names),
sample_unit=edf_to_onda_unit(header.physical_dimension, units),
edf_signal_encoding(header, seconds_per_record)...)
sensor_label=first(signal_names))
return PlanV2(row)
end
end
Expand Down
34 changes: 34 additions & 0 deletions test/import.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,40 @@ using StableRNGs
@test isempty(bad_samples)
end

@testset "units labels and encoding matched independently" begin
n_records = 100
edf, edf_channel_indices = make_test_data(StableRNG(42), 256, 512, n_records, Int16)

signal = edf.signals[1]
header = signal.header

plan = plan_edf_to_onda_samples(header, edf.header.seconds_per_record)
no_label = plan_edf_to_onda_samples(header, edf.header.seconds_per_record;
labels=Dict())
no_units = plan_edf_to_onda_samples(header, edf.header.seconds_per_record;
units=Dict())
no_both = plan_edf_to_onda_samples(header, edf.header.seconds_per_record;
units=Dict(), labels=Dict())

@test ismissing(no_label.channel)
@test ismissing(no_label.sensor_type)
@test no_label.sample_unit == plan.sample_unit
@test no_label.sample_resolution_in_unit == plan.sample_resolution_in_unit
@test no_label.sample_offset_in_unit == plan.sample_offset_in_unit

@test no_units.channel == plan.channel
@test no_units.sensor_type == plan.sensor_type
@test ismissing(no_units.sample_unit)
@test no_units.sample_resolution_in_unit == plan.sample_resolution_in_unit
@test no_units.sample_offset_in_unit == plan.sample_offset_in_unit

@test ismissing(no_both.channel)
@test ismissing(no_both.sensor_type)
@test ismissing(no_both.sample_unit)
@test no_both.sample_resolution_in_unit == plan.sample_resolution_in_unit
@test no_both.sample_offset_in_unit == plan.sample_offset_in_unit
end

@testset "de/serialization of plans" begin
edf, _ = make_test_data(StableRNG(42), 256, 512, 100, Int16)
plan = plan_edf_to_onda_samples(edf)
Expand Down

2 comments on commit 9e899b4

@kleinschmidt
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/86528

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.11.7 -m "<description of version>" 9e899b40f6f0923c40ffebd1e5ed603980b9cc6d
git push origin v0.11.7

Please sign in to comment.