Ejemplo n.º 1
0
def ovpOtherFactor(dm, factor, rt = 'rtFromLanding',\
		nRows = 2, nCols = 4, nBin = 5, ws = True):
	
	"""
	"""
	
	# Determine whether or not to first split data per participant
	# (i.e. to make within-subjects bins):
	if ws:
		keys = ['file', factor]
	else:
		keys = None

	# Determine exp:
	exp = dm["exp"][0]
	
	# 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)

	
	
	fig = plt.figure()
	plt.subplots_adjust(wspace = .3, hspace = .4)
	
	figName = "%s: OVP effects as a function of binned landing positions and %s - WS = %s" \
		% (exp, factor, ws)
	plt.suptitle(figName)

	plotCount = 0

	subjectID = ["file"]
	
	if exp == "004A":
		factorList = [[factor,"binned_endX1"], [factor,"binned_endX1Corr"]]
	else:
		factorList = [[factor,"binned_endX1"]]
		
	for factors in factorList:
		for dv in [rt, "durationFix1", "refixProb", "saccCount"]:
			
			plotCount +=1
		
			_dm = dm.select("%s != ''"%dv)
			
			plt.subplot(nRows, nCols, plotCount)
			plt.title(dv)
			pm = PivotMatrix(_dm, factors, subjectID, dv, colsWithin = True)
			pm.linePlot(fig = fig)

	plt.savefig("%s.png"%figName)
Ejemplo n.º 2
0
def simon(dm):
	
	"""
	"""
	

	pm = PivotMatrix(dm, ['response_hand', 'mask_side'], ['file'], dv='RT', colsWithin=False)
	pm._print()
	pm.barPlot(show=True)
	plt.title("simon effect")
Ejemplo n.º 3
0
def affordance(dm):
	
	"""
	"""
	
	dm = dm.select('symm == "asymm"')

	pm = PivotMatrix(dm, ['response_hand', 'handle_side'],['file'], dv = "RT")
	pm.barPlot(show=True)
	plt.title("affordance effect")
Ejemplo n.º 4
0
def gapEffect(dm, dv = "saccLat"):
	
	"""
	Regardless of color change...
	"""
	
	pm = PivotMatrix(dm, ['gap'],['file'],dv =dv)
	pm._print()
	pm.barPlot(show=True)
	plt.ylabel(dv)
	plt.title("gap effect")
Ejemplo n.º 5
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()
Ejemplo n.º 6
0
def affCross(trim = True, exclY = False, dv = "RT"):
	
	"""
	Affordance effect as cross-over interaction between handle
	and response hand ACROSS saccades
	
	NOTE: on-object is difficult here, because we're not
	looking across saccades.
	"""

	fig = plt.figure()
	title = "Affordance effect per Exp - exclY = %s" % exclY
	plt.suptitle(title)
	plotNr = 1
	
	for exp in ["004A", "004B"]:
		
		if exp != "004B":
			continue
		
		
		plt.subplot(1,2,plotNr)
		plt.title("Exp = %s" % exp)
		
		dm = getDM.getDM(exp)
		
		dm = onObject.onObject(dm, "1", exclY = exclY)

		if trim:
			trimmed_dm = dm.selectByStdDev(keys = \
				["handle_side", "response_hand", "file"], dv = dv)
		else:
			trimmed_dm = dm

		am = AnovaMatrix(trimmed_dm, ["handle_side", "response_hand"], dv = dv, \
			subject = "file")._print(ret=True)
		print am
#		raw_input()
		
		# Get descriptive statistics:
		pm = PivotMatrix(trimmed_dm, ["comp"], ["file"], colsWithin = False, \
			dv = dv, err = 'se')
		print pm
		
		
		raw_input()
		pm = PivotMatrix(trimmed_dm, ["handle_side", "response_hand"], \
			["file"], dv = dv, colsWithin = True)
		pm.linePlot(fig = fig)
		
		plotNr +=1
		
	plt.savefig("%s.png"%title)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
def affLumCongr(dm):
	
	dm = dm.select('symm == "asymm"')

	xLabels = ["hande left", "handle right"]
	lLabels = ["control", "more contrast right", "more contrast left"]
	yLabel = "landing position: negative = left, positive = right"
	
	pm = PivotMatrix(dm, ['handle_side', 'mask_side'], ['file'], \
		dv='endX')
	pm._print()
	pm.barPlot(xLabels = xLabels, lLabels = lLabels, yLabel = yLabel, show=True)
	plt.title("overlap between contrast and affordance")
