June 23, 2017

Outline for the Week

  • Day 1: Data files
    • Experiment Builder Script Setup
    • EDF files
    • Other EB files
  • Day 2: Data viewer
    • Visualizing data; QC
    • Interest areas
    • Creating reports
  • Day 3: ET data in R
    • Reading EDF ASCII files
    • Creating Reports
    • Interest areas
    • Visualizing data (ggplot)

Outline for Today

  • Reading EDF ASCII files
  • Creating Reports
  • Interest areas
  • Visualizing data (ggplot)

Reading EDF ASCII files

EDF2ASC

Command line utility for converting EDF files to ASC files.

  • There is a GUI version of the tool.
  • There is a Mac OS version called EDFconverter.

Eyelink Data files

EDF2ASC

EB Screenshot

EDF2ASC

EB Screenshot

FDBeye package

edf2asc()

library(FDBeye)

Need to Tell FDBeye where to find the edf2asc utility.

edf2asc()

options(FDBeye_edf2asc_exec = "C:/Program Files (x86)/SR Research/EyeLink/EDF_Access_API/Example/edf2asc64.exe")
getOption("FDBeye_edf2asc_exec")
## [1] "C:/Program Files (x86)/SR Research/EyeLink/EDF_Access_API/Example/edf2asc64.exe"
## Set some options.  Here '-y' forces overwrite of existing
## ASC files.
options(FDBeye_edf2asc_opts = "-y")

edf2asc()

Get a list of EDF files and process them with edf2asc.

edffiles <- list.files(".", pattern = "edf$", recursive = TRUE)
edffiles
## [1] "data/RAN/1950180/1950180.edf"
ascfiles <- edf2asc(edffiles)
ascfiles
## [1] "data/RAN/1950180/1950180.asc"

Returns a list of the ASC files that are created.

readELascii()

eldat <- readELascii(ascfiles[1])
##        X1    X2    X3    X4    X5    X6    X7    X8
## 1 4318226 613.4 493.9 803.0 640.1 493.4 656.0 .....
## [1] "Sbinoc && !(Svel||Sres)"
##        X1    X2    X3    X4 X5 X6  X7    X8
## 1 4341642 -63.3 720.5 276.0  .  . 0.0 ...C.
## [1] "Sbinoc && !(Svel||Sres)"
##        X1    X2    X3    X4    X5    X6    X7    X8
## 1 4364730 626.6 527.3 789.0 658.2 525.4 613.0 .....
## [1] "Sbinoc && !(Svel||Sres)"
##        X1    X2    X3    X4    X5    X6    X7    X8
## 1 4382990 616.1 536.3 892.0 641.8 528.6 683.0 .....
## [1] "Sbinoc && !(Svel||Sres)"
##        X1    X2    X3    X4    X5    X6    X7    X8
## 1 4402394 612.1 520.8 861.0 649.3 502.7 664.0 .....
## [1] "Sbinoc && !(Svel||Sres)"
##        X1    X2    X3    X4    X5    X6    X7    X8
## 1 4427690 557.0 445.8 864.0 587.1 433.5 703.0 .....
## [1] "Sbinoc && !(Svel||Sres)"

readELascii()

names(eldat)
## [1] "session" "trials"
names(eldat$session)
## [1] "subj"     "script"   "sessdate" "srcfile"
names(eldat$trials)
## [1] "0" "1" "2" "3" "4" "5"
names(eldat$trials$"0")
## [1] "fix"      "sacc"     "blink"    "trialvar" "samp"     "msg"

Fixation Report

fixdat <- fixReport(eldat)
names(fixdat)
##  [1] "subject"                 "trialn"                 
##  [3] "time0"                   "event"                  
##  [5] "eye"                     "stime"                  
##  [7] "etime"                   "dur"                    
##  [9] "xpos"                    "ypos"                   
## [11] "pupil"                   "currentEyeTrackerTime"  
## [13] "currentDisplayPCTime"    "AudioRecordingStartTime"
## [15] "AlignVoiceTriggerTime"   "trial"                  
## [17] "p1"                      "p2"                     
## [19] "p3"                      "p4"                     
## [21] "p5"                      "p6"                     
## [23] "p7"                      "p8"                     
## [25] "p9"                      "p10"                    
## [27] "p11"                     "p12"                    
## [29] "p13"                     "p14"                    
## [31] "p15"                     "p16"                    
## [33] "p17"                     "p18"                    
## [35] "p19"                     "p20"                    
## [37] "p21"                     "p22"                    
## [39] "p23"                     "p24"                    
## [41] "p25"                     "p26"                    
## [43] "p27"                     "p28"                    
## [45] "p29"                     "p30"                    
## [47] "p31"                     "p32"                    
## [49] "p33"                     "p34"                    
## [51] "p35"                     "p36"                    
## [53] "cell_width"              "cell_height"

Fixation Report: Clean It Up

fixdat <- fixdat %>% select(c(subject, trialn, time0, event, 
    eye, stime, etime, dur, xpos, ypos, pupil, trial))

