Skip to content

Commit

Permalink
Adds new type for spike waveforms
Browse files Browse the repository at this point in the history
  • Loading branch information
grero committed Jun 15, 2017
1 parent 0dc27db commit 6c08ab9
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/SpikeSorter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ include("viterbi.jl")
include("readfiles.jl")
include("features.jl")
include("extraction.jl")
include("io.jl")
import GUICheck
if GUICheck.hasgui()
include("plot.jl")
Expand Down
32 changes: 32 additions & 0 deletions src/io.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Base.write

function Base.write(io::IO, waveforms::SpikeWaveforms)
#write a header
headersize = 64
nbytes = 0
npoints, nchannels, nspikes = size(waveforms.waveforms)
nbytes += write(io, npoints)
nbytes += write(io, nchannels)
nbytes += write(io, nspikes)
seek(io, headersize)

#write timestamps, followed by waveforms
nbytes += write(io, waveforms.timestamps)
nbytes += write(io, waveforms.waveforms)
nbytes
end

function Base.read(io::IO, ::Type{SpikeWaveforms})
#read the header
headersize = 64
npoints = read(io, Int64)
nchannels = read(io, Int64)
nspikes = read(io, Int64)
seek(io, headersize)

#read timestamps
timestamps = read(io, Float64, nspikes)
waveforms = read(io, Float64, (npoints, nchannels, nspikes))
SpikeWaveforms(waveforms, timestamps)
end

5 changes: 5 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import HDF5

type SpikeWaveforms
waveforms::Array{Float64,3}
timestamps::Array{Float64,1}
end

type TemplateFile
templates::Array{Float64,3}
cinv::Array{Float64,2}
Expand Down
9 changes: 9 additions & 0 deletions test/io.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
wf = SpikeSorter.SpikeWaveforms(randn(60,1,1024),cumsum(rand(1024)))
fname = tempname()

write(fname, wf)
wf2 = read(fname, SpikeSorter.SpikeWaveforms)

@test_approx_eq wf.timestamps wf2.timestamps
@test_approx_eq wf.waveforms wf2.waveforms

4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using Base.Test
using SpikeSorter

include("io.jl")

0 comments on commit 6c08ab9

Please sign in to comment.