Ejemplo n.º 9
0
def lumBinAn(dm, nBin = 8):
	
	"""
	"""
	
	dm = latBins(dm)
	
	pm = PivotMatrix(dm, ['mask_side', 'saccLatBin'], ['file'], dv='endX', colsWithin=False)
	pm._print()
	xLabels = range(1,nBin+1)
	xLabel = "binned latencies"
	lLabel = "contrast manipulation"
	lLabels = ["control", "more contrast right", "more contrast left"]
	#lLabels = None
	yLabel = "landing position - negative = left, positive = right"
	pm.linePlot(show=True,xLabels = xLabels, xLabel = xLabel, yLabel = yLabel, legendTitle = lLabel, lLabels = lLabels)
	plt.axhline(0, color = "grey", linestyle = "--")
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
def affordanceEffect(dm, nRows = None, nCols = None, \
		rowCount = None, fig = None):
	
	"""
	RT as a function of handle side and response handle
	
	Note: this two-way interaction should be identical
	to a main effect of compatibility.
	
	Arguments:
	dm
	
	Keyword arguments:
	nRows
	nCols
	rowCount
	fig
	"""

	# Select only handled objects:
	dm = dm.select("symm == 'asymm'")
	
	# Select only trials on which there was no mask applied:
	dm = dm.select("contrast_side == 'control'")
	
	#fig = plt.figure()
	nPlot = 0
	
	factors = ["response_hand", "handle_side"]
	pp = ["file"]
	dv = "rtFromLanding"
		
	# Trim:
	_dm = dm.selectByStdDev(keys = factors + pp, dv = dv)
	
	
	am = AnovaMatrix(_dm, factors = factors, dv = dv, \
		subject = pp[0])._print(maxLen=10, ret=True)
	
	plt.subplot2grid((nRows,nCols), (rowCount, 0))
	pm = PivotMatrix(_dm, factors, pp, dv = dv, colsWithin = True)
	pm.linePlot(fig = fig, legendTitle = factors[0], xLabel = factors[1])

	plt.subplot2grid((nRows,nCols), (rowCount, 1), colspan=2)
	plt.text(0.1,0.1,am, family='monospace')
Ejemplo n.º 12
0
def contrastEffect(dm, saccCount):
	
	"""
	Plots dist hist of sacc latencies as a function of gap condition.
	
	Arguments:
	dm
	saccCount
	"""
	
	# Define keys:
	factors = ["contrast_side", "gap"]
	pp = ["file"]
	dv = "saccLat%s" % saccCount
	
	exp = dm["exp"][0]
	
	
	# Apply selections:
	dm = dm.select("%s != ''" % dv)
	dm = dm.selectByStdDev(keys = factors + pp, dv = dv)
	
	# Create figure:
	fig = plt.figure()
	plt.subplots_adjust(hspace = .4)
	figName = "%s: Latencies sacc %s as a function of Gap and Contrast" % (exp, saccCount)
	plt.suptitle(figName)
	plt.subplot2grid((2,2), (0, 0))
	
	pm = PivotMatrix(dm, factors, pp, dv, colsWithin = True)
	pm.linePlot(fig = fig,xLabel = factors[-1], legendTitle = factors[0], lLabels = ["left", "contrast", "right"])
	# NOTE why I have to give the lLabels as a parameter: the underscore of "_left" gives problems for plotting
	## the legend.??
	plt.ylabel(dv)
	
	am = AnovaMatrix(dm, factors = factors, dv = dv, \
		subject = pp[0])._print(maxLen=10, ret=True)
	plt.subplot2grid((2,2), (1, 0), colspan=2)
	plt.text(0.1,0.1,am, family='monospace')
	plt.savefig("%s.png"%figName)
	
	return fig
Ejemplo n.º 13
0
def plotFullModel(dm, sacc):
	
	"""
	"""


	fig = plt.figure(figsize = (15, 5))
	plt.suptitle("Sacc = %s" % sacc)
	ax1 = plt.subplot(141)
	lCols = ["blue", "red", "orange", "yellow", "green", "pink"]
	
	xVar = "sacc%s_ex" % sacc
	yVar = "sacc%s_ey" % sacc
	
	dm = dm.select("%s != ''" % xVar)
	dm = dm.select("%s != ''" % yVar)

	dm = dm.select("%s != -1000" % xVar)
	dm = dm.select("%s != -1000" % yVar)

	for a in dm.unique("realAngle"):
		_dm = dm.select("realAngle == %s" % a)
		col = lCols.pop()
		plt.scatter(_dm[xVar], _dm[yVar], color = col, marker = ".", label = a)
	plt.axvline(constants.xCen, color = gray[3], linestyle = '--')
	plt.axhline(constants.yCen, color = gray[3], linestyle = '--')

	ax2 = plt.subplot(142)
	pm = PivotMatrix(dm, ["stim_type", "realAngle"], ["file"], "xNorm1", colsWithin =True)
	pm.linePlot(fig = fig)
	pm.save("PM.csv")
	pm._print()
	plt.axhline(0, color = gray[3], linestyle = "--")

	ax3 = plt.subplot(143)
	plt.title("object")
	dmObj= dm.select("stim_type == 'object'")
	#slope, intercept, r_value, p_value, std_err  = scipy.stats.linregress(stimObj["ecc"], stimObj["xNorm1"])
	x = dmObj["ecc"]
	y = dmObj["xNorm%s" % sacc]
	fit = scipy.polyfit(x,y,1)
	fit_fn = scipy.poly1d(fit)
	plt.plot(x,y, 'yo', x, fit_fn(x), '--k')

	ax4 = plt.subplot(144)
	plt.title("non-object")
	dmNo= dm.select("stim_type == 'non-object'")
	#slope, intercept, r_value, p_value, std_err  = scipy.stats.linregress(stimObj["ecc"], stimObj["xNorm1"])
	x = dmNo["ecc"]
	y = dmNo["xNorm%s" % sacc]
	fit = scipy.polyfit(x,y,1)
	fit_fn = scipy.poly1d(fit)
	plt.plot(x,y, 'yo', x, fit_fn(x), '--k')

	plt.savefig("./plots/Full_model_004C_sacc%s.png" % sacc)
	plt.show()
