Esempio n. 1
0
def affordancePerSacc(trim = True, exclY = True, dv = "RT"):
	
	"""
	"""


	fig = plt.figure()
	title = "Affordance effect per sacc - dv = %s" % dv
	plt.suptitle(title)
	plotNr = 1
	
	for exp in ["004A", "004B"]:
		
		colList = ["red", "blue"]
	
		plt.subplot(1,2,plotNr)
		
		plt.title("Exp = %s" % exp)
		
		dm = getDM.getDM(exp)
	
		for sacc in ["1", "2"]:
			
			_dm = dm.select("endX%sNorm != ''" % sacc)
			_dm = _dm.select("endX%sNorm > -.5" % sacc)
			_dm = _dm.select("endX%sNorm < .5" % sacc)

			if exclY:
				_dm = _dm.select("endY%sNorm != ''" % sacc)
				_dm = _dm.select("endY%sNorm > -.5" % sacc)
				_dm = _dm.select("endY%sNorm < .5" % sacc)
			
			trimmed_dm = _dm.selectByStdDev(keys =["comp", "file"], dv = dv)
		
		
			for val in trimmed_dm.unique("comp"):
				print val
				print trimmed_dm["RT"][trimmed_dm.where("comp == '%s'" % val)].mean()
			
			pm = PivotMatrix(trimmed_dm, ["comp"], ["file"], dv = dv, colsWithin = True)
			
			am = AnovaMatrix(trimmed_dm, ["comp"], dv = dv, \
				subject = "file")._print(ret=True)

			print am
			
			col = colList.pop()
			pm.plot(nLvl1=1, fig = fig, colors = [col])
			plt.show()
		plt.legend(["data sacc 1", "data sacc 2"])
		plotNr +=1
			
	plt.show()
Esempio n. 2
0
def perHandle(trim = True, exclY = True):
	
	"""
	"""
	
	fig = plt.figure()
	title = "Per handle side - exclY = %s" % exclY
	
	for sacc in ["1", "2", "3"]:
		
		if sacc == "3":
			continue
		colList = ["#3465a4","#73d216", "#f57900"]
		
		plt.subplot(1,3,int(sacc))
		for exp in ["004A", "004B"]:
			
			dm = getDM.getDM(exp = exp)
			
			# Only include on-object saccades:
			dm = dm.select("endX%sNorm != ''" % sacc)
			dm = dm.select("endX%sNorm > -.5" % sacc)
			dm = dm.select("endX%sNorm < .5" % sacc)
			
			if exclY:
				dm = dm.select("endY%sNorm != ''" % sacc)
				dm = dm.select("endY%sNorm > -.5" % sacc)
				dm = dm.select("endY%sNorm < .5" % sacc)
			
			if exp == "004A":
				dvList = ["endX%sNorm" % sacc, "endX%sCorrNorm" % sacc]
			else:
				dvList = ["endX%sNorm" % sacc]
				
				for dv in dvList:
					
					print dv
					
					if trim:
						dm = dm.selectByStdDev(keys = ["file"], dv = dv)
					
					pm = PivotMatrix(dm, ["handle_side"], ["file"], dv=dv, colsWithin=True)
					pm._print()
					sys.exit()
					col = colList.pop()
					pm.plot(nLvl1 = 1,fig = fig, colors = [col])
		# Modify plot:
		plt.xlabel("handle side")
		plt.ylabel("normalised landing position")
		plt.axhline(0, linestyle = "--", color = "#888a85")
		
	plt.savefig("%s.png" % title)
Esempio n. 3
0
def affPerSacc(trim = True, exclY = False, dv = "RT", \
	colList = ["#73d216", "#f57900"]):
	
	"""
	Affordance effect as t-test between levels of the factor 
	compatibility, per saccade.
	
	Keyword arguments:
	"""

	fig = plt.figure()
	title = "Affordance effect per sacc - dv = %s - exclY = %s" % (dv, exclY)
	plt.suptitle(title)
	plotNr = 1
	
	for exp in ["004A", "004B"]:
		copyColList = colList[:]
		plt.subplot(1,2,plotNr)
		plt.title("Exp = %s" % exp)
		
		dm = getDM.getDM(exp)
	
		for sacc in ["1", "2"]:
			
			# Only on-object saccades:
			_dm = onObject.onObject(dm, sacc, exclY = exclY, verbose = False)
			# Trim:
			if trim:
				trimmed_dm = _dm.selectByStdDev(keys =["comp", "file"], dv = dv)
			else:
				trimmed_dm = _dm
		
			pm = PivotMatrix(trimmed_dm, ["comp"], ["file"], dv = dv, colsWithin = True)
			
			am = AnovaMatrix(trimmed_dm, ["comp"], dv = dv, \
				subject = "file")._print(ret=True)
			print am
			
			col = copyColList.pop()
			pm.plot(nLvl1=1, fig = fig, colors = [col])
		plt.legend(["data sacc 1", "data sacc 2"])
		plotNr +=1
			
	plt.savefig("%s.png"%title)
	plt.savefig("%s.svg"%title)
