Exemple #1
0
def process_images(imglist, eventfile, ppname, imgdir, plotdir):

  # check if the image directory exists
  if not os.path.isdir(imgdir):
    raise Exception("ERROR: no image directory found; path '%s' does not exist!" % imgdir)

  # check if output directorie exist; if not, create it
  if not os.path.isdir(plotdir):
    os.mkdir(plotdir)

  # EXPERIMENT SPECS
  DISPSIZE = (1920,1080) # (px,px)
  SCREENSIZE = (39.9,29.9) # (cm,cm)
  SCREENDIST = 61.0 # cm
  PXPERCM = numpy.mean([DISPSIZE[0]/SCREENSIZE[0],DISPSIZE[1]/SCREENSIZE[1]]) # px/cm

  # read the file
  smidata = read_smioutput(eventfile, None, ag_mode=SMIModes.LEFT_ONLY, stop=None, debug=False)

  nokey = 0
  processed = 0

  # loop through trials
  for trialnr in range(len(imglist)):
    # load image name, saccades, and fixations
    imgname = imglist[int(trialnr)]
    try:
      saccades = smidata[trialnr]['events']['Esac'] # [starttime, endtime, duration, startx, starty, endx, endy]
      fixations = smidata[trialnr]['events']['Efix'] # [starttime, endtime, duration, endx, endy]
    except KeyError:
      print "No eyetracking data for trial %s (image: %s)" % (trialnr + 1, imgname)
      nokey += 1
      continue
    except IndexError:
      print "No eyetracking data for trial %s (image: %s)" % (trialnr + 1, imgname)
      nokey += 1
      continue

    processed += 1
    
    # paths
    imagefile = os.path.join(imgdir, imgname)

    # rawplotfile = os.path.join(plotdir, "raw_data_%s_%d" % (ppname,trialnr))
    scatterfile = os.path.join(plotdir, "fixations_%s_%d" % (ppname,trialnr))
    scanpathfile =  os.path.join(plotdir, "scanpath_%s_%d" % (ppname,trialnr))
    heatmapfile = os.path.join(plotdir, "heatmap_%s_%d" % (ppname,trialnr))
    
    # raw data points
    # draw_raw(smidata[trialnr]['x'], smidata[trialnr]['y'], DISPSIZE, imagefile=imagefile, savefilename=rawplotfile)

    # fixations
    draw_fixations(fixations, DISPSIZE, imagefile=imagefile, durationsize=True, durationcolour=False, alpha=0.5, savefilename=scatterfile)
    
    # scanpath
    draw_scanpath(fixations, saccades, DISPSIZE, imagefile=imagefile, alpha=0.5, savefilename=scanpathfile)

    # heatmap   
    draw_heatmap(fixations, DISPSIZE, imagefile=imagefile, durationweight=True, alpha=0.75, savefilename=heatmapfile)
  print "%s images processed.  %s sections without eyetracker data." % (processed, nokey)
def generate_plots(IMGDIR, PLOTDIR, filename, fixations, saccades, data,
                   DISPSIZE, trialnr):

    # cognitive load
    if int(filename[4:5]) == 1:
        cognitive_load = "LOW"
    else:
        cognitive_load = "HIGH"

    #imgname = "screenshot.jpg"
    #imagefile = os.path.join(IMGDIR,imgname)

    # paths
    rawplotfile = os.path.join(
        PLOTDIR, "raw_data_%s_%s" % (filename[:3], cognitive_load))
    scatterfile = os.path.join(
        PLOTDIR, "fixations_%s_%s" % (filename[:3], cognitive_load))
    scanpathfile = os.path.join(
        PLOTDIR, "scanpath_%s_%s" % (filename[:3], cognitive_load))
    heatmapfile = os.path.join(
        PLOTDIR, "heatmap_%s_%s" % (filename[:3], cognitive_load))

    # raw data points
    draw_raw(data[trialnr]['x'],
             data[trialnr]['y'],
             DISPSIZE,
             imagefile=None,
             savefilename=rawplotfile)

    # fixations
    draw_fixations(fixations,
                   DISPSIZE,
                   imagefile=None,
                   durationsize=True,
                   durationcolour=False,
                   alpha=0.5,
                   savefilename=scatterfile)

    # scanpath
    draw_scanpath(fixations,
                  saccades,
                  DISPSIZE,
                  imagefile=None,
                  alpha=0.5,
                  savefilename=scanpathfile)

    # heatmap
    draw_heatmap(fixations,
                 DISPSIZE,
                 imagefile=None,
                 durationweight=True,
                 alpha=0.5,
                 savefilename=heatmapfile)