Ejemplo n.º 14
0
def affOtherFactor(dm, factor2, nRows = None, nCols = None, \
		rowCount = None, fig = None):
	
	"""
	RT as a function of compatibility and something else (e.g. category).
	
	Arguments:
	dm
	factor2
	"""	
	
	# Declare keys:
	factors = ["comp"] + [factor2]
	pp = ["file"]
	dv = "rtFromLanding"
	

	# Select only handled objects:
	dm = dm.select("symm == 'asymm'")
	# Trim:
	dm = dm.selectByStdDev(keys = factors + pp, dv = dv)

	# Create figure:
	#fig = plt.figure()
	nPlot = 0
	
	
	# Stats:
	am = AnovaMatrix(dm, factors = factors, dv = dv, \
		subject = pp[0])._print(maxLen=10, ret=True)
	
	# Plot:
	plt.subplot2grid((nRows, nCols), (rowCount, 0))
	pm = PivotMatrix(dm, factors, pp, dv = dv, colsWithin = True)
	pm.linePlot(fig = fig, lLabels = None,legendTitle = factors[0], xLabel = factors[1])
	plt.subplot2grid((nRows,nCols), (rowCount, 1), colspan=2)
	plt.text(0.1,0.1,am, family='monospace')
Ejemplo n.º 15
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()
Ejemplo n.º 16
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()
Ejemplo n.º 17
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))
Ejemplo n.º 18
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
Ejemplo n.º 19
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)
Ejemplo n.º 20
0
def vfDiff(dm,dv = "RT"):

	pm = PivotMatrix(dm, ['visual_field'],['file'], dv = dv)
	pm.barPlot(show=True)
	plt.ylabel(dv)
	plt.title("visual field difference")
Ejemplo n.º 21
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))
Ejemplo n.º 22
0
def desc(dm):

	"""
	Save descriptive statistics.

	Arguments:
	dm		--	A DataMatrix.
	"""

	dm_cor = dm.select('correct == 1')

	pm = PivotMatrix(dm, ['postRotDelay'], ['subject_nr'], \
	'soa', colsWithin=False)
	pm.save('output/soa.csv')
	pm = PivotMatrix(dm, ['subject_nr'], ['subject_nr'], \
		'correct', colsWithin=False)
	pm.save('output/accuracy.csv')
	pm = PivotMatrix(dm_cor, ['subject_nr'], ['subject_nr'], \
		'response_time', colsWithin=False)
	pm.save('output/rt.csv')
	pm = PivotMatrix(dm, ['postRotDelay', 'targetRot'], ['subject_nr'], \
		'correct', colsWithin=False)
	pm.save('output/acc.targetrot.postRotDelay.csv')
	pm = PivotMatrix(dm_cor, ['postRotDelay', 'targetRot'], ['subject_nr'], \
		'response_time', colsWithin=False)
	pm.save('output/rt.targetrot.postRotDelay.csv')
	# Do the split analysis on RTs
	pm = PivotMatrix(dm_cor, ['cond', 'postRotDelay', 'valid'], \
		['subject_nr'], dv='response_time')
	pm.save('output/rt.cond.postRotDelay.valid.pm.csv')
	# Do the full split on RTs after applying 2.5 SD
	pm = PivotMatrix(dm_cor.selectByStdDev(['subject_nr'], 'response_time'), \
		['cond', 'postRotDelay', 'valid'], ['subject_nr'], dv='response_time')
	pm.save('output/rt.2.5sd.cond.postRotDelay.valid.pm.csv')
	# Do the full split on iRts
	pm = PivotMatrix(dm_cor, ['cond', 'postRotDelay', 'valid'], \
		['subject_nr'], dv='iRt')
	pm.save('output/iRt.cond.postRotDelay.valid.pm.csv')