Esempio n. 4
0
def affordances(trim = True, exclY = True, dv = "RT"):
	
	"""
	"""

	fig = plt.figure()
	title = "Affordance effect per Exp"
	plt.suptitle(title)
	plotNr = 1
	
	for exp in ["004A", "004B"]:
		
		plt.subplot(1,2,plotNr)
		
		plt.title("Exp = %s" % exp)
		
		dm = getDM.getDM(exp)
		
		trimmed_dm = dm.selectByStdDev(keys =["handle_side", "response_hand", "file"], dv = dv)

		for val in trimmed_dm.unique("comp"):
			print val
			print trimmed_dm["RT"][trimmed_dm.where("comp == '%s'" % val)].mean()

		pm = PivotMatrix(trimmed_dm, ["handle_side", "response_hand"], ["file"], dv = dv, colsWithin = True)
		pm.linePlot(fig = fig)
		plt.show()


		pm = PivotMatrix(trimmed_dm, ["comp"], ["file"], dv = dv, colsWithin = True)
		pm.plot(nLvl1 = 1, fig = fig)
		plt.show()
		

		plotNr +=1
		
		###am = AnovaMatrix(trimmed_dm, ["comp"], dv = dv, \
			###subject = "file")._print(ret=True)

		###print am
		
			
	plt.show()
Esempio n. 5
0
def fixChange(dm, nBin = 4):
	
	dmGap = dm.select('gap == "zero"')
	dmNoGap = dm.select('gap == "overlap"')
	dmFixGray = dmNoGap.select('large_fix_col == "change"')
	dmFixBlack = dmNoGap.select('large_fix_col == "no_change"')
	
	fig = plt.figure()
	
	dmFixGray = dmFixGray.addField('fixSizeBin')
	dmFixGray = dmFixGray.calcPerc('large_fix_size', 'fixSizeBin', keys=['file'], nBin=nBin)
	pm = PivotMatrix(dmFixGray, ["fixSizeBin"], ["file"], dv = "saccLat")
	pm.plot(fig=fig, nLvl1 = 1,colors = ["blue"])

	dmFixBlack = dmFixBlack.addField('fixSizeBin')
	dmFixBlack = dmFixBlack.calcPerc('large_fix_size', 'fixSizeBin', keys=['file'], nBin=nBin)
	pm = PivotMatrix(dmFixBlack, ["fixSizeBin"], ["file"], dv = "saccLat")
	pm.plot(fig=fig, nLvl1 = 1,colors = ["red"])
	plt.legend(["color change", "no color change"])
	plt.show()
Esempio n. 6
0
def ovpSingleFix(dm, counter = 'fixCount', \
		rt = 'rtFromLanding', ws = True, nRows = 2, nCols = 4, nBin = 4):
	
	"""
	Plots OVP effects (only the ones that are suitable) for single-fixation
	cases only
	"""
	
	# Select only single fixations:
	dm = dm.select('%s == 1' % counter)
	
	# Determine exp:
	exp = dm['exp'][0]
	
	
	if ws:
		keys = ['file']
	else:
		keys = None

	# Add factors containing bins:
	dm = dm.addField("binned_endX1")
	dm = dm.calcPerc("endX1Norm", "binned_endX1", \
		keys = keys, nBin = nBin)
	if exp == "004A":
		dm = dm.addField("binned_endX1Corr")
		dm = dm.calcPerc("endX1CorrNorm", "binned_endX1Corr", \
			keys = keys, nBin = nBin)
	
	
	# Create figure:
	fig = plt.figure()
	#fig = plt.figure(figsize = (10,5))
	plt.subplots_adjust(wspace = .4, hspace = 0)
	figName = "%s: OVP effects for single fixations only - counter = %s - WS = %s" % (exp, counter, ws)
	plt.suptitle(figName)

	plotCount = 0

	# Define keys:
	factors = ["binned_endX1"]
	subjectID = ["file"]
	dvList = [rt, "durationFix1", "gazeDur", "saccLat1"]
	
	if exp == "004A":
		factorList = ["binned_endX1", "binned_endX1Corr"]
	else:
		factorList = ["binned_endX1"]
		
	for factors in factorList:
		for dv in dvList:
			
			plotCount +=1
			
			# Exclude trials on which the dv does not exist:
			_dm = dm.select("%s != ''"%dv)
			
			plt.subplot(nRows, nCols, plotCount)
			#if factors == factorList[0]:
				#plt.title(dv)
			pm = PivotMatrix(_dm, factors, subjectID, dv, colsWithin = True)
			pm.plot(nLvl1 = 1, fig = fig)
			
			if dv == 'endX2Norm':
				plt.axhline(0, linestyle = '--', color = 'gray')
				
			if factors == factorList[0]:
				plt.xticks([])

	plt.savefig("%s RT = %s.png"%(figName,rt))