Exemple #3
0
 imgname, ext = os.path.splitext(os.path.basename(imgname))
 # empty lists
 fixations = []
 # loop through all participants
 for ppname in PPS:
     fixfile = open(
         os.path.join(IOUTDIR, ppname, trackertype,
                      "fixations_%s.dat" % imgname), 'r')
     fixations.extend(pickle.load(fixfile))
     fixfile.close()
 # plot fixations
 fig = gazeplotter.draw_fixations(
     fixations,
     DISPSIZE,
     imagefile=os.path.join(IMGDIR, "%s%s" % (imgname, ext)),
     durationsize=True,
     durationcolour=False,
     alpha=0.5,
     savefilename=os.path.join(
         OUTDIR, "fixations_%s_%s.png" % (trackertype, imgname)))
 pyplot.close(fig)
 # create heatplot
 fig = gazeplotter.draw_heatmap(
     fixations,
     DISPSIZE,
     imagefile=os.path.join(IMGDIR, "%s%s" % (imgname, ext)),
     durationweight=True,
     alpha=0.5,
     savefilename=os.path.join(
         OUTDIR, "heatmap_%s_%s.png" % (trackertype, imgname)))
 pyplot.close(fig)
Exemple #4
0
                                   "raw_data_%s_%d" % (ppname, trialnr))
        scatterfile = os.path.join(pplotdir,
                                   "fixations_%s_%d" % (ppname, trialnr))
        scanpathfile = os.path.join(pplotdir,
                                    "scanpath_%s_%d" % (ppname, trialnr))
        heatmapfile = os.path.join(pplotdir,
                                   "heatmap_%s_%d" % (ppname, trialnr))

        ##raw data points
        #draw_raw(edfdata[trialnr]['x'], edfdata[trialnr]['y'],edfdata[trialnr]['size'], DISPSIZE, imagefile=imagefile, savefilename=rawplotfile)

        #fixations
        draw_fixations(fixations,
                       DISPSIZE,
                       imagefile=imagefile,
                       durationsize=True,
                       durationcolour=True,
                       alpha=0.5,
                       savefilename=scatterfile)

        ##scanpath
        draw_scanpath(fixations,
                      saccades,
                      DISPSIZE,
                      imagefile=imagefile,
                      alpha=0.5,
                      savefilename=scanpathfile)

        # heatmap
        draw_heatmap(fixations,
                     DISPSIZE,
Exemple #5
0
			imagedata[i]['events']['Sfix'], imagedata[i]['events']['Efix'] = \
				fixation_detection(imagedata[i]['x'], imagedata[i]['y'], imagedata[i]['trackertime'], missing=0.0, maxdist=maxdist, mindur=FIXMINDUR)

		# PLOT DATA
		for i in range(len(imagedata)):
			# image name
			imgname = os.path.splitext(os.path.basename(IMAGES[i]))[0]
			# pickle fixation data
			fixfile = open(os.path.join(outputdir, "fixations_%s.dat" % imgname), 'w')
			pickle.dump(imagedata[i]['events']['Efix'], fixfile)
			fixfile.close()
			# plot raw data
			fig = gazeplotter.draw_raw(imagedata[i]['x'], imagedata[i]['y'], DISPSIZE, imagefile=IMAGES[i], savefilename=os.path.join(outputdir, "image_%s_raw.png" % imgname))
			pyplot.close(fig)
			# plot fixations
			fig = gazeplotter.draw_fixations(imagedata[i]['events']['Efix'], DISPSIZE, imagefile=IMAGES[i], durationsize=True, durationcolour=False, alpha=0.5, savefilename=os.path.join(outputdir, "image_%s_fixations.png" % imgname))
			pyplot.close(fig)
			# draw heatmap
			fig = gazeplotter.draw_heatmap(imagedata[i]['events']['Efix'], DISPSIZE, imagefile=IMAGES[i], durationweight=True, alpha=0.5, savefilename=os.path.join(outputdir, "image_%s_heatmap.png" % imgname))
			pyplot.close(fig)
		
			# ROI ANALYSIS
			if "01F_HA_O" in IMAGES[i]:
				# empty dicts
				Nfix = {}
				fixdur = {}
				dwelltime = {}
				# go through all ROI names
				for ROIname in ROILIST:
					# starting values
					Nfix[ROIname] = 0
if 'images' in OPTIONS:
    # loop through all trackers
    for trackertype in TRACKERS:
        # loop through all images
        for imgname in IMAGES:
            # get rid of image path and extension
            imgname, ext = os.path.splitext(os.path.basename(imgname))
                # empty lists
                fixations = []
                    # loop through all participants
                    for ppname in PPS:
                        fixfile = open(os.path.join(IOUTDIR, ppname, trackertype, "fixations_%s.dat" % imgname), 'r')
                            fixations.extend(pickle.load(fixfile))
                                fixfile.close()
                        # plot fixations
                        fig = gazeplotter.draw_fixations(fixations, DISPSIZE, imagefile=os.path.join(IMGDIR, "%s%s" % (imgname,ext)), durationsize=True, durationcolour=False, alpha=0.5, savefilename=os.path.join(OUTDIR, "fixations_%s_%s.png" % (trackertype,imgname)))
                        pyplot.close(fig)
                        # create heatplot
                        fig = gazeplotter.draw_heatmap(fixations, DISPSIZE, imagefile=os.path.join(IMGDIR, "%s%s" % (imgname,ext)), durationweight=True, alpha=0.5, savefilename=os.path.join(OUTDIR, "heatmap_%s_%s.png" % (trackertype,imgname)))
                    pyplot.close(fig)
        
            # PRECISION AND ACCURACY AVERAGES
            # empty dicts
            alldata = {}
                for ppname in PPS:
                    # read data file
                    datafile = open(os.path.join(IOUTDIR, ppname, trackertype, "ROI_analysis.txt"), 'r')
                        data = datafile.readlines()
                        datafile.close()
                        # parse data
                        for i in range(len(data)):
        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'],
                         gazedata[trialnr]['y'],
                         RESOLUTION,
                         imagefile=imgfile,
                         savefilename=os.path.join(outdir,
                                                   '%s_samples.png' % imgname))
    # plot the fixations
    gazeplotter.draw_fixations(fixations,
                               RESOLUTION,
                               imagefile=imgfile,
                               durationsize=True,
                               durationcolour=False,
                               alpha=0.5,
                               savefilename=os.path.join(
                                   outdir, '%s_fixations.png' % imgname))
    # plot a heatmap
    gazeplotter.draw_heatmap(fixations,
                             RESOLUTION,
                             imagefile=imgfile,
                             durationweight=True,
                             alpha=0.5,
                             savefilename=os.path.join(
                                 outdir, '%s_heatmap.png' % imgname))