Ejemplo n.º 23
0
dm = dm.select("direction == 0")
dm = dm.addField("congruency", dtype = str)
dm = dm.addField("respHand", dtype = str)
dm["respHand"][dm.where("correct_response == 1")] = "left"
dm["respHand"][dm.where("correct_response == 2")] = "right"

for i in dm.range():
	
	handle = dm["flip"][i]
	respHand = dm["respHand"][i]
	
	
	if handle == respHand:
		dm["congruency"][i] = "congruent"
		print "congruent"
	else:
		dm["congruency"][i] = "incongruent"
		print "incongruent"
	
	
	print "flip = ", dm["flip"][i]
	print "correct response = ", dm["correct_response"][i]
	print "response hand = ", dm["respHand"][i]
	print "congruency = ", dm["congruency"][i]
	
pm = PivotMatrix(dm, ["congruency", "stim_type"], ["file"], "response_time", colsWithin = True)
pm.linePlot()
plt.show()


Ejemplo n.º 24
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))
Ejemplo n.º 25
0
def gapEffect(dm, saccCount = "1"):
	
	"""
	Plots dist hist of sacc latencies as a function of gap condition.
	
	Arguments:
	dm
	
	Keyword arguments:
	saccCount	--- Default = "1"
	
	"""
	
	# Define keys:
	factors = ["visual_field", "gap"]
	pp = ["file"]
	dv = "saccLat%s" % saccCount
	
	exp = dm["exp"][0]
	# Apply selections:
	dm = dm.select("%s != ''" % dv)
	dm = dm.selectByStdDev(keys = factors + pp, dv = dv)
	
	# Create figure:
	fig = plt.figure()
	plt.subplots_adjust(hspace = .4)
	figName = "%s: Latencies sacc %s as a function of Gap and Visual Field" % (exp, saccCount)
	plt.suptitle(figName)
	nPlots = 0

	for vf in ["upper", "lower"]:
		
		vf_dm = dm.select("visual_field == '%s'" % vf)
		
		#plt.subplot(nRows, nCols, nPlots)
		plt.subplot2grid((3,2), (nPlots, 0))
		
		for gap in ["zero", "overlap"]:
			
		
			if gap == "zero":
				col = "#ef2929"
			else:
				col = "#8ae234"
			
			plt.title("%s visual field" % vf)

			gap_dm = vf_dm.select("gap == '%s'" % gap)
			plt.hist(gap_dm[dv], bins = 30, color = col, alpha = .3)
			plt.xlim(0, 400)
			plt.ylabel('freq')
			plt.xlabel('initial saccade latencies')
				
		if vf == "lower":
			plt.legend(["zero", "overlap"], loc = 'best')
		nPlots +=1

	plt.subplot2grid((3,2), (0, 1), rowspan=2)
	pm = PivotMatrix(dm, factors, pp, dv, colsWithin = True)
	pm.linePlot(fig = fig)
	plt.ylabel("saccade latency")
	am = AnovaMatrix(dm, factors = factors, dv = dv, \
		subject = pp[0])._print(maxLen=10, ret=True)
	plt.subplot2grid((3,2), (2, 0), colspan=2)
	plt.text(0.1,0.1,am, family='monospace')
	plt.savefig("%s.png"%figName)
