From ce85f5e423a83149e323bdc18c9b89d7c5fc8a3c Mon Sep 17 00:00:00 2001 From: Samuele Carcagno Date: Sat, 6 May 2017 19:16:40 +0100 Subject: [PATCH 1/6] some julia-0.6 compatibility changes --- src/BDF.jl | 139 ++++++++++++++++++------------------ test/test_channel_select.jl | 5 +- 2 files changed, 73 insertions(+), 71 deletions(-) diff --git a/src/BDF.jl b/src/BDF.jl index 6f1c632..e0ce4cc 100755 --- a/src/BDF.jl +++ b/src/BDF.jl @@ -1,7 +1,6 @@ module BDF using Compat, DocStringExtensions -VERSION < v"0.4-" && using Docile export readBDF, readBDFHeader, writeBDF, splitBDFAtTime, splitBDFAtTrigger, decodeStatusChannel @@ -42,7 +41,7 @@ dats, evtTab, trigChan, sysChan = readBDF("res1.bdf", transposeData=true) #retur function readBDF(fName::AbstractString; from::Real=0, to::Real=-1, channels::AbstractVector=[-1], transposeData::Bool=false) channels = unique(channels) - if isa(channels, AbstractVector{Compat.ASCIIString}) + if isa(channels, AbstractVector{String}) bdfHeader = readBDFHeader(fName) channels = [findfirst(channels, c) for c in bdfHeader["chanLabels"]] channels = channels[channels .!= 0] @@ -69,18 +68,18 @@ function readBDF(fid::IO; from::Real=0, to::Real=-1, channels::AbstractVector{In nDataRecords = parse(Int, ascii(String(read(fid, UInt8, 8)))) recordDuration = float(ascii(String(read(fid, UInt8, 8)))) nChannels = parse(Int, ascii(String(read(fid, UInt8, 4)))) - chanLabels = Array(Compat.ASCIIString, nChannels) - transducer = Array(Compat.ASCIIString, nChannels) - physDim = Array(Compat.ASCIIString, nChannels) - physMin = Array(Int32, nChannels) - physMax = Array(Int32, nChannels) - digMin = Array(Int32, nChannels) - digMax = Array(Int32, nChannels) - prefilt = Array(Compat.ASCIIString, nChannels) - nSampRec = Array(Int, nChannels) - reserved = Array(Compat.ASCIIString, nChannels) - scaleFactor = Array(Float32, nChannels) - sampRate = Array(Int, nChannels) + chanLabels = Array{String}(nChannels) + transducer = Array{String}(nChannels) + physDim = Array{String}(nChannels) + physMin = Array{Int32}(nChannels) + physMax = Array{Int32}(nChannels) + digMin = Array{Int32}(nChannels) + digMax = Array{Int32}(nChannels) + prefilt = Array{String}(nChannels) + nSampRec = Array{Int}(nChannels) + reserved = Array{String}(nChannels) + scaleFactor = Array{Float32}(nChannels) + sampRate = Array{Int}(nChannels) duration = recordDuration*nDataRecords @@ -144,12 +143,12 @@ function readBDF(fid::IO; from::Real=0, to::Real=-1, channels::AbstractVector{In end recordsToRead = to - from if transposeData - data = Array(Int32, ((recordsToRead*nSampRec[1]), (nKeepChannels))) + data = Array{Int32}((recordsToRead*nSampRec[1]), (nKeepChannels)) else - data = Array(Int32, ((nKeepChannels), (recordsToRead*nSampRec[1]))) + data = Array{Int32}((nKeepChannels), (recordsToRead*nSampRec[1])) end - trigChan = Array(Int16, recordsToRead*nSampRec[1]) - sysCodeChan = Array(Int16, recordsToRead*nSampRec[1]) + trigChan = Array{Int16}(recordsToRead*nSampRec[1]) + sysCodeChan = Array{Int16}(recordsToRead*nSampRec[1]) startPos = 3*from*nChannels*nSampRec[1] skip(fid, startPos) @@ -222,7 +221,7 @@ function readBDF(fid::IO; from::Real=0, to::Real=-1, channels::AbstractVector{In trigDurs = (stopPoints - startPoints)/sampRate[1] evt = trigChan[startPoints] - evtTab = @compat Dict{Compat.ASCIIString,Any}("code" => evt, + evtTab = Dict{String,Any}("code" => evt, "idx" => startPoints, "dur" => trigDurs ) @@ -298,18 +297,18 @@ function readBDFHeader(fid::IO; fName::AbstractString="") nDataRecords = parse(Int, ascii(String(read(fid, UInt8, 8)))) recordDuration = float(ascii(String(read(fid, UInt8, 8)))) nChannels = parse(Int, ascii(String(read(fid, UInt8, 4)))) - chanLabels = Array(Compat.ASCIIString, nChannels) - transducer = Array(Compat.ASCIIString, nChannels) - physDim = Array(Compat.ASCIIString, nChannels) - physMin = Array(Int32, nChannels) - physMax = Array(Int32, nChannels) - digMin = Array(Int32, nChannels) - digMax = Array(Int32, nChannels) - prefilt = Array(Compat.ASCIIString, nChannels) - nSampRec = Array(Int, nChannels) - reserved = Array(Compat.ASCIIString, nChannels) - scaleFactor = Array(Float32, nChannels) - sampRate = Array(Int, nChannels) + chanLabels = Array{String}(nChannels) + transducer = Array{String}(nChannels) + physDim = Array{String}(nChannels) + physMin = Array{Int32}(nChannels) + physMax = Array{Int32}(nChannels) + digMin = Array{Int32}(nChannels) + digMax = Array{Int32}(nChannels) + prefilt = Array{String}(nChannels) + nSampRec = Array{Int}(nChannels) + reserved = Array{String}(nChannels) + scaleFactor = Array{Float32}(nChannels) + sampRate = Array{Int}(nChannels) duration = recordDuration*nDataRecords @@ -360,32 +359,32 @@ function readBDFHeader(fid::IO; fName::AbstractString="") close(fid) - d = @compat Dict{Compat.ASCIIString,Any}("fileName" => fName, - "idCodeNonASCII" => idCodeNonASCII, - "idCode" => idCode, - "subjID" => subjID, - "recID" => recID, - "startDate" => startDate, - "startTime" => startTime, - "nBytes" => nBytes, - "versionDataFormat" => versionDataFormat, - "nDataRecords" => nDataRecords, - "recordDuration" => recordDuration, - "nChannels" => nChannels, - "chanLabels" => chanLabels, - "transducer" => transducer, - "physDim"=> physDim, - "physMin" => physMin, - "physMax" => physMax, - "digMin" => digMin, - "digMax" => digMax, - "prefilt" => prefilt, - "nSampRec" => nSampRec, - "reserved" => reserved, - "scaleFactor" => scaleFactor, - "sampRate" => sampRate, - "duration" => duration, - ) + d = Dict{String,Any}("fileName" => fName, + "idCodeNonASCII" => idCodeNonASCII, + "idCode" => idCode, + "subjID" => subjID, + "recID" => recID, + "startDate" => startDate, + "startTime" => startTime, + "nBytes" => nBytes, + "versionDataFormat" => versionDataFormat, + "nDataRecords" => nDataRecords, + "recordDuration" => recordDuration, + "nChannels" => nChannels, + "chanLabels" => chanLabels, + "transducer" => transducer, + "physDim"=> physDim, + "physMin" => physMin, + "physMax" => physMax, + "digMin" => digMin, + "digMax" => digMax, + "prefilt" => prefilt, + "nSampRec" => nSampRec, + "reserved" => reserved, + "scaleFactor" => scaleFactor, + "sampRate" => sampRate, + "duration" => duration, + ) return(d) end @@ -437,8 +436,8 @@ writeBDF("bdfRec.bdf", dats, trigs, statChan, sampRate, startDate="23.06.14", startTime="10.18.19") ``` """ -function writeBDF{P<:Real, Q<:Real, R<:Real, S<:Compat.ASCIIString, T<:Compat.ASCIIString, U<:Compat.ASCIIString, V<:Real, W<:Real, Z<:Compat.ASCIIString}(fName::AbstractString, data::AbstractMatrix{P}, trigChan::AbstractVector{Q}, statusChan::AbstractVector{R}, sampRate::Integer; subjID::Compat.ASCIIString="", - recID::Compat.ASCIIString="", startDate::Compat.ASCIIString=Libc.strftime("%d.%m.%y", time()), startTime::Compat.ASCIIString=Libc.strftime("%H.%M.%S", time()), versionDataFormat::Compat.ASCIIString="24BIT", +function writeBDF{P<:Real, Q<:Real, R<:Real, S<:String, T<:String, U<:String, V<:Real, W<:Real, Z<:String}(fName::AbstractString, data::AbstractMatrix{P}, trigChan::AbstractVector{Q}, statusChan::AbstractVector{R}, sampRate::Integer; subjID::String="", + recID::String="", startDate::String=Libc.strftime("%d.%m.%y", time()), startTime::String=Libc.strftime("%H.%M.%S", time()), versionDataFormat::String="24BIT", chanLabels::AbstractVector{S}=["" for i=1:size(data)[1]], transducer::AbstractVector{T}=["" for i=1:size(data)[1]], physDim::AbstractVector{U}=["" for i=1:size(data)[1]], @@ -754,9 +753,9 @@ function writeBDF{P<:Real, Q<:Real, R<:Real, S<:Compat.ASCIIString, T<:Compat.AS dats[i,:] = dats[i,:] /scaleFactor[i] end - dats = round(Int32, dats) #need to pad dats - trigs = round(Int16, trigs) - statChan = round(Int16, statChan) + dats = round.(Int32, dats) #need to pad dats + trigs = round.(Int16, trigs) + statChan = round.(Int16, statChan) for n=1:nDataRecords for c=1:nChannels if c < nChannels @@ -810,7 +809,7 @@ function splitBDFAtTrigger(fName::AbstractString, trigger::Integer; from::Real=0 stopPoints = [sepPoints; size(data)[2]] startDateTime = DateTime(string(origHeader["startDate"], ".", origHeader["startTime"]), "dd.mm.yy.HH.MM.SS") - timeSeconds = [0; round(Int, sepPoints.*sampRate)] + timeSeconds = [0; round.(Int, sepPoints.*sampRate)] for i=1:nChunks thisFname = joinpath(dirname(fName), basename(fName)[1:end-4] * "_" * string(i) * basename(fName)[end-3:end]) @@ -859,7 +858,7 @@ function splitBDFAtTime{T<:Real}(fName::AbstractString, timeSeconds::Union{T, Ab data, evtTab, trigChan, sysCodeChan = readBDF(fName, from=from, to=to) origHeader = readBDFHeader(fName) sampRate = origHeader["sampRate"][1] #assuming sampling rate is the same for all channels - sepPoints = round(Int, sampRate.*timeSeconds) + sepPoints = round.(Int, sampRate.*timeSeconds) for i=1:length(sepPoints) if sepPoints[i] > size(data)[2] error("Split point exceeds data points") @@ -927,11 +926,11 @@ end function decodeStatusChannel(statusChannel::AbstractVector{Int16}) n = length(statusChannel) - newEpoch = Array(Bool, n) - speedMode = Array(Int8, n) - CMSInRange = Array(Bool, n) - batteryLow = Array(Bool, n) - isMK2 = Array(Bool, n) + newEpoch = Array{Bool}(n) + speedMode = Array{Int8}(n) + CMSInRange = Array{Bool}(n) + batteryLow = Array{Bool}(n) + isMK2 = Array{Bool}(n) for i=1:n x = bin(statusChannel[i]) newEpoch[i] = parse(Bool, x[8]) @@ -941,7 +940,7 @@ function decodeStatusChannel(statusChannel::AbstractVector{Int16}) isMK2[i] = parse(Bool, x[1]) end - decodedStatusChannel = @compat Dict{Compat.ASCIIString,Any}("newEpoch" => newEpoch, + decodedStatusChannel = Dict{String,Any}("newEpoch" => newEpoch, "speedMode" => speedMode, "CMSInRange" => CMSInRange, "batteryLow" => batteryLow, diff --git a/test/test_channel_select.jl b/test/test_channel_select.jl index 3e8beb3..3d45277 100644 --- a/test/test_channel_select.jl +++ b/test/test_channel_select.jl @@ -11,7 +11,8 @@ for ci in ([1, 2, 3], [1, 2, 3, 4, 5, 6], 1:14, [1, 3, 9, 11, 15], [5, 2, 7]) @test size(dats2, 2) == size(dats, 2) @test size(dats2, 1) == length(ci) - @test_approx_eq(dats[ci, :], dats2) + #@test_approx_eq(dats[ci, :], dats2) + @test isequal(dats[ci, :], dats2) @test statusChan2 == statusChan end @@ -24,5 +25,7 @@ for (ci, el) in zip((["A1", "A2"], ["A1", "A3"], ["A3", "A1", "A11", "A16"]), ([ @test size(dats2, 1) == length(ci) @test_approx_eq(dats[el, :], dats2) + #@test dats[el, :] ≈ dats2 + #@test isequal(dats[el, :], dats2) @test statusChan2 == statusChan end From 1229bba1746c186cd1a1f9d27a07a178ca7350ea Mon Sep 17 00:00:00 2001 From: Samuele Carcagno Date: Fri, 12 May 2017 12:13:33 +0100 Subject: [PATCH 2/6] improve readability of test_channel_select --- test/test_channel_select.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/test_channel_select.jl b/test/test_channel_select.jl index 3d45277..c8d37ef 100644 --- a/test/test_channel_select.jl +++ b/test/test_channel_select.jl @@ -17,15 +17,15 @@ for ci in ([1, 2, 3], [1, 2, 3, 4, 5, 6], 1:14, [1, 3, 9, 11, 15], [5, 2, 7]) end -for (ci, el) in zip((["A1", "A2"], ["A1", "A3"], ["A3", "A1", "A11", "A16"]), ([1, 2], [1, 3], [3, 1, 11, 16])) +for (chanLabs, chanNum) in zip((["A1", "A2"], ["A1", "A3"], ["A3", "A1", "A11", "A16"]), ([1, 2], [1, 3], [3, 1, 11, 16])) - dats2, evtTab2, trigs2, statusChan2 = readBDF(origFilePath, channels = ci) + dats2, evtTab2, trigs2, statusChan2 = readBDF(origFilePath, channels = chanLabs) @test size(dats2, 2) == size(dats, 2) - @test size(dats2, 1) == length(ci) + @test size(dats2, 1) == length(chanLabs) - @test_approx_eq(dats[el, :], dats2) + #@test_approx_eq(dats[el, :], dats2) #@test dats[el, :] ≈ dats2 - #@test isequal(dats[el, :], dats2) + @test isequal(dats[chanNum, :], dats2) @test statusChan2 == statusChan end From 25bd036b923f35bc5d00ebae9b4b02a8d19553c9 Mon Sep 17 00:00:00 2001 From: Samuele Carcagno Date: Fri, 12 May 2017 15:45:54 +0100 Subject: [PATCH 3/6] Fix Iss. #19 in compat0.6 branch --- src/BDF.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BDF.jl b/src/BDF.jl index e0ce4cc..3361ae0 100755 --- a/src/BDF.jl +++ b/src/BDF.jl @@ -43,7 +43,7 @@ function readBDF(fName::AbstractString; from::Real=0, to::Real=-1, channels::Abs channels = unique(channels) if isa(channels, AbstractVector{String}) bdfHeader = readBDFHeader(fName) - channels = [findfirst(channels, c) for c in bdfHeader["chanLabels"]] + channels = [findfirst(bdfHeader["chanLabels"], c) for c in channels] channels = channels[channels .!= 0] end From 677cac3a991e713174c3db097ced51b1b4fc31bc Mon Sep 17 00:00:00 2001 From: Samuele Carcagno Date: Fri, 12 May 2017 15:49:05 +0100 Subject: [PATCH 4/6] update julia version in .travis.yml for compat0.6 branch --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 71e4c21..4cd5fb4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,8 @@ os: - linux - osx julia: - - 0.4 + - 0.5 + - 0.6 - nightly notifications: email: false From 4661811570cddaa781695e960984979df48b08d1 Mon Sep 17 00:00:00 2001 From: Samuele Carcagno Date: Fri, 12 May 2017 16:01:09 +0100 Subject: [PATCH 5/6] update require --- REQUIRE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/REQUIRE b/REQUIRE index 024c1ab..fe63833 100755 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,4 @@ Compat 0.7.18 DocStringExtensions HDF5 -julia 0.5- \ No newline at end of file +julia 0.6- \ No newline at end of file From 9db0b335f1d951671c85f4292608126458d5a30d Mon Sep 17 00:00:00 2001 From: Samuele Carcagno Date: Tue, 20 Jun 2017 20:17:06 +0100 Subject: [PATCH 6/6] remove 0.6 pre-release support --- REQUIRE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/REQUIRE b/REQUIRE index fe63833..02da480 100755 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,4 @@ Compat 0.7.18 DocStringExtensions HDF5 -julia 0.6- \ No newline at end of file +julia 0.6 \ No newline at end of file