Esempio n. 7
0
def timeCourse(yLim = [-.25,.25], exclY = False, nRows = 1, nCols = 3, \
	colList = ["#ef2929", "#3465a4","#73d216", "#f57900"],\
	lLegend = ["exp1: relative to center", "exp1: relative to CoG",\
	"exp2: relative to CoG"], binMax = 10, binMin = 2):

	"""
	Time course per saccade
	"""
	
	if exclY:
		binMax = 3
		binMin = 1

	fig = plt.figure()#figsize = (9,7))
	
	plt.subplots_adjust(wspace = 0)
	
	title = "Time course per saccade - exclY = %s -binMax = %s binMin = %s" \
		% (exclY, binMax, binMin)
	#plt.suptitle(title)
	plotNr = 0

	
	lLegend = ["Experiment 1 (relative to center)", "Experiment 1 (relative to CoG)", \
		"Experiment 2 (relative to CoG)", "Saliency-model simulation"]
	

	dm_sim = getDM.getDM("004C")
	
	for sacc in ["1", "2", "3"]:
		plotNr +=1
		
		copyColList = ["#73d216","#f57900","#3465a4","#3465a4"]
		markerList = ["s","^","o", "o"]		

		sim_avg = dm_sim["endX%sNormToHandle" % sacc].mean()
		
		for exp in ["004A", "004B"]:
			if exp == "004A":
				dvList = ["endX%sNormToHandle" % sacc, "endX%sCorrNormToHandle" % sacc]
			else:
				dvList = ["endX%sNormToHandle" % sacc]

			for dv in dvList:

				if sacc== "1":
					nBin = binMax
				if sacc== "2":
					nBin = binMax
				if sacc== "3":
					nBin = binMin

				
				dm = getDM.getDM(exp = exp)
				#dm = dm.select("corrDirection == 'correction awayHandle'")
					
				# Only on-object:
				_dm = onObject.onObject(dm, sacc, exclY = exclY)
			
				# Make bins, only for the first dv (for the second dv, the binned 
				# variable is the same and therefore already exists:
				saccLat = "saccLat%s" % sacc
				varToBin = saccLat
				binnedVar = "binnend%s" % varToBin
				binned_dm = _dm.addField(binnedVar)
				binned_dm = binned_dm.calcPerc(varToBin, binnedVar ,keys = ["file"], nBin = nBin)
				
				plt.subplot(nRows,nCols,plotNr)
				col = copyColList.pop()
				plt.title("sacc = %s" % sacc)
				pm = PivotMatrix(binned_dm, binnedVar, "file", dv, colsWithin = True, err = 'se')
				pm.plot(nLvl1=1, fig = fig, colors = [col])
		
		# Modify plot:
		if sacc != "1":
			plt.yticks([])
		if sacc == "3":
			plt.legend(lLegend)
		else:
			plt.legend([])
		plt.xticks([])
		plt.ylim(yLim)
		
		# Indicate reference point:
		plt.axhline(0, color = "#555753", linestyle = "--", linewidth = 2)
		# Indicate saliency peak:
		plt.axhline(sim_avg, color = "#ef2929", linestyle = "--", linewidth = 2)

	for ext in [".png", ".svg"]:
		plt.savefig(os.path.join(dst, "Figure2%s" % ext))
