Skip to content

Commit 2f43df8

Browse files
authoredMar 25, 2019
Merge pull request #10 from grero/recordings
Recordings
2 parents 68b9bc8 + c0ee1c1 commit 2f43df8

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed
 

‎Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Eyelink"
22
uuid = "83654edc-39a9-11e9-3850-750e501afe4a"
33
authors = ["roger <roger.herikstad@gmail.com>"]
4-
version = "0.5.3"
4+
version = "0.6.0"
55

66
[deps]
77
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"

‎README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
[![Build Status](https://travis-ci.org/grero/Eyelink.jl.svg?branch=master)](https://travis-ci.org/grero/Eyelink.jl)
44
[![Coverage Status](https://coveralls.io/repos/github/grero/Eyelink.jl/badge.svg?branch=master)](https://coveralls.io/github/grero/Eyelink.jl?branch=master)
55
## Introduction
6-
Open up an edf file, loading both events and continuos data:
6+
Open up an EDF file, loading both events and continuos data:
77

88
```julia
99
eyelinkdata = Eyelink.load("w7_10_2.edf")
1010
```
11+
12+
Since an EDF file contains a lot of data, and one might not be interested in all that data for every analysis, there are convenience functions for getting certain types of data. For instance, to get just the calibrated gaze positions, one can do the following
13+
14+
```julia
15+
gazex, gazey, gtime = Eyelink.getgazepos("w7_10_2.edf")
16+
```

‎src/Eyelink.jl

+11-7
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function edfload(edffile::EDFFile)
5959
nevents = get_element_count(f)
6060
samples = Array{FSAMPLE}(undef, nevents)
6161
events = Array{Event}(undef, nevents)
62+
recording_info = Recording[]
6263
event_count = 0
6364
sample_count = 0
6465
total_count = 0
@@ -70,8 +71,9 @@ function edfload(edffile::EDFFile)
7071
sample_count += 1
7172
samples[sample_count] = _sample
7273

73-
elseif nextevent == :recording_info
74-
#nothing
74+
elseif nextevent == :recordinginfo
75+
_recinfo = edfdata(f)
76+
push!(recording_info, _recinfo)
7577
elseif nextevent == :no_pending_items
7678
#ntohing
7779
else #event
@@ -86,7 +88,7 @@ function edfload(edffile::EDFFile)
8688
total_count += 1
8789
update!(p, total_count)
8890
end
89-
Dict([("events", events[1:event_count]), ("samples", samples[1:sample_count])])
91+
Dict([("events", events[1:event_count]), ("samples", samples[1:sample_count]), ("recording_info", recording_info)])
9092
end
9193

9294
function get_element_count(edffile::EDFFile)
@@ -107,7 +109,7 @@ function load(f::String;check=1, load_events=true,load_samples=true,do_save=true
107109
ss = load(File(format"HDF5", samplefile))
108110
edffile = edfopen(f, check, true, false)
109111
data = edfload(edffile)
110-
eyedata = EyelinkData(data["events"],ss)
112+
eyedata = EyelinkData(data["recording_info"], data["events"],ss)
111113
else
112114
edffile = edfopen(f, check, load_events, load_samples)
113115
data = edfload(edffile)
@@ -119,7 +121,7 @@ function load(f::String;check=1, load_events=true,load_samples=true,do_save=true
119121
else
120122
ss = Samples(0)
121123
end
122-
eyedata = EyelinkData(data["events"], ss)
124+
eyedata = EyelinkData(data["recording_info"], data["events"], ss)
123125
end
124126
eyedata
125127
end
@@ -158,8 +160,10 @@ function edfdata(f::EDFFile)
158160
if f.nextevent == :sample_type
159161
#TODO: Implement this
160162
_sample = unsafe_load(convert(Ptr{FSAMPLE}, _data), 1)
161-
return _sample
162-
elseif f.nextevent == :recording_info
163+
return _sample
164+
elseif f.nextevent == :recordinginfo
165+
_recinfo = unsafe_load(convert(Ptr{Recording}, _data),1)
166+
return _recinfo
163167
elseif f.nextevent == :no_pending_items
164168
else
165169
#even type

‎src/types.jl

+27
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ datatypes = Dict{Int16, Symbol}(0 => :nopending,
1616
16 => :endsamples,
1717
17 => :startevent,
1818
18 => :endevent,
19+
30 => :recordinginfo,
1920
200 => :sample_type)
2021

2122

@@ -31,6 +32,29 @@ function EDFFile(fname::String, ptr::Ptr)
3132
EDFFile(fname,ptr,0,0,:unknown)
3233
end
3334

35+
struct Recording
36+
time::UInt32
37+
sample_rate::Float32
38+
eflags::UInt16
39+
sflags::UInt16
40+
state::UInt8
41+
record_type::UInt8
42+
pupil_type::UInt8
43+
recording_mode::UInt8
44+
filter_type::UInt8
45+
pos_type::UInt8
46+
eye::UInt8
47+
end
48+
49+
function Recording()
50+
args = []
51+
for f in fieldnames(Recording)
52+
tt = fieldtype(Recording,f)
53+
push!(args, zero(tt))
54+
end
55+
Recording(args...)
56+
end
57+
3458
struct EyeEvent
3559
time::Int64
3660
x::Float32
@@ -415,9 +439,12 @@ function convert(::Type{Array{T,1}}, M::Dict) where T<:AbstractSaccade
415439
end
416440

417441
struct EyelinkData
442+
recording_info::Vector{Recording}
418443
events::Array{Event,1}
419444
samples::Samples
420445
end
421446

447+
Eyelinkdata(events::Vector{Event}, samples::Samples) = EyelinkData([Reording()], events, samples)
448+
422449
get_gaze(eyelinkdata::EyelinkData) = (eyelinkdata.samples.gx, eyelinkdata.samples.gy)
423450
get_pupil(eyelinkdata::EyelinkData) = eyelinkdata.samples.pa

‎test/runtests.jl

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ end
1414
@testset "Load file" begin
1515
download("http://cortex.nus.edu.sg/testdata/w7_10_2.edf", "w7_10_2.edf")
1616
eyelinkdata = Eyelink.load("w7_10_2.edf")
17+
@test eyelinkdata.recording_info[1].time == 0x001c0657
18+
@test eyelinkdata.recording_info[1].state == 0x01
19+
@test eyelinkdata.recording_info[2].time == 0x001c07f9
20+
@test eyelinkdata.recording_info[2].state == 0x00
1721
mm = eyelinkdata.events[1].message
1822
@test mm == "DISPLAY_COORDS 0 0 1920 1200"
1923
start_fix_events = filter(ee->ee.eventtype==:endfix,eyelinkdata.events)

0 commit comments

Comments
 (0)
Please sign in to comment.