Exemple #8
0
	# PLOTS
	
	print("plotting gaze data")

	# loop through trials
	for trialnr in range(len(data)):
		
		# load image name, saccades, and fixations
		imgname = data[trialnr][header.index("image")]
		saccades = edfdata[trialnr]['events']['Esac'] # [starttime, endtime, duration, startx, starty, endx, endy]
		fixations = edfdata[trialnr]['events']['Efix'] # [starttime, endtime, duration, endx, endy]
		
		# paths
		imagefile = os.path.join(IMGDIR,imgname)
		rawplotfile = os.path.join(pplotdir, "raw_data_%s_%d" % (ppname,trialnr))
		scatterfile = os.path.join(pplotdir, "fixations_%s_%d" % (ppname,trialnr))
		scanpathfile =  os.path.join(pplotdir, "scanpath_%s_%d" % (ppname,trialnr))
		heatmapfile = os.path.join(pplotdir, "heatmap_%s_%d" % (ppname,trialnr))
		
		# raw data points
		draw_raw(edfdata[trialnr]['x'], edfdata[trialnr]['y'], DISPSIZE, imagefile=imagefile, savefilename=rawplotfile)

		# fixations
		draw_fixations(fixations, DISPSIZE, imagefile=imagefile, durationsize=True, durationcolour=False, alpha=0.5, savefilename=scatterfile)
		
		# scanpath
		draw_scanpath(fixations, saccades, DISPSIZE, imagefile=imagefile, alpha=0.5, savefilename=scanpathfile)

		# heatmap		
		draw_heatmap(fixations, DISPSIZE, imagefile=imagefile, durationweight=True, alpha=0.5, savefilename=heatmapfile)