Esempio n. 8
0
def binPerSacc(direction = "ToHandle", cousineau = True,nBin = 8,trim = False, \
		figTitle = True, usePm = True, yLim = [-.25,.25], onlyExp2 = False):
	
	"""

	Argument:
	dm		--- data matrix
	
	Keyword argument:
	cousineau		--- withinize or not. Default = True.

	direction		--- {"toHandle", "toContrast"
	"""

	titleList = ["Exp1 absolute", "Exp1 corrected", "Exp2"]

	
	if not onlyExp2:
		fig = plt.figure(figsize = (9,7))
		title = "Landing %s as a function of bin PER SACC cousineau = %s trim = %s onlyExp2 = %s" % \
			(direction, cousineau,trim, onlyExp2)
		if figTitle:
			plt.title(title)
			
	nRows = 1
	nCols = 3
	plotNr = 0
	
	for exp in ["004A", "004B"]:
		
		if onlyExp2:
			if exp != "004B":
				continue
		
		start_dm = getDM.getDM(exp = exp, driftCorr = True)

		if direction == "ToHandle":
			start_dm = start_dm.select("contrast_side == 'control'", verbose = False)
		if direction == "ToContrast":
			start_dm = start_dm.select("contrast_side != 'control'", verbose = False)

		if exp == "004A":
			corrList = ["uncorrected", "corrected"]
			if onlyExp2:
				nCols = 1
				continue
		if exp == "004B":
			corrList = ["uncorrected"]
		
		for corr in corrList:
			subTitle = titleList[plotNr]
			
			plotNr +=1
			
			colList = [["#f57900"], ["#73d216"], ["#3465a4"]]
										 
			
			if onlyExp2:
				fig = plt.figure(figsize = (3,7))
				title = "Landing %s as a function of bin PER SACC ONLY EXP2 cousineau = %s trim = %s onlyExp2 = %s" % \
					(direction, cousineau,trim, onlyExp2)
				
			
			for saccCount in ["1", "2", "3"]:
				
				if saccCount == "1":
					nBin = 10
				if saccCount == "2":
					nBin = 10
				if saccCount == "3":
					nBin = 3
				
				print '\n\tsacc count = %s\n' % saccCount
				
				if corr == "uncorrected":
					dv = "endX%sNorm%s"%(saccCount, direction)
				elif corr == "corrected":
					dv = "endX%sCorrNorm%s"%(saccCount, direction)
					
				print "\tDV = %s\n" % dv

				dv_dm = timecourse.onObject(start_dm,dv, verbose = False)
				
				saccLat = "saccLat%s" % saccCount
				
				# Trim the data matrix such that the most extreme latencies are excluded:
				if trim:
					trimmed_dm = dv_dm.selectByStdDev(keys = ["file"], dv = saccLat, verbose = False)
				else:
					trimmed_dm = dv_dm
				
				# Withinize sacc latencies, if wanted:
				print "\n\tcousineau = %s\n" % cousineau
				if cousineau:
					
					_dm = trimmed_dm.addField("cousineau_%s"%saccLat, dtype = None)
					_dm = _dm.withinize(saccLat, "cousineau_%s"%saccLat, "file", verbose = False, whiten=False)
					saccLat = "cousineau_%s"%saccLat
				else:
					_dm = dv_dm
					
					
				col = colList.pop()

				# Make bins, only for the first dv (for the second dv, the binned variable is the same and
				# therefore already exists:
				varToBin = saccLat
				binnedVar = "binnend%s" % varToBin
				binned_dm = _dm.addField(binnedVar)
				binned_dm = binned_dm.calcPerc(varToBin, binnedVar ,keys = ["file"], nBin = nBin)
				
				# Determine x and y means per bin by hand:
				if not usePm:
					
					lX = []
					lY = []
					binCount = 0
					for _bin in binned_dm.unique(binnedVar):  
					
					# Filter out all but one bin
						dm_one_bin = binned_dm.select('%s == %f' % (binnedVar, _bin))
				
						# Get the mean sacc lat and the mean landing position (for x and y axis, respectively):
						# NOTE: withinising doesn't make any real difference for the overall pattern. 
				
						yMean = dm_one_bin[dv].mean()
						xMean = dm_one_bin[varToBin].mean()
						binCount +=1
						print binCount, xMean
						lX.append(xMean)
						lY.append(yMean)
					
					if exp == "004B":
						print 'XXXXXXXXX'
						print saccCount
						i = 0
						for x in lX:
							i +=1
							print "Bin %s: " % i, x
						print 
						print 'xxxxxxxxxxx'
					if not onlyExp2:
						plt.subplot(nRows,nCols,plotNr)
						plt.title(subTitle)
					plt.plot(lX, lY, color = col[0], marker = 'o')
					plt.xlabel("binned saccade latencies from stimulus onset")
					plt.ylabel("landing position (%s) %s" % (corr,direction))
					
				# Disadvantages of pm: 
					# - There SHOULD be enough observations per participant to be able to plot
					# - bin number (instead of bin mean) on x axis
				if usePm:
					if not onlyExp2:
						plt.subplot(nRows,nCols,plotNr)
						plt.title(subTitle)
					
					pm = PivotMatrix(binned_dm, binnedVar, "file", dv, colsWithin = True, err = 'se')
					pm.plot(nLvl1=1, fig = fig, colors = col)
			
			if plotNr != "1":
				plt.yticks([])
			plt.xticks([])
			plt.ylim(yLim)
			plt.legend(["initial saccade", "refixation 1", "refixation 2"])
			plt.axhline(0, color = "#555753", linestyle = "--", linewidth = 2)
	plt.savefig(os.path.join('%s.png' % title))
	plt.savefig(os.path.join('%s.svg' % title))
