# separate header from rest of file header = data.pop(0) header = header.replace('\n', '').replace('\r', '').replace('"', '').split(SEP) # process file contents for i in range(len(data)): data[i] = data[i].replace('\n', '').replace('\r', '').replace('"', '').split(SEP) # GAZE DATA print("loading gaze data") edfdata = read_eyetribe(fp, EDFSTART, stop=EDFSTOP, missing=INVALCODE, debug=False) print("plotting gaze data") # dataframe of results out = csv.writer(open(os.path.join(DATADIR, '%s.aoi.analisis.txt' % ppname), "a"), delimiter=';', quoting=csv.QUOTE_ALL) out.writerow([ "Sujeto", "Imagen", "Area", "Ensayo", "FF_AOI", "DF_AOI", "LF_AOI", "FE_AOI0", "DE_AOI0", "LE_AOI0", "Dwell_AOI" ])
import sys sys.path.append("../PyGazeAnalyser") from pygazeanalyser import eyetribereader, gazeplotter import os IMGDIR = os.path.join('/home/akos/Documents/tcsai-saliency/mod_imgs') IMGNAMES = os.listdir(IMGDIR) outdir = os.path.join('/home/akos/Documents/tcsai-saliency/gazeviz') RESOLUTION = (1024, 768) DATAFILE = 'testdata/subject-5-1.tsv' # ,stop="stop_trial" gazedata = eyetribereader.read_eyetribe( DATAFILE, "start_trial", stop_time=2995, # first 3 seconds missing=0.0) imgs = open("imgorder.txt").read().split('\n') for i in range(len(gazedata)): if i < 4: pass # print gazedata[i]['events']['msg'] # imgname = gazedata[i]['events']['msg'][69][1].split()[-1] # imgname = imgname.split('.')[0] + '.jpg' else: print i + 4 print gazedata[i]['events']['msg'] # imgname = gazedata[i]['events']['msg'][71][1].split()[-1] imgname = imgs[i + 4] imgname = imgname.split('.')[0] + '.jpg' imgfile = os.path.join(IMGDIR, imgname)
DIR = os.path.dirname(os.path.abspath(__file__)) LOGFILE = os.path.join(DIR, 'example_data.txt.tsv') IMGDIR = os.path.join(DIR, 'imgs') IMGNAMES = os.listdir(IMGDIR) # # # # # # ANALYSIS # create a new output directory outdir = os.path.join(DIR, 'output') if not os.path.isdir(outdir): os.mkdir(outdir) # read the data file gazedata = eyetribereader.read_eyetribe(LOGFILE, "image_on", stop="image_off", missing=0.0) # loop through all trials for trialnr in range(len(gazedata)): # find the image file name for msg in gazedata[trialnr]['events']['msg']: if '.jpg' in msg[1]: imgname = os.path.splitext(msg[1])[0] imgfile = os.path.join(IMGDIR, msg[1]) # get the fixations fixations = gazedata[trialnr]['events']['Efix'] print "outdir:", outdir # plot the samples gazeplotter.draw_raw(gazedata[trialnr]['x'],
#if not os.path.isfile(fp): ## if not, check if the EDF exists #edfp = os.path.join(DATADIR, '%s.edf' % ppname) #if os.path.isfile(edfp): ## if it does, convert if usinf edf2asc.exe #os.system("edf2asc %s" % edfp) ## load ASCII #fp = os.path.join(DATADIR, '%s.asc' % ppname) ## if it does not exist, raise an exception #else: #raise Exception("No eye data file (neither ASC, nor EDF) file found for participant '%s' (tried paths:\nASC: %s\nEDF: %s" % (ppname, fp, edfp)) # read the file # edfdata[trialnr]['time'] = list of timestamps in trialnr # edfdata[trialnr]['size'] = list of pupil size samples in trialnr edfdata = read_eyetribe(fp, EDFSTART, EDFSTOP, missing=0.0) # NEW OUTPUT DIRECTORIES # create a new output directory for the current participant pplotdir = os.path.join(PLOTDIR, ppname) # check if the directory already exists if not os.path.isdir(pplotdir): # create it if it doesn't yet exist os.mkdir(pplotdir) # # # # # # PLOTS print("plotting gaze data")