Exemplo n.º 1
0
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)
Exemplo n.º 2
0
 def save_all_raw(self, bar):
     """
     Saves all positions in an image file, each position is represented by a dot on the image.
     :return: None
     """
     rgb_im = self.image.convert('RGB')
     rgb_im.save('converted_image.jpg')
     del rgb_im
     dir = self.image_dir + "raw_points_images/"
     if not os.path.exists(dir):
         os.makedirs(dir)
     for u_id in self.user_positions:
         out = dir + u_id + "_points.png"
         pos = self.user_positions[u_id]
         draw_raw(pos, (self.rescaled_width, self.rescaled_height), imagefile='converted_image.jpg', savefilename=out)
         bar.next()
     #gc.collect()
     os.remove('converted_image.jpg')
Exemplo n.º 3
0
		maxdist = ang2cm(FIXTHRESH, SCREENDIST) * PIXPERCM
		# overwrite fixations
		for i in range(len(imagedata)):
			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
# 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'],
                         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,
Exemplo n.º 5
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)
Exemplo n.º 6
0
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)