Ejemplo n.º 26
0
def landWithoutContrast(factor = ["handle_side"], nRows = 3, nCols = 4, saccNr = "1", \
	yLim = [-.1, .1], pp = ["file"], stats = True, colsWithin = True, sepPlots = True, exclY = True):
	
	"""
	Plots effect of handle side on landing-position variable. Only trials without
	contrast manipulation are included.
	
	Arguments:
	dm
	
	Keyword arguments:
	saccNr		--- nth saccade of interest (default = first, "1")
	sepPlots	--- save and return as separate plots or as subplots of one main figure
	"""

	# Create figure:
	# Experiment 004A:
	exp = "004A"
	dm1 = getDM.getDM(exp = exp, driftCorr = True)
	
	# Only use objects without contrast manipulation
	dm1 = dm1.select("mask_side == 'control'", verbose = False)
	figList = []
	
	if not sepPlots:
		
		fig = plt.figure(figsize = (10,2))
		nRows = 1
		nCols = 3
		plotNr = 0
	
	for dv in ["endX%sNorm" % saccNr, "endX%sCorrNorm" % saccNr]:
		
		if sepPlots:
			
			fig = plt.figure(figsize = (10,3))
			figName = "exp %s dv %s colsWithin = %s - exclY = %s" % (exp, dv, colsWithin, exclY)
		
		else:
			plotNr +=1
			plt.subplot(nRows,nCols,plotNr)
			
		_dm = dm1

		# Only trials where variable has a value:
		_dm = _dm.select("%s != ''"%dv)
		
		# Only on-object EM's:
		_dm = _dm.select('endX%sNorm < .5' % saccNr)
		_dm = _dm.select('endX%sNorm > -.5' % saccNr)

		if exclY:
			_dm = _dm.select('endY%sNorm < .5' % saccNr)
			_dm = _dm.select('endY%sNorm > -.5' % saccNr)
		
	
		# Trim:
		_dm = _dm.selectByStdDev(keys = factor + pp, dv = dv)
		
		
		#plt.subplot2grid((nRows,nCols), (plotCount, 0))
		pm = PivotMatrix(_dm, factor, pp, dv, colsWithin=colsWithin, err='se')
		#plt.axhline(0, linestyle = "--", color = "#555753")
		#plt.ylim(yLim)
		#pm.barPlot(fig=fig)
		
		pm.barPlot(fig = fig, _dir='right')
		plt.axvline(0, linestyle = "--", color = "#555753")
		plt.axhline(0.5, linestyle = "-", color = "#555753")
		plt.xlim(yLim)
		
		if sepPlots:
			if "Corr" in dv:
				plt.xlabel("corrected horizontal landing position")
			else:
				plt.xlabel("horizontal landing position")
		else:
			plt.xticks([])
		if stats:
			am = AnovaMatrix(_dm, factors = factor, dv = dv, \
				subject = pp[0])._print(maxLen=7, ret=True)
			print am
		#plt.subplot2grid((nRows,nCols), (plotCount, 1), colspan=3)
		#plt.title("Exp = %s DV = %s" % (exp, dv))
		#plt.text(0.05,0.1,am, family='monospace')
		#plt.xticks([])
		#plt.yticks([])
		#plotCount +=1
		
		if sepPlots:
			plt.savefig("%s.svg"%figName)
			plt.savefig("%s.png"%figName)
			#plt.show()
			figList.append(fig)
		
	# For experiment 004B we plot only the normalised landing position.
	# Correcting for CoG doesn't make sense here!
	
	
	exp = "004B"

	
	# Get dm:
	dm2 = getDM.getDM(exp = exp, driftCorr = True)
	
	# Only trials without contrast manipulation:
	dm2 = dm2.select("mask_side == 'control'")
	
	# Only trials where variable has a value:
	dm2 = dm2.select("%s != ''"%dv)
	
	# Only on-object eye movements:
	dm2 = dm2.select('endX%sNorm < .5' % saccNr)
	dm2= dm2.select('endX%sNorm > -.5' % saccNr)
	
	if exclY:
		dm2 = dm2.select('endY%sNorm < .5' % saccNr)
		dm2= dm2.select('endY%sNorm > -.5' % saccNr)
			
				 
	# Pivot matrix and stats:
	dv = "endX%sNorm" % saccNr


	# Trim:
	dm2 = dm2.selectByStdDev(keys = factor + pp, dv = dv)
	
	if sepPlots:
		fig = plt.figure(figsize = (10,3))
		figName = "exp %s dv %s colsWithin = %s - exclY = %s" % (exp, dv, colsWithin, exclY)
	
	else:
		plt.subplot(nRows,nCols,3)

	pm = PivotMatrix(dm2, factor, pp, dv = dv, colsWithin = colsWithin, err = 'se')
	#plt.subplot2grid((nRows,nCols), (plotCount, 0))
	
	pm.barPlot(fig = fig, _dir='right')
	plt.axvline(0, linestyle = "--", color = "#555753")
	plt.axhline(0.5, linestyle = "-", color = "#555753")
	plt.xlim(yLim)
	if sepPlots:
		plt.xlabel("horizontal landing position")
	
	else:
		plt.xticks([])
	if stats:
		am = AnovaMatrix(dm2, factors = factor, dv = dv, \
			subject = pp[0])._print(maxLen=7, ret=True)
		print am
	#plt.subplot2grid((nRows,nCols), (plotCount, 1), colspan=3)
	#plt.title("Exp = %s DV = %s" % (exp, dv))
	#plt.text(0.05,0.1,am, family='monospace')
	#plt.xticks([])
	#plt.yticks([])
	
	if sepPlots:
		plt.savefig("%s.png"%figName)
		plt.savefig("%s.svg"%figName)
		
		figList.append(fig)
		
		return figList
	else:
		return fig