Esempio n. 9
0
def binAllSaccs(direction = "ToHandle", figTitle = False, trim = True, cousineau = True, nBin = 15, usePm = True, err = 'se',\
		onlySacc1 = False, onlyExp2 = False):
	
	"""
	Throw all saccades latencies (since stim onset) in for bin analysis, irrespective of saccade count
	
	Arguments:
	dm
	direction --- {"ToHandle", "ToContrast"}, variable on the y axis
	
	Keyword arguments:
	onlyFirstSacc	--- True means only bin the FIRST sacc lateny
	
	Returns fig list
	
	
	"""
	lLabels = ["Exp1 absolute", "Exp1 corrected", "Exp2"]
			
	colList = [["#f57900"], ["#73d216"], ["#3465a4"]]
	fig = plt.figure(figsize = (3,7))
	title = "Landing %s as a function of ALL binned sacc lats cousineau = %s trim = %s usePm = %s onlyExp2 = %s onlySacc1 = %s" \
		% (direction, cousineau, trim, usePm, onlyExp2, onlySacc1)
	
	if figTitle:
		plt.title(title)
		
	
	for exp in ["004A", "004B"]:
		
		dm = getDM.getDM(exp = exp, driftCorr = True)
	
		if direction == "ToHandle":
			dm = dm.select("contrast_side == 'control'", verbose = False)
		if direction == "ToContrast":
			dm = dm.select("contrast_side != 'control'", verbose = False)
			
		lDm = []
		
		if exp == "004A":
			if onlyExp2:
				continue
			# Max sacc count = 4
			lSacc = range(1,5)
			
		if exp == "004B":
			# Max sacc count = 3
			lSacc = range(1,4)
			
		for saccCount in lSacc:
			
			if onlySacc1:
				if saccCount != 1:
					continue
			
			# Create dms containing all latencies (i.e., the to-be-binned variable) 
			# of a given saccade count, e.g.
			# almost all trials for the first saccade, and less and less for the
			# subsequent saccades.
			# Do the same for the landing positions (dv's on the y-axis):
			
			# Select one saccade:
			dm_sacc = dm.select("saccLat%s != ''" % str(saccCount))
			
			# Create new column containing sacc count:
			dm_sacc = dm_sacc.addField("saccNr", dtype = str)
			dm_sacc["saccNr"] = "sacc%s" % saccCount
			
			# Create new column containing IV and DV's, but without the
			# sacc count in the column header:
			dm_sacc = dm_sacc.addField("absSaccLat", dtype = float)
			dm_sacc["absSaccLat"] = dm_sacc["saccLat%s" % str(saccCount)]
			
			dm_sacc = dm_sacc.addField("abs%s" % direction, dtype = float)
			dm_sacc["abs%s" % direction] = dm_sacc["endX%sNorm%s"%(str(saccCount), direction)]
			
			dm_sacc = dm_sacc.addField("absCorr%s" % direction, dtype = float)
			dm_sacc["absCorr%s" % direction] = dm_sacc["endX%sCorrNorm%s"%(str(saccCount), direction)]
			
			# Add the dm to the list of dm's
			lDm.append(dm_sacc)

		# Combine all dm's into one big dm:
		merged_dm = lDm[0]
		
		for dm in lDm[1:]:
			merged_dm = merged_dm + dm
		
		if exp == "004A":	
			corrList = ["uncorrected", "corrected"]
			continue
		if exp == "004B":
			corrList = ["uncorrected"]
		
		for corr in corrList:
		
			if corr == "uncorrected":
				dv = "abs%s" % direction
			elif corr == "corrected":
				dv = "absCorr%s" % direction
				
			print "\tDV = %s\n" % dv
			
			# There should be no ''s in the dm anymore, but off-object saccades are still
			# possible, so this filtering remains necessary:
			dv_dm = timecourse.onObject(merged_dm,dv, verbose = False)
				
			saccLat = "absSaccLat"

			# Trim the data matrix such that the most extreme latencies are excluded:
			print "\n\ttrim = %s\n" % trim
			if trim:
				trimmed_dm = dv_dm.selectByStdDev(keys = ["file"], dv = saccLat, verbose = False)
			else:
				trimmed_dm = dv_dm
			
			# Withinize sacc latencies, if wanted:
			print "\n\tcousineau = %s\n" % cousineau
			if cousineau:
				
				_dm = trimmed_dm.addField("cousineau_%s"%saccLat, dtype = None)
				_dm = _dm.withinize(saccLat, "cousineau_%s"%saccLat, "file", verbose = False, whiten=False)
				saccLat = "cousineau_%s"%saccLat
			else:
				_dm = dv_dm
					
			# Make bins, only for the first dv (for the second dv, the binned variable is the same and
			# therefore already exists:
			varToBin = saccLat
			binnedVar = "binnend%s" % varToBin
			binned_dm = _dm.addField(binnedVar)
			binned_dm = binned_dm.calcPerc(varToBin, binnedVar ,keys = ["file"], nBin = nBin)
			
			col = colList.pop()
			print
			print "EXP = ", exp
			print "DV = ", dv
			print
			if not usePm:
				
				lX = []
				lY = []
				binCount = 0
				for _bin in binned_dm.unique(binnedVar):  
				
				# Filter out all but one bin
					dm_one_bin = binned_dm.select('%s == %f' % (binnedVar, _bin))
			
					# Get the mean sacc lat and the mean landing position (for x and y axis, respectively):
					# NOTE: withinising doesn't make any real difference for the overall pattern. 
			
					yMean = dm_one_bin[dv].mean()
					xMean = dm_one_bin[varToBin].mean()
					binCount +=1 
					print binCount,xMean
					
					lX.append(xMean)
					lY.append(yMean)
				
				i = 0
				for x in lX:
					i +=1
					print "Bin %s: " % i, x
					
				plt.plot(lX, lY, color = col[0], marker = 'o')
			
			if usePm:
				
				pm = PivotMatrix(binned_dm, binnedVar, "file", dv, colsWithin = True, err = err)
				pm.plot(nLvl1=1, fig = fig, colors = col)
				
				#pm.barPlot(fig = fig, xLabel = "binned saccade latencies from stimulus onset", \
					#yLabel = "landing position (%s) %s" % (corr,direction))
	plt.xlabel("Binned stimulus-saccade interval")
	plt.ylabel("Landing positiontowards handle")
	plt.legend(lLabels)
	plt.ylim(-.2, .2)
	plt.axhline(0, color = "#555753", linestyle = "--", linewidth = 2)
	
	plt.savefig("%s.png"%title)
	plt.savefig("%s.svg"%title)
	
	return fig
