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

Test MNE can read our exports #71

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style = "yas"
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.4' # Earliest supported version
- '1.6' # Earliest supported version
- '1' # Latest release
- 'nightly'
os:
Expand Down
8 changes: 6 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[compat]
Accessors = "0.1"
BitIntegers = "0.2"
FilePathsBase = "0.9.13"
julia = "1.4"
PyMNE = "0.2.2"
julia = "1.6"

[extras]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
FilePathsBase = "48062228-2e41-5def-b9a4-89aafe57970f"
PyMNE = "6c5003b2-cbe8-491c-a0d1-70088e6a0fd6"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["FilePathsBase", "Test"]
test = ["Accessors", "FilePathsBase", "PyMNE", "Test"]
30 changes: 30 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ using EDF: TimestampedAnnotationList, PatientID, RecordingID, SignalHeader,
using Dates
using FilePathsBase
using Test
using PyMNE
using Accessors

#####
##### Testing utilities
Expand Down Expand Up @@ -33,6 +35,17 @@ end

deep_equal(a::T, b::S) where {T,S} = false

function mne_read(edf)
tmpfile = joinpath(mktempdir(), "test.edf")
EDF.write(tmpfile, edf)
# Check we can load it and do something with it
py = PyMNE.io.read_raw_edf(tmpfile; verbose=false)
py.load_data(; verbose=false)
data = pyconvert(Array, py.get_data())
@test data isa Matrix
return py
end

#####
##### Actual tests
#####
Expand Down Expand Up @@ -93,6 +106,14 @@ const DATADIR = joinpath(@__DIR__, "data")
EDF.read!(file)
@test deep_equal(edf.signals, file.signals)

# Check we can read it into MNE
py = mne_read(edf)
@test length(py.annotations) == 5
ann = py.annotations[1]
@test pyconvert(Float64, ann["onset"]) == 0.1344
@test pyconvert(Float64, ann["duration"]) == 0.256
@test pyconvert(String, ann["description"]) == "type A"

# test that EDF.write(::IO, ::EDF.File) errors if file is
# discontiguous w/o an AnnotationsSignal present
bad_file = EDF.File(IOBuffer(),
Expand Down Expand Up @@ -253,6 +274,15 @@ const DATADIR = joinpath(@__DIR__, "data")
edf = EDF.File(io)
@test sprint(show, edf) == "EDF.File with 140 16-bit-encoded signals"
end

@testset "Exports readable by MNE" begin
edf = EDF.read(joinpath(DATADIR, "test_float_extrema.edf"))
@test edf.signals[1].header.digital_minimum ≈ -32767.0f0
edf = @set edf.signals[1].header.digital_minimum = -32767 * 2
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand what the purpose of this is. If it's necessary for testing a particular behavior, can you add a comment? I think it's the only use of Accessors here so if it's not actually necessary then dropping it would reduce the number of test dependencies.

Copy link
Member Author

Choose a reason for hiding this comment

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

this PR was meant to complement #72 which uses Accessors more extensively in the tests

however I no longer remember what the point of this line is anymore :/


py = mne_read(edf)
@test isempty(py.annotations)
end
end

@testset "BDF+ Files" begin
Expand Down
Loading