str(fixdat)
## 'data.frame':    679 obs. of  12 variables:
##  $ subject: chr  "1950180" "1950180" "1950180" "1950180" ...
##  $ trialn : Factor w/ 6 levels "0","1","2","3",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ time0  : int  4318226 4318226 4318226 4318226 4318226 4318226 4318226 4318226 4318226 4318226 ...
##  $ event  : chr  "FIX" "FIX" "FIX" "FIX" ...
##  $ eye    : Factor w/ 2 levels "L","R": 1 2 1 2 1 1 2 1 2 1 ...
##  $ stime  : num  4318242 4318242 4318510 4318470 4318642 ...
##  $ etime  : num  4318414 4318414 4318614 4318802 4318806 ...
##  $ dur    : num  176 176 108 336 168 192 188 124 112 264 ...
##  $ xpos   : num  613 638 131 229 185 ...
##  $ ypos   : num  521 515 418 300 307 ...
##  $ pupil  : num  824 669 937 727 901 904 717 862 674 923 ...
##  $ trial  : chr  "letters1" "letters1" "letters1" "letters1" ...

Look at your Data

Individual Trial: FDBeye::fixPlot()

Under Repair.

Now for some generic ggplot.

Individual Trial

letters2 <- filter(fixdat, trial == "letters2")
p1 <- ggplot(aes(x = xpos, y = ypos, size = dur, color = eye), 
    data = letters2) + geom_point()

Individual Trial

p2 <- p1 + geom_point(alpha = 1/2) + scale_x_continuous(limits = c(0, 
    1279)) + scale_y_reverse(limits = c(1023, 0)) + coord_fixed() + 
    guides(size = FALSE, color = FALSE)

Individual Trial: read region file

regions <- read_tsv("data/RAN/Interest Area and Canvas Overlay Setup in DV/letters1-big.ias", 
    col_names = c("type", "regnum", "left", "top", "right", "bottom", 
        "reglabel"))

Region files, in the form of Data Viewer ias files, are just tab-separated variable files, without headers.

Individual Trial: add regions to plot

p3 <- p2 + geom_rect(aes(xmin = left, ymin = top, xmax = right, 
    ymax = bottom), fill = NA, color = "blue", data = regions, 
    inherit.aes = FALSE)

Individual Trial: zoom in

p4 <- p3 + ylim(875, 200) + xlim(175, 1100)

Individual Trial: closest line

regions <- regions %>% mutate(vcenter = (top+bottom)/2,
                              hcenter = (left+right)/2)
lines <- unique(regions$vcenter)
p5 <- p2  + ylim(875, 200) +
    xlim(175, 1100) +
    geom_hline(yintercept=lines, color="orange")

Individual Trial: closest line

Individual Trial: closest line

getNearestLine <- function(y, lines) {
    which.min(abs(y-lines))
}
line <- apply(matrix(letters2$ypos), 1, getNearestLine, lines)
line
##   [1] 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2
##  [36] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
##  [71] 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 2 2
## [106] 1 1 3 3
letters2 <- data.frame(letters2, line)

Color fixations according to nearest line (vcenter, line).

Individual Trial: closest line

p6 <- p5 + geom_point(aes(color=as.factor(line)))

Individual Trial: closest line

letters2r <- filter(letters2, eye=="R")

p10 <- ggplot(aes(x=xpos, y=ypos, size=dur), data=letters2r) +
    geom_point(aes(color=as.factor(line)), alpha=1/2) +
    scale_y_reverse(limits=c(875,200)) +
    scale_x_continuous(limits=c(175,1100)) +
    coord_fixed() +
    guides(size=FALSE, color=FALSE) +
    geom_hline(yintercept=lines, color="orange")

Putting everything together.

Individual Trial: closest line

Individual Trial: fix out of sequence

letters2r$line
##  [1] 2 2 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3
## [36] 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 2 1 3
tmp <- FDButils::series(letters2r$line, step = 0, minseries = 3)
ffix <- tmp[1, 2]
lfix <- sum(tmp[4, 2:3]) - 1

letters2r$line[ffix:lfix]
##  [1] 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3
## [36] 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
letters2r.trim <- letters2r[ffix:lfix, ]

Individual Trial: trimmed

Multiple Trials/Conditions

s180 <- filter(fixdat, eye=="R")

p11 <- ggplot(aes(x=xpos, y=ypos, size=dur), data=s180) +
    geom_point(aes(color=(stime-time0)), alpha=1/2) +
    scale_color_gradientn(colors=rainbow(4)) +
    scale_y_reverse(limits=c(875,200)) +
    scale_x_continuous(limits=c(175,1100)) +
    coord_fixed() +
    guides(size=FALSE) +
    geom_hline(yintercept=lines, color="orange") +
    facet_wrap(~trial, nrow=2, dir="v")

Also color fixations according to onset time (stime).

Multiple Trials

Color highlights relative durations of trials and helps show fixations out sequence.

Recap of Today

  • Reading EDF ASCII files
  • Creating Reports
  • Interest areas
  • Visualizing data (ggplot)

Outline for the Week

  • Day 1: Data files
    • Experiment Builder Script Setup
    • EDF files
    • Other EB files
  • Day 2: Data viewer
    • Visualizing data; QC
    • Interest areas
    • Creating reports
  • Day 3: ET data in R
    • Reading EDF ASCII files
    • Creating Reports
    • Interest areas
    • Visualizing data (ggplot)