Esempio n. 10
0
def contrastSide(trim = True, exclOverlap = False):
	
	"""
	Landing position as a function of contrast.
	
	Positive values indicate landing position to the right,
	negative values indicate landing pos to the left
	"""
	
	fig = plt.figure()
	title = "Effect of contrast - exclOverlap = %s" % exclOverlap
	plt.suptitle(title)
	
	for sacc in ["1", "2", "3"]:
		
		colList = ["#ef2929", "#3465a4","#73d216", "#f57900"]
		plt.subplot(1,3, int(sacc))
		plt.title("sacc = %s"% (sacc))
		
		# Exp 1:
		exp = "004A"
		dm_004A = getDM.getDM(exp = exp, driftCorr = True, onlyControl = False)

		# This is the same for corrected landing positions (the saccade
		# doesn't change; only the reference point does)
		dm_004A = dm_004A.select("endX%sNorm != ''" % sacc, verbose = False)
		dm_004A = dm_004A.select("endX%sNorm > -.5" % sacc, verbose = False)
		dm_004A = dm_004A.select("endX%sNorm < .5" % sacc, verbose = False)
			
		for dv in ["endX%sNorm" % sacc, "endX%sCorrNorm" % sacc]:
			
			#If wanted, trim the data
			if trim:
				_dm = dm_004A.selectByStdDev(keys = ["contrast_side", "file"], dv = dv)

			# For experiment 1 there are not enough third fixations:
			if exp == "004A" and sacc == "3":
				
				colList = ["#ef2929", "#3465a4"]
				continue
			
			# Get pivot matrix:
			pm = PivotMatrix(_dm, ["contrast_side"], ["file"], dv=dv, colsWithin=True)#, xLabels = ["left", "control", "right"])
			col = colList.pop()
			pm.plot(fig = fig, nLvl1 = 1, colors = [col])

		# Experiment 2 and 3:
		dv = "endX%sNorm" % sacc
		
		for exp in ["004B", "004C"]:
			
			if exp == "004C" and exclOverlap:
				dm = dm.select("gap == 'zero'")
			
			print "EXP = ", exp
			
			dm = getDM.getDM(exp = exp, driftCorr = True, onlyControl = False)
			
			# This is the same for corrected landing positions (the saccade
			# doesn't change; only the reference point does)
			dm = dm.select("endX%sNorm != ''" % sacc, verbose = False)
			dm = dm.select("endX%sNorm > -.5" % sacc, verbose = False)
			dm = dm.select("endX%sNorm < .5" % sacc, verbose = False)
			
			#If wanted, trim the data
			if trim:
				_dm = dm.selectByStdDev(keys = ["contrast_side", "file"], dv = dv)
			# Get pivot matrix:
			pm = PivotMatrix(_dm, ["contrast_side"], ["file"], dv=dv, colsWithin=True)
			col = colList.pop()
			pm.plot(fig = fig, nLvl1 = 1, colors = [col])
		
		# Modify plot:
		plt.ylim(-.2, .2)
		
		#if sacc == "1":
		plt.legend(["Exp1 (abs)", "Exp1 (corr)", "Exp2 (abs)", "Exp2 (sim)"])
		if sacc == "3":
			plt.legend(["Exp2 (abs)", "Exp2 (sim)"])
		
		plt.axhline(0, color = "#888a85", linestyle = "--", linewidth = 2)
	
	plt.savefig("%s.png" % title)