Ejemplo n.º 27
0
def allSaccLats(dm, direction, figTitle = True, trim = True, cousineau = True, nBin = 15, usePm = True, err = 'se'):
	
	"""
	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:
	
	Returns fig list
	
	
	"""
	figList = []
	print '\n\tdirection = %s \n' % direction
	
	if direction == "ToHandle":
		start_dm = dm.select("contrast_side == 'control'")
	if direction == "ToContrast":
		start_dm = dm.select("contrast_side != 'control'")
	
	exp = start_dm['exp'][0]
	
	lDm = []
	
	if exp == "004A":
		# Max sacc count = 4
		lSacc = range(1,5)
	if exp == "004B":
		# Max sacc count = 3
		lSacc = range(1,4)
		
	for saccCount in lSacc:
		
		# 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
	
		corrList = ["corrected", "uncorrected"]
	
	for corr in corrList:
	
		fig = plt.figure(figsize = (3,7))
		title = "Landing (%s) %s as a function of ALL binned sacc lats exp %s cousineau = %s trim = %s usePm = %s" \
			% (corr, direction, exp, cousineau, trim, usePm)
			
		if figTitle:
			plt.title(title)
			
		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 = onObject(merged_dm,dv)
			
		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)
		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 = True, 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)
		
		if not usePm:
			
			lX = []
			lY = []
			
			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()
				
				lX.append(xMean)
				lY.append(yMean)
			
			
			plt.plot(lX, lY, color = "#3465a4", marker = 'o')
			plt.xlabel("binned saccade latencies from stimulus onset")
			plt.ylabel("landing position (%s) %s" % (corr,direction))
			plt.ylim(-.2, .2)
			plt.axhline(0, color = "#555753", linestyle = "--", linewidth = 2)
			plt.savefig(os.path.join(dst,'%s.png' % title))
		
		if usePm:
			
			pm = PivotMatrix(binned_dm, binnedVar, "file", dv, colsWithin = True, err = 'se')
			#pm.plot(nLvl1=1, fig = fig, xLabel = "binned saccade latencies from stimulus onset", \
			#	yLabel = "landing position (%s) %s" % (corr,direction))
			
			pm.barPlot(fig = fig, xLabel = "binned saccade latencies from stimulus onset", \
				yLabel = "landing position (%s) %s" % (corr,direction))
			
			plt.ylim(-.2, .2)
			plt.axhline(0, color = "#555753", linestyle = "--", linewidth = 2)
			plt.savefig(os.path.join(dst,'%s.png' % title))
			
			plt.savefig(os.path.join(dst,'%s.png' % title))
			
		
		figList.append(fig)

	return figList
Ejemplo n.º 28
0
def twoWayHandle(dm, dv, factor2, onlyControl = True, addStats = True, figTitle = True):
	
	"""
	Plots landing positions as a function of gap condition.
	
	Arguments:
	dm
	dv		--- dv, should be a landing variable
	factor2	-- second IV
	"""
	
	if onlyControl and factor2 == "contrast_side":
		print "You can't exclude contrast manipulation if one of the IV's is contrat_side"
		return
	
	if onlyControl:
		dm = dm.select("contrast_side == 'control'")
	
	# Define keys:
	factors = [factor2, "handle_side"]
	pp = ["file"]
	
	exp = dm["exp"][0]
	
	if addStats:
		nCols = nRows = 2
		fig = plt.figure()
		
	else:
		nCols = nRows = 1
		fig = plt.figure(figsize = (3,5))
		
	# Apply selections:
	dm = dm.select("%s != ''" % dv)
	dm = dm.selectByStdDev(keys = factors + pp, dv = dv)
	
	# Create figure:
	plt.subplots_adjust(hspace = .4)
	
	figName = "%s: %s as a function of %s and Handle Side onlyControl = %s" % (exp, dv, factor2, onlyControl)
	if figTitle:
		plt.suptitle(figName)
	plt.subplot2grid((nRows,nCols), (0, 0))
	
	pm = PivotMatrix(dm, factors, pp, dv, colsWithin = True)

	# Note why I have to give the lLabels as a parameter: the underscore of "_left" gives problems for plotting
	# the legend.??
	if factor2 == "contrast_side":
		lLabels = ["left", "contrast", "right"]
	else:
		lLabels = None
	pm.linePlot(fig = fig,xLabel = factors[-1], legendTitle = factors[0], lLabels = lLabels)
	
	plt.ylabel(dv)
	plt.axhline(0, color = "#555753", linestyle = "--", linewidth = 2)
	
	if addStats:
		am = AnovaMatrix(dm, factors = factors, dv = dv, \
			subject = pp[0])._print(maxLen=10, ret=True)
		plt.subplot2grid((nRows,nCols), (1, 0), colspan=2)
		plt.text(0.1,0.1,am, family='monospace')
		plt.savefig("%s.png"%figName)
	
	return fig
