diff --git a/Project.toml b/Project.toml index 050ed26..ffd0ab2 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.6" +version = "0.11.7" [deps] Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" diff --git a/src/import_edf.jl b/src/import_edf.jl index b097090..eb7dce9 100644 --- a/src/import_edf.jl +++ b/src/import_edf.jl @@ -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" @@ -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 diff --git a/test/import.jl b/test/import.jl index 610e6b8..6c61c66 100644 --- a/test/import.jl +++ b/test/import.jl @@ -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)