Skip to content

Commit

Permalink
round TimestampedAnnotationList fields to nearest representable EDF v…
Browse files Browse the repository at this point in the history
…alue (#38)

Co-authored-by: Alex Arslan <[email protected]>
  • Loading branch information
jrevels and ararslan authored Nov 3, 2020
1 parent bca8a2d commit 3493a89
Show file tree
Hide file tree
Showing 3 changed files with 25 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 = "EDF"
uuid = "ccffbfc1-f56e-50fb-a33b-53d1781b2825"
authors = ["Beacon Biosignals, Inc."]
version = "0.5.1"
version = "0.6.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
17 changes: 17 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ const ANNOTATIONS_SIGNAL_LABEL = "EDF Annotations"
A type representing a time-stamped annotations list (TAL).
Note that this type's constructor may attempt to round given `onset_in_seconds` and
`duration_in_seconds` arguments to their nearest representable values in accordance
with the EDF+ specification, which a) represents these values as ASCII, b) constrains
these values to an 8 character limit, and c) does not allow the use of scientific
notation for these fields.
See EDF+ specification for details.
# Fields
Expand All @@ -94,6 +100,17 @@ struct TimestampedAnnotationList
onset_in_seconds::Float64
duration_in_seconds::Union{Float64,Nothing}
annotations::Vector{String}
function TimestampedAnnotationList(onset_in_seconds, duration_in_seconds, annotations)
onset_in_seconds = _nearest_representable_edf_time_value(onset_in_seconds)
duration_in_seconds = _nearest_representable_edf_time_value(duration_in_seconds)
return new(onset_in_seconds, duration_in_seconds, annotations)
end
end

_nearest_representable_edf_time_value(::Nothing) = nothing

function _nearest_representable_edf_time_value(x)
return round(x; digits=(8 - (ndigits(floor(Int, x)) + signbit(x) + isinteger(x))))
end

function Base.:(==)(a::TimestampedAnnotationList, b::TimestampedAnnotationList)
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ const DATADIR = joinpath(@__DIR__, "data")
@test eof(io)
end

@test EDF._edf_repr(EDF._nearest_representable_edf_time_value(-0.0023405432)) == "-0.00234"
@test EDF._edf_repr(EDF._nearest_representable_edf_time_value(0.0023405432)) == "0.002340"
@test EDF._edf_repr(EDF._nearest_representable_edf_time_value(1.002343)) == "1.002343"
@test EDF._edf_repr(EDF._nearest_representable_edf_time_value(1011.05432)) == "1011.054"
@test EDF._edf_repr(EDF._nearest_representable_edf_time_value(-1011.05432)) == "-1011.05"
@test EDF._edf_repr(EDF._nearest_representable_edf_time_value(-1013441.5)) == "-1013442"
@test EDF._edf_repr(EDF._nearest_representable_edf_time_value(-1013441.3)) == "-1013441"
@test EDF._edf_repr(34577777) == "34577777"
@test EDF._edf_repr(0.0345) == "0.034500"
@test EDF._edf_repr(-0.02) == "-0.02000"
Expand Down

2 comments on commit 3493a89

@jrevels
Copy link
Member Author

@jrevels jrevels commented on 3493a89 Nov 3, 2020

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/24113

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.6.0 -m "<description of version>" 3493a89bdcef69e3b4aeea754517f999b0b73d32
git push origin v0.6.0

Please sign in to comment.