Esempio n. 11
0
def timeCourse(direction = "ToHandle", cousineau = True,nBin = 8,trim = False, \
		usePm = True, yLim = [-.25,.25], onlyExp2 = False, exclY = True):

	"""
	"""
	
	if direction != "ToHandle":
		print "Only ToHandle at the moment!!"
		return

	titleList = ["Exp1: relative to center", "Exp1: relative to CoG", \
		"Exp2: relative to CoG"]

	fig = plt.figure(figsize = (9,7))
	
	title = "Time course per saccade - cousineau = %s trim = %s - exclY = %s" % \
		(direction, cousineau,exclY)
	plt.title(title)
			
	nRows = 1
	nCols = 3
	plotNr = 0
	
	for exp in ["004A", "004B"]:
		
		if exp == "004A":
			corrList = ["uncorrected", "corrected"]
		if exp == "004B":
			corrList = ["uncorrected"]
		
		for corr in corrList:
			subTitle = titleList[plotNr]
			
			plotNr +=1
			
			colList = [["#f57900"], ["#73d216"], ["#3465a4"]]
			
			for sacc in ["1", "2", "3"]:
				
				dm = getDM.getDM(exp = exp)
				
				#if sacc == "3":
				#	continue
				
				if sacc== "1":
					nBin = 3
				if sacc== "2":
					nBin = 3
				if sacc== "3":
					nBin = 2
					if exp == "004B":
						nBin = 1
				
				print '\n\tsacc count = %s\n' % sacc
				
				if corr == "uncorrected":
					dv = "endX%sNorm%s"%(sacc, direction)
				elif corr == "corrected":
					dv = "endX%sCorrNorm%s"%(sacc, direction)
					
				print "\tDV = %s\n" % dv

				# This is the same for corrected landing positions (the saccade
				# doesn't change; only the reference point does)
				dm = dm.select("endX%sNorm != ''" % sacc)
				dm = dm.select("endX%sNorm > -.5" % sacc)
				dm = dm.select("endX%sNorm < .5" % sacc)
		
				if exclY:
					dm = dm.select("endY%sNorm != ''" % sacc)
					dm = dm.select("endY%sNorm > -.5" % sacc)
					dm = dm.select("endY%sNorm < .5" % sacc)
				
				saccLat = "saccLat%s" % sacc
				
				# Trim the data matrix such that the most extreme latencies are excluded:
				if trim:
					_dm = dm.selectByStdDev(keys = ["file"], dv = saccLat, verbose = False)
				else:
					_dm = dm
				
				# Withinize sacc latencies, if wanted:
				print "\n\tcousineau = %s\n" % cousineau
				if cousineau:
					
					_dm = _dm.addField("cousineau_%s"%saccLat, dtype = None)
					_dm = _dm.withinize(saccLat, "cousineau_%s"%saccLat, "file", verbose = False, whiten=False)
					saccLat = "cousineau_%s"%saccLat
					
				col = colList.pop()

				# Make bins, only for the first dv (for the second dv, the binned variable is the same and
				# therefore already exists:
				varToBin = saccLat
				binnedVar = "binnend%s" % varToBin
				binned_dm = _dm.addField(binnedVar)
				binned_dm = binned_dm.calcPerc(varToBin, binnedVar ,keys = ["file"], nBin = nBin)
				
				# Disadvantages of pm: 
					# - There SHOULD be enough observations per participant to be able to plot
					# - bin number (instead of bin mean) on x axis
				plt.subplot(nRows,nCols,plotNr)
				plt.title(subTitle)
				pm = PivotMatrix(binned_dm, binnedVar, "file", dv, colsWithin = True, err = 'se')
				pm.plot(nLvl1=1, fig = fig, colors = col)
			
			if plotNr != "1":
				plt.yticks([])
			plt.xticks([])
			plt.ylim(yLim)
			plt.legend(["initial saccade", "refixation 1", "refixation 2"])
			plt.axhline(0, color = "#555753", linestyle = "--", linewidth = 2)
		#plt.show()
	plt.savefig(os.path.join('%s.png' % title))
	plt.savefig(os.path.join('%s.svg' % title))