Ejemplo n.º 29
0
def ovp(dm, rt = "rtFromLanding", ws = True, nRows = 1, nCols = 8, nBin = 5, \
	binVar = "endX1Norm", binVar2 = None, figSize = (15,4), onlyControl = True):
	
	"""
	Plots OVP effects as a function of binned initial landing position.
	
	Arguments:
	dm			--- data matrix
	rt			--- variable for RT
	ws 			--- Vincentize or not.
	binVar		--- variable for first row of OVP plots
	binVar2		--- variable for second row of OVP plots (optional)
	onlyControl	--- exclude contrast manipulation. Default = True
	
	"""
	
	# If wanted, exclude the contrast manipulation:
	if onlyControl:
		dm = dm.select("mask_side == 'control'")
	
	# Determine whether or not to first split data per participant
	# (i.e. to make within-subjects bins):
	if ws:
		keys = ['file']
	else:
		keys = None

	# Determine exp:
	exp = dm["exp"][0]
	

	# Add factors containing bins:
	binnedVar = "binned_%s"%binVar
	dm = dm.addField(binnedVar)
	dm = dm.calcPerc(binVar, binnedVar,keys = keys, nBin = nBin)
	
	factorList = [binnedVar]
	
	if binVar2 != None:
		binnedVar2 = "binned_%s" % binVar2
		dm = dm.addField(binnedVar2)
		dm = dm.calcPerc(binVar2, binnedVar2, keys = keys, nBin = nBin)
		factorList.append(binnedVar2)
	
	# Create figure:
	fig = plt.figure(figsize = figSize)
	plt.subplots_adjust(wspace = .5)
	figName = "%s: OVP effects as a function of binned %s - WS = %s" % (exp, factorList, ws)
	plt.suptitle(figName)

	plotCount = 0

	# Define keys:
	subjectID = ["file"]
	dvList = [rt, "durationFix1", "refixProb", "saccCount", "gazeDur", "durationFix2", \
		"endX2Norm", "saccLat1"]
	
	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)
			plt.title(dv)
			pm = PivotMatrix(_dm, factors, subjectID, dv, colsWithin = True)
			pm.barPlot(fig = fig)
			
			if dv == 'endX2Norm':
				plt.axhline(0, linestyle = '--', color = 'gray')
				
			# Determine ylim's:
			if exp == "004A":
				if dv == "rtFromLanding":
					plt.ylim(500,550)
				if dv == "durationFix1":
					plt.ylim(260, 300)
				if dv == "durationFix2":
					plt.ylim(315, 355)
				if dv == "refixProb":
					plt.ylim(0.58, 0.72)
				if dv == "saccCount":
					plt.ylim(1.75, 1.94)
				if dv == "endX2Norm":
					plt.ylim(-.2, .2)
				if dv == "gazeDur":
					plt.ylim(500, 600)
				if dv == "saccLat1":
					plt.ylim(150, 200)
			
			if exp == "004B":
				
				if dv == "rtFromLanding":
					plt.ylim(400,500)
				if dv == "durationFix1":
					plt.ylim(260, 300)
				if dv == "durationFix2":
					plt.ylim(270, 300)
				if dv == "refixProb":
					plt.ylim(0.4, 0.65)
				if dv == "saccCount":
					plt.ylim(1.6, 2.)
				if dv == "endX2Norm":
					plt.ylim(-.2, .2)
				if dv == "gazeDur":
					plt.ylim(450, 510)
				if dv == "saccLat1":
					plt.ylim(150, 250)
			
			
			#plt.ylabel(dv)
			plt.xticks([])

	plt.savefig("%s RT = %s nBin = %s.png"%(figName,rt, nBin))