def read_files(reduced, csvonly):

    # Loop through all files
    for ppname in PPS:
        print("loading gaze data")

        # path
        fp = os.path.join(DATADIR, '%s.tsv' % ppname)

        # check if the path exist
        if not os.path.isfile(fp):
            raise Exception(
                "No eye data file file found for participant '%s'" % (ppname))

        # read the file
        tobiidata = read_tobii(fp, reduced, missing=0.0, debug=True)

        #save_csv(tobiidata)

        pplotdir = os.path.join(PLOTDIR, ppname[:3])

        if not csvonly:
            print("plotting gaze data")

        # Loop through trials
        for trialnr in range(len(tobiidata)):

            # Load image name, saccades, and fixations
            imgname = "screenshot.jpg"
            imagefile = os.path.join(IMGDIR, imgname)
            print(imagefile)
            # [starttime, endtime, duration, startx, starty, endx, endy]
            saccades = tobiidata[trialnr]['events']['Esac']
            # [starttime, endtime, duration, endx, endy]
            fixations = tobiidata[trialnr]['events']['Efix']

            # cognitive load
            if int(ppname[4:5]) == 1:
                cognitive_load = "LOW"
            else:
                cognitive_load = "HIGH"
            if reduced:
                suffix = "_reduced"
            else:
                suffix = ""

            # Save the fixation and saccades in csv format for MATLAB
            save_csv(fixations, saccades, ppname, suffix)

            if not csvonly:
                # paths
                rawplotfile = os.path.join(
                    pplotdir,
                    "raw_data_%s_%s%s" % (ppname[:3], cognitive_load, suffix))
                scatterfile = os.path.join(
                    pplotdir,
                    "fixations_%s_%s%s" % (ppname[:3], cognitive_load, suffix))
                scanpathfile = os.path.join(
                    pplotdir,
                    "scanpath_%s_%s%s" % (ppname[:3], cognitive_load, suffix))
                heatmapfile = os.path.join(
                    pplotdir,
                    "heatmap_%s_%s%s" % (ppname[:3], cognitive_load, suffix))

                # raw data points
                draw_raw(tobiidata[trialnr]['x'],
                         tobiidata[trialnr]['y'],
                         DISPSIZE,
                         imagefile=None,
                         savefilename=rawplotfile)

                # fixations
                draw_fixations(fixations,
                               DISPSIZE,
                               imagefile=None,
                               durationsize=True,
                               durationcolour=False,
                               alpha=0.5,
                               savefilename=scatterfile)

                # scanpath
                draw_scanpath(fixations,
                              saccades,
                              DISPSIZE,
                              imagefile=None,
                              alpha=0.5,
                              savefilename=scanpathfile)

                # heatmap
                draw_heatmap(fixations,
                             DISPSIZE,
                             imagefile=None,
                             durationweight=True,
                             alpha=0.5,
                             savefilename=heatmapfile)
Exemple #10
0
        imgfile = os.path.join(IMGDIR, imgname)
        print imgname, imgfile
        # get the fixations
        fixations = gazedata[i]['events']['Efix']
        # get the saccades
        saccades = gazedata[i]['events']['Esac']
        # plot a heatmap
        gazeplotter.draw_heatmap(fixations,
                                 RESOLUTION,
                                 imagefile=imgfile,
                                 alpha=0.5,
                                 invert_x=True,
                                 invert_y=False,
                                 savefilename=os.path.join(
                                     outdir, '%s_fix.png' % imgname))

        gazeplotter.draw_fixations(fixations,
                                   RESOLUTION,
                                   imagefile=imgfile,
                                   alpha=0.5,
                                   invert_x=True,
                                   invert_y=False,
                                   savefilename=os.path.join(
                                       outdir, '%s_heatmap.png' % imgname))

        # gazeplotter.draw_scanpath(fixations, saccades, RESOLUTION, imagefile=imgfile,
        #		alpha=0.5, invert_x=True, invert_y=False,
        #		savefilename=os.path.join(outdir ,'%s_scan.png' % imgname))

        print "YEEEEEEEEEEEE"