Esempio n. 12
0
def contrastSide(trim = True, exclOverlap = False, exclY = True):
	
	"""
	Landing position as a function of contrast.
	
	Positive values indicate landing position to the right,
	negative values indicate landing pos to the left
	
	NOTE: be careful with using --shortcut, because
	for the contrast analyses the contrast manipulations
	should not be excluded.
	
	TODO: make a ToContrast variable, such that we have more observations
	per cell and can do the on-object filter on the y axis as well?
	The disadvantage is that we can't use the no-contrast-trials in this case
	#(because 'ToContrast' should be a difference score between two bins).
	"""
	
	fig = plt.figure()
	title = "Effect of contrast - exclOverlap = %s - exclY = %s" % (exclOverlap, exclY)
	plt.suptitle(title)
	
	for sacc in ["1", "2", "3"]:
		
		colList = ["#ef2929", "#3465a4","#73d216", "#f57900"]
		plt.subplot(1,3, int(sacc))
		plt.title("sacc = %s"% (sacc))
		
		# Exp 1:
		exp = "004A"
		dm1 = getDM.getDM(exp = exp, driftCorr = True, onlyControl = False)

		# This is the same for corrected landing positions (the saccade
		# doesn't change; only the reference point does)
		dm1 = dm1.select("endX%sNorm != ''" % sacc, verbose = False)
		dm1 = dm1.select("endX%sNorm > -.5" % sacc, verbose = False)
		dm1 = dm1.select("endX%sNorm < .5" % sacc, verbose = False)
		
		if exclY:
			dm1 = dm1.select("endY%sNorm != ''" % sacc)
			dm1 = dm1.select("endY%sNorm > -.5" % sacc)
			dm1 = dm1.select("endY%sNorm < .5" % sacc)
			
		for dv in ["endX%sNorm" % sacc, "endX%sCorrNorm" % sacc]:
			
			#If wanted, trim the data
			if trim:
				_dm1 = dm1.selectByStdDev(keys = ["contrast_side", "file"], dv = dv)

			# For experiment 1 there are not enough third fixations anyway,
			# not even when not filtering on-object on the y-axis.
			if exp == "004A" and sacc == "3":
				
				colList = ["#ef2929", "#3465a4"]
				continue
			
			# Get pivot matrix:
			pm = PivotMatrix(_dm1, ["contrast_side"], ["file"], dv=dv, colsWithin=True)#, xLabels = ["left", "control", "right"])
			col = colList.pop()
			pm.plot(fig = fig, nLvl1 = 1, colors = [col])

		# Experiment 2 and 3:
		dv = "endX%sNorm" % sacc
		
		for exp in ["004B", "004C"]:
			if exclY and exp == "004B" and sacc == "3":
				colList = ["#ef2929"]
			   
				continue
			
			if exp == "004C" and exclOverlap:
				dm = dm.select("gap == 'zero'")
			
			print "EXP = ", exp
			
			dm = getDM.getDM(exp = exp, driftCorr = True, onlyControl = False)
			
			# This is the same for corrected landing positions (the saccade
			# doesn't change; only the reference point does)
			dm = dm.select("endX%sNorm != ''" % sacc, verbose = False)
			dm = dm.select("endX%sNorm > -.5" % sacc, verbose = False)
			dm = dm.select("endX%sNorm < .5" % sacc, verbose = False)
			
			if exclY:
				dm = dm.select("endY%sNorm != ''" % sacc)
				dm = dm.select("endY%sNorm > -.5" % sacc)
				dm = dm.select("endY%sNorm < .5" % sacc)

			
			#If wanted, trim the data
			if trim:
				_dm = dm.selectByStdDev(keys = ["contrast_side", "file"], dv = dv)
			# Get pivot matrix:
			pm = PivotMatrix(_dm, ["contrast_side"], ["file"], dv=dv, colsWithin=True)
			col = colList.pop()
			pm.plot(fig = fig, nLvl1 = 1, colors = [col])
		
		# Modify plot:
		plt.ylim(-.2, .2)
		
		plt.legend(["Exp1 (abs)", "Exp1 (corr)", "Exp2 (abs)", "Exp2 (sim)"])
		if sacc == "3":
			plt.legend(["Exp2 (abs)", "Exp2 (sim)"])
			if exclY:
				plt.legend(["Exp2 (sim)"])
		
		plt.axhline(0, color = "#888a85", linestyle = "--", linewidth = 2)
	
	plt.savefig("%s.png" % title)
Esempio n. 13
0
def contrastSide(trim = True):
	
	"""
	Landing position as a function of contrast.
	
	Keyword arguments:
	
	"""
	
	colList = ["#ef2929","#73d216","#f57900","#3465a4"]
	
	lLegend = ["Exp. 1 (relative to center)", "Exp. 1 (relative to CoG)", \
		"Experiment 2 (relative to CoG)", "Saliency-model simulation"]
	
	yLim = [-.3, .3]
	yTitle = "normalised landing position"
	
	fig = plt.figure()
	title = "Effect of contrast"
	plt.suptitle(title)
	plt.subplots_adjust(wspace = 0)

	
	for sacc in ["1", "2"]:#, "3"]:
		copyColList = colList[:]
		plt.subplot(1,2, int(sacc))
		plt.title("sacc = %s"% (sacc))

		#linestyles = ['o-', ',--', 'x:' #TODO
		for exp in ["004A", "004B", "004C"]:
			dm = getDM.getDM(exp, onlyControl = False)

			# Only on-object:
			on_dm = onObject.onObject(dm, sacc)
			
			if exp == "004A":
			
				dvList = ["endX%sNorm" % sacc, "endX%sCorrNorm" % sacc]
			else:
				dvList = ["endX%sNorm" % sacc]
				
						
			for dv in dvList:

				#If wanted, trim the data
				if trim:
					trim_dm = on_dm.selectByStdDev(keys = ["contrast_side", "file"], dv = dv)
				else:
					trim_dm = on_dm

				# Get pivot matrix:
				pm = PivotMatrix(trim_dm, ["contrast_side"], ["file"], dv=dv, colsWithin=True)

				col = copyColList.pop()
				#Constants.plotLineSymbols = [linestyles.pop()]
				pm.plot(fig = fig, nLvl1 = 1, colors = [col])
				
				if exp != "004C":
					am = AnovaMatrix(trim_dm, ["contrast_side"], dv, subject = "file")
					print exp, dv				
					print am
					#raw_input()
				
		plt.ylim(yLim)
		if sacc == "1":
			plt.ylabel(yTitle)
		if sacc == "2":
			plt.legend(lLegend)
			plt.yticks([])
		plt.axhline(0, color = "#888a85", linewidth = 2)
		plt.xlabel("Contrast manipulation")
	
	for ext in [".png", ".svg"]:
		plt.savefig("Figure_S1%s" % ext)