Ejemplo n.º 30
0
def splitHeavy(factor = ["corrDirection", "handle_side"], nRows = 3, nCols = 4, saccNr = "1", \
	yLim = [-.5, .5], pp = ["file"], stats = True, colsWithin = True, sepPlots = True, exclY = True):
	
		# Create figure:
	# Experiment 004A:
	exp = "004A"
	dm1 = getDM.getDM(exp = exp, driftCorr = True)
	
	dm1 = dm1.select("corrDirection != 'correction smaller than 8'")
	
	for corr in dm1.unique("corrDirection"):
		print corr
		tmp = dm1.select("corrDirection == '%s'" % corr)
		print "Corr direction = ", corr
		print tmp.unique("object")

	
	# Only use objects without contrast manipulation
	dm1 = dm1.select("mask_side == 'control'", verbose = False)
	figList = []
	
	if not sepPlots:
		
		fig = plt.figure(figsize = (10,2))
		nRows = 1
		nCols = 3
		plotNr = 0
	
	for dv in ["endX%sNorm" % saccNr, "endX%sCorrNorm" % saccNr]:
		
		if sepPlots:
			
			fig = plt.figure(figsize = (10,3))
			figName = "split by heavy side exp %s dv %s colsWithin = %s - exclY = %s" % (exp, dv, colsWithin, exclY)
		
		else:
			plotNr +=1
			plt.subplot(nRows,nCols,plotNr)
			
		_dm = dm1

		# Only trials where variable has a value:
		_dm = _dm.select("%s != ''"%dv)
		
		# Only on-object EM's
		_dm = _dm.select('endX%sNorm < .5' % saccNr)
		_dm = _dm.select('endX%sNorm > -.5' % saccNr)
		
		if exclY:
			_dm = _dm.select('endY%sNorm < .5' % saccNr)
			_dm = _dm.select('endY%sNorm > -.5' % saccNr)
	
	
		# Trim:
		_dm = _dm.selectByStdDev(keys = factor + pp, dv = dv)
		
		
		#plt.subplot2grid((nRows,nCols), (plotCount, 0))
		pm = PivotMatrix(_dm, factor, pp, dv, colsWithin=colsWithin, err='se')
		#plt.axhline(0, linestyle = "--", color = "#555753")
		#plt.ylim(yLim)
		#pm.barPlot(fig=fig)
		
		pm.barPlot(fig = fig, _dir='right', legendTitle = "handle side")
		plt.axvline(0, linestyle = "--", color = "#555753")
		plt.axhline(0.5, linestyle = "-", color = "#555753")
		plt.xlim(yLim)
		
		if sepPlots:
			if "Corr" in dv:
				plt.xlabel("corrected horizontal landing position")
			else:
				plt.xlabel("horizontal landing position")
		else:
			plt.xticks([])
		if stats:
			am = AnovaMatrix(_dm, factors = factor, dv = dv, \
				subject = pp[0])._print(maxLen=7, ret=True)
			print am
		#plt.subplot2grid((nRows,nCols), (plotCount, 1), colspan=3)
		#plt.title("Exp = %s DV = %s" % (exp, dv))
		#plt.text(0.05,0.1,am, family='monospace')
		#plt.xticks([])
		#plt.yticks([])
		#plotCount +=1
		
		if sepPlots:
			plt.savefig("%s.svg"%figName)
			plt.savefig("%s.png"%figName)
			#plt.show()
			figList.append(fig)
		
	# For experiment 004B we plot only the normalised landing position.
	# Correcting for CoG doesn't make sense here!
	
	exp = "004B"

	# Get dm:
	dm2 = getDM.getDM(exp = exp, driftCorr = True)
	
	# Only trials without contrast manipulation:
	dm2 = dm2.select("mask_side == 'control'")
	dm2 = dm2.select("corrDirection != 'correction smaller than 8'")
	
	# Only trials where variable has a value:
	dm2 = dm2.select("%s != ''"%dv)
	
	# Only on-object eye movements:
	dm2 = dm2.select('endX%sNorm < .5' % saccNr)
	dm2= dm2.select('endX%sNorm > -.5' % saccNr)
	
	if exclY:
		dm2 = dm2.select('endY%sNorm < .5' % saccNr)
		dm2= dm2.select('endY%sNorm > -.5' % saccNr)
			
	
	# Pivot matrix and stats:
	dv = "endX%sNorm" % saccNr
				 
	# Trim:
	dm2 = dm2.selectByStdDev(keys = factor + pp, dv = dv)
	
	if sepPlots:
		fig = plt.figure(figsize = (10,3))
		figName = "split by heavy side exp %s dv %s colsWithin = %s" % (exp, dv, colsWithin)
	
	else:
		plt.subplot(nRows,nCols,3)

	pm = PivotMatrix(dm2, factor, pp, dv = dv, colsWithin = colsWithin, err = 'se')
	#plt.subplot2grid((nRows,nCols), (plotCount, 0))
	
	pm.barPlot(fig = fig, _dir='right')
	plt.axvline(0, linestyle = "--", color = "#555753")
	plt.axhline(0.5, linestyle = "-", color = "#555753")
	plt.xlim(yLim)
	if sepPlots:
		plt.xlabel("horizontal landing position")
	
	else:
		plt.xticks([])
	if stats:
		am = AnovaMatrix(dm2, factors = factor, dv = dv, \
			subject = pp[0])._print(maxLen=7, ret=True)
		print am
	#plt.subplot2grid((nRows,nCols), (plotCount, 1), colspan=3)
	#plt.title("Exp = %s DV = %s" % (exp, dv))
	#plt.text(0.05,0.1,am, family='monospace')
	#plt.xticks([])
	#plt.yticks([])
	
	if sepPlots:
		plt.savefig("%s.png"%figName)
		plt.savefig("%s.svg"%figName)
		
		figList.append(fig)
		
		return figList
	else:
		plt.savefig('per corrDir.png')
		return fig