Beispiel #1
0
def saliency():
	
	"""
	Plots avg LPs simulation
	"""
	
	fig = plt.figure(figsize = (1.5,4))
	
	dm = DataMatrix(np.load(".cache/dm_sim_select_driftcorr.npy"))

	# PLOT SIMULATED SACCADES:
	for stimType in dm.unique("stim_type"):
		
		if stimType == "object":
			col = green[1]
		elif stimType == "non-object":
			col = red[1]
		
		lSacc = []
		for sacc in [1,2]:
			stimDm = dm.select("stim_type == '%s'" % stimType)
		
			m = stimDm["xNorm%s" % sacc].mean()
			lSacc.append(m)
			
		plt.plot([1,2], lSacc, color = col, marker = 'o', markerfacecolor = 'white',
			markeredgecolor = col, markeredgewidth = 1)
	# HACK:
	# PLOT REAL LPs:
	for stimType in dm.unique("stim_type"):
		
		if stimType == "object":
			col = blue[1]
		elif stimType == "non-object":
			col = orange[1]
		
		lSacc = []
		for sacc in [1,2]:
			stimDm = dm.select("stim_type == '%s'" % stimType)
		
			m = stimDm["xNorm%s" % sacc].mean()
			lSacc.append(m)
			
		plt.plot([1,2], lSacc, color = col, marker = 'o', markerfacecolor = 'white',
			markeredgecolor = col, markeredgewidth = 1, label = stimType)
	
	plt.axhline(0, linestyle = "--", color = gray[3])
	plt.ylim(-.3, .07)
	plt.xlim(0.8, 2.2)
	plt.legend(frameon = False)
	plt.savefig("./plots/simulation.png")
	plt.savefig("./plots/simulation.svg")
Beispiel #2
0
def saccEndPoints(dm):

    """
	Analyzes and plots the saccade endpoints.

	Arguments:
	dm		--	DataMatrix
	"""

    i = 1
    newFig()
    l = [["Condition", "Luminance", "SaccDir", "End X (M)", "End X (SD)"]]
    for cond in ("constant", "swap", "onset"):
        for saccCol in ("white", "black"):
            _dm = dm.select('cond == "%s"' % cond).select('saccCol == "%s"' % saccCol)
            a = (_dm.select('saccSide == "left"')["saccEndX"] - 512) / pxPerDeg
            l.append([cond, saccCol, "left", a.mean(), a.std()])
            a = (_dm.select('saccSide == "right"')["saccEndX"] - 512) / pxPerDeg
            l.append([cond, saccCol, "right", a.mean(), a.std()])
            plt.subplot(3, 2, i)
            plt.xlim(0, 1024)
            plt.ylim(0, 768)
            plt.title("%s - %s" % (cond, saccCol))
            plt.axvline(1024 / 2, linestyle=":", color="black")
            plt.axvline(1024 / 6, linestyle=":", color="black")
            plt.axvline(1024 - 1024 / 6, linestyle=":", color="black")
            plt.axhline(768 / 2, linestyle=":", color="black")
            plt.plot(_dm["saccEndX"], _dm["saccEndY"], ",", color=darkColor)
            if cond != "onset":
                plt.xticks([])
            else:
                plt.xticks([0, 512, 1024])
            if saccCol != "white":
                plt.yticks([])
            else:
                plt.yticks([0, 384, 768])
            i += 1
    dm = DataMatrix(l)
    dm.sort(["SaccDir"])
    dm.save("output/%s/saccEndPoints.csv" % exp)
    print dm
    saveFig("endPoints", show=True)
def descriptives(dm):

	l = [['pp', 'rt', 'resp', 'nchar', 'nfunc', 'chardur', 'funcdur']]
	for i in dm.range():
		sn, full_resp, rt = dm['subject_nr'][i], dm['full_response'][i], \
			dm['free_writing_time'][i]
		resp = dm['free_writing_result'][i].replace('Space', ' ')
		rt = rt / 1000. - (len(full_resp)+1)*1.185
		nchar = len(full_resp) + 1
		charDur = rt / (len(full_resp)+1)
		funcDur = rt / len(resp)
		nresp = len(resp)
		print(full_resp)
		print('%2d\t%s\t%.2f\t%d\t%d\t%.2f\t%.2f' % (sn, resp, rt, nchar, len(resp),
			charDur, funcDur))
		l.append([sn, rt, resp, nchar, len(resp), charDur, funcDur])
	dm = DataMatrix(l)
	dm.sort('pp')
	print(dm)
	dm.save('output/sentences.csv')
	def __init__(self, path='data', ext='.asc', startTrialKey='start_trial',
		endTrialKey='stop_trial', variableKey='var', dtype='|S128', maxN=None,
		maxTrialId=None, requireEndTrial=True, traceFolder='traces',
		offlineDriftCorr=False, skipList=[], blinkReconstruct=False, only=None,
		acceptNonMatchingColumns=True):

		"""
		Constructor. Reads all Eyelink ASCII files from a specific folder.

		Keyword arguments:
		path			--	the folder containing the csv files (default='data')
		ext				--	the extension of the csv files (default='.csv')
		startTrialKey	-- 	the start trial keyword (default='start_trial')
		endTrialKey		--	the stop trial keyword (default='stop_trial')
		variableKey		--	the variable keyword (default='var')
		dtype			--	the numpy dtype to be used (default='|S128')
		maxN			--	the maximum number of subjects to process
							(default=None)
		maxTrialId		--	the maximum number of trials to process
							(default=None)
		requireEndTrial	--	indicates whether an exception should be raised if a
							trial hasn't been neatly closed. Otherwise the trial
							is simply disregarded. (default=True)
		traceFolder		--	the folder to save the gaze traces. Traces are saved
							as 3d numpy arrays (x, y, pupil size) in .npy
							format. To start collecting traces, set
							`self.tracePhase` to a value. Use the value
							'__baseline__' to use an automatic baseline.
							(default='traces')
		offlineDriftCorr	--	Indicates whether coordinates should be
								corrected based on the drift-correction check,
								in case the 'active' drift correctrion is
								disabled (as on the Eyelink 1000).
								(default=False)
		skipList		--	A list of trialIDs that should not be processed.
							(default=[])
		blinkReconstruct	--	Indicates whether pupil size should be
								interpolated during blinks. (default=False)
		only			--	A list of files that should be analyzed, or None
							to analyze all files. Mostly useful for debugging
							purposes. (default=None)
		acceptNonMatchingColumns	--- Boolean indicating whether or not to
										raise an exception if current dm and
										to-be-added dm
										do not have identical column headers.
										If set to True, the intersection of
										column headers is used and the check
										is not carried out. If set to False,
										the the check is carried out.
										(default=True)
		"""

		self.startTrialKey = startTrialKey
		self.endTrialKey = endTrialKey
		self.variableKey = variableKey
		self.dtype = dtype
		self.requireEndTrial = requireEndTrial
		self.maxTrialId = maxTrialId
		self.tracePhase = None
		self.traceFolder = traceFolder
		self.traceSmoothParams = None
		self.offlineDriftCorr = offlineDriftCorr
		self.driftAdjust = 0,0
		self.skipList = skipList
		self.blinkReconstruct = blinkReconstruct
		self.acceptNonMatchingColumns = acceptNonMatchingColumns
		self.traceImg = '--traceimg' in sys.argv
		self.tracePlot = '--traceplot' in sys.argv

		print '\nScanning \'%s\'' % path
		self.dm = None
		nFile = 0
		for fname in os.listdir(path):
			if only != None and fname not in only:
				print 'Skipping %s ...' % fname
				continue
			if os.path.splitext(fname)[1] == ext:
				sys.stdout.write('Reading %s ...' % fname)
				sys.stdout.flush()
				a = self.parseFile(os.path.join(path, fname))
				dm = DataMatrix(a)

				if self.dm == None:
					self.dm = dm
				else:

					# If column headers are not identical:
					if self.dm.columns() != dm.columns():

						# Determine warning message:
						warningMsg = "The column headers are not identical. Difference:\n%s"\
						% "\n".join(list(set(self.dm.columns()).\
							symmetric_difference(set(dm.columns()))))

						# Determine whether to only print the warning,
						# or to raise an exception:
						if not acceptNonMatchingColumns:
							raise Exception(warningMsg)
						if acceptNonMatchingColumns:
							print warningMsg

					self.dm += dm

				print '(%d rows)' % len(dm)
				nFile += 1
			if maxN != None and nFile >= maxN:
				break
		print '%d files\n' % nFile
Beispiel #5
0
if __name__ == '__main__':



	l = [['img', 'xCogOrig', 'yCogOrig', 'xCogMatch', 'yCogMatch']]
	for obj in os.listdir(srcOb):
		
		#if not "paintbrush" in obj:
		#	continue
		if "png" in obj or 'cog-correct' in obj:
			continue
		nob = "non-object_%s" % obj		
		objPath = os.path.join(srcOb, obj)
		nobPath = os.path.join(srcNob, nob)
		print
		print 'Original %s' % objPath
		x, y = matchCog(objPath)
		print "COG original object = ", x
		#sys.exit()
		
		print 'Match %s' % nobPath
		_x, _y = matchCog(nobPath, xy=(x,y))
		l.append([obj, x, y, _x, _y])
		#plt.show()
		#break

	dm = DataMatrix(l)
	print dm
	dm.save('cogMatch.csv')
Beispiel #6
0
from exparser.DataMatrix import DataMatrix
import numpy as np


f = ".cache/004C_lat_driftcorr_False.npy"
dm = DataMatrix(np.load(f))

for pp in dm.unique("file"):
	ppDm = dm.select("file == '%s'" % pp, verbose = False)
	_ppDm = ppDm.select("xNorm1 == -1000", verbose = False)
	print pp, float(len(_ppDm))/float(len(ppDm))
Beispiel #7
0
def prepFit(dm, suffix=''):

	"""
	Perform a linear-regression fit on only the first 220 ms.

	Arguments:
	dm		--	DataMatrix

	Keyword arguments:
	suffix	--	A suffix for the output files. (default='')
	"""

	fig = newFig(size=bigWide)
	plt.subplots_adjust(wspace=0, hspace=0)
	i = 0

	l = [['subjectNr', 'sConst', 'iConst', 'sOnset', 'iOnset', 'sSwap',
		'iSwap']]

	for dm in [dm] + dm.group('subject_nr'):

		print 'Subject %s' % i
		row = [i]

		# We use a 6 x 2 plot grid
		# XX X X X X
		# XX X X X X
		if i == 0:
			# Overall plot
			ax = plt.subplot2grid((2,6),(0,0), colspan=2, rowspan=2)
			linewidth = 1
			title = 'Full data (N=%d)' % len(dm.select('cond != "swap"'))
		else:
			# Individual plots
			ax = plt.subplot2grid((2,6),((i-1)/4, 2+(i-1)%4))
			linewidth = 1
			title = '%d (N=%d)' % (i, len(dm.select('cond != "swap"')))

		plt.text(0.9, 0.1, title, horizontalalignment='right', \
			verticalalignment='bottom', transform=ax.transAxes)

		if i == 0:
			plt.xticks([0, 50, 100, 150, 200])
		elif i > 0 and i < 5:
			plt.xticks([])
		else:
			plt.xticks([0, 100])
		if i > 0:
			plt.yticks([])
		else:
			plt.yticks([0, -.01, -.02])
		plt.ylim(-.025, .01)
		plt.axhline(0, color='black', linestyle=':')
		for cond in ('constant', 'onset', 'swap'):
			_dm = dm.select("cond == '%s'" % cond, verbose=False)
			dmWhite = _dm.select('saccCol == "white"', verbose=False)
			xAvg, yAvg, errAvg= TraceKit.getTraceAvg(_dm, signal='pupil', \
				phase='postSacc', traceLen=postTraceLen, baseline=baseline, \
				baselineLock=baselineLock)
			xWhite, yWhite, errWhite = TraceKit.getTraceAvg(dmWhite, \
				signal='pupil', phase='postSacc', traceLen=postTraceLen, \
				baseline=baseline, baselineLock=baselineLock)
			yWhite -= yAvg
			xWhite = xWhite[:prepWin]
			yWhite = yWhite[:prepWin]
			if cond == 'constant':
				col = constColor
				lineStyle = '-'
			elif cond == 'onset':
				col = onsetColor
				lineStyle = '--'
			else:
				col = swapColor
				lineStyle = '-.'
				yWhite *= -1
			opts = Plot.regress(xWhite, yWhite, lineColor=col, symbolColor=col,
				label=cond, annotate=False, symbol=lineStyle, linestyle=':')
			s = 1000.*opts[0]
			_i = 1000.*opts[1]
			print 's = %.4f, i = %.4f' % (s, _i)
			if i > 0:
				row += [s, _i]
			else:
				plt.legend(frameon=False, loc='upper right')
		if i > 0:
			l.append(row)
		i += 1
	saveFig('linFitPrepWin%s' % suffix, show=False)
	dm = DataMatrix(l)
	dm.save('output/%s/linFitPrepWin%s.csv' % (exp, suffix))

	# Summarize the data and perform ttests on the model parameters
	for dv in ['s', 'i']:
		print'\nAnalyzing %s' % dv
		aConst = dm['%sConst' % dv]
		aOnset = dm['%sOnset' % dv]
		aSwap = dm['%sSwap' % dv]
		print 'Constant: M = %f, SE = %f' % (aConst.mean(), \
			aConst.std() / np.sqrt(N))
		print 'Onset: M = %f, SE = %f' % (aOnset.mean(), \
			aOnset.std() / np.sqrt(N))
		print 'Swap: M = %f, SE = %f' % (aSwap.mean(), \
			aSwap.std() / np.sqrt(N))
		# Standard t-tests
		t, p = ttest_rel(aConst, aOnset)
		print 'Const vs onset, t = %.4f, p = %.4f' % (t, p)
		t, p = ttest_rel(aSwap, aOnset)
		print 'Swap vs onset, t = %.4f, p = %.4f' % (t, p)
		t, p = ttest_rel(aConst, aSwap)
		print 'Const vs swap, t = %.4f, p = %.4f' % (t, p)
Beispiel #8
0
def fit(dm, suffix='', maxSmp=None):

	"""
	Fits the data based on an exponential pupil model.

	Arguments:
	dm		--	DataMatrixpass

	Keyword arguments:
	suffix	--	A suffix for the output files. (default='')
	maxSmp	--	The maximum number of samples to base the fit on, or None for
				no limit. (default=None)
	"""

	fig = newFig(size=bigWide)
	plt.subplots_adjust(wspace=0, hspace=0)
	i = 0

	l = [['subjectNr', 't0Const', 'speedConst', 'lim1Const', 'lim2Const', \
		't0Onset', 'speedOnset', 'lim1Onset', 'lim2Onset']]

	for dm in [dm] + dm.group('subject_nr'):

		print 'Subject %s' % i
		row = [i]

		# We use a 6 x 2 plot grid
		# XX X X X X
		# XX X X X X
		if i == 0:
			# Overall plot
			ax = plt.subplot2grid((2,6),(0,0), colspan=2, rowspan=2)
			# Draw 'window of preparation'
			plt.axvspan(0, prepWin, color=green[1], alpha=.2)
			linewidth = 1
			title = 'Full data (N=%d)' % len(dm.select('cond != "swap"'))
		else:
			# Individual plots
			ax = plt.subplot2grid((2,6),((i-1)/4, 2+(i-1)%4))
			linewidth = 1
			title = '%d (N=%d)' % (i, len(dm.select('cond != "swap"')))

		plt.text(0.9, 0.1, title, horizontalalignment='right', \
			verticalalignment='bottom', transform=ax.transAxes)

		if i == 0:
			plt.xticks([0, 500, 1000, 1500])
		elif i > 0 and i < 5:
			plt.xticks([])
		else:
			plt.xticks([0, 1000])
		if i > 0:
			plt.yticks([])
		else:
			plt.yticks([0, -.1, -.2, -.3])
		for cond in ('constant', 'onset'):
			_dm = dm.select("cond == '%s'" % cond, verbose=False)
			dmWhite = _dm.select('saccCol == "white"', verbose=False)
			xAvg, yAvg, errAvg= TraceKit.getTraceAvg(_dm, signal='pupil', \
				phase='postSacc', traceLen=postTraceLen, baseline=baseline, \
				baselineLock=baselineLock)
			xWhite, yWhite, errWhite = TraceKit.getTraceAvg(dmWhite, \
				signal='pupil', phase='postSacc', traceLen=postTraceLen, \
				baseline=baseline, baselineLock=baselineLock)
			yWhite -= yAvg
			if cond == 'constant':
				col = constColor
				lineStyle = '-'
			elif cond == 'onset':
				col = onsetColor
				lineStyle = '--'
			else:
				col = swapColor
				lineStyle = '-'
			if maxSmp != None:
				xWhite = xWhite[:maxSmp]
				yWhite = yWhite[:maxSmp]
			opts = fitCurve(xWhite, yWhite, col=col, label=cond, \
				linewidth=linewidth, lineStyle=lineStyle)
			print 't0 = %.4f, s = %.4f, l1 = %.4f, l2 = %.4f' % tuple(opts)
			t0 = opts[0]
			if i > 0:
				row += list(opts)
			else:
				plt.legend(frameon=False, loc='upper right')
			print '%s : %f' % (cond, t0)
		if i > 0:
			l.append(row)
		i += 1
	saveFig('fit%s' % suffix, show=False)
	dm = DataMatrix(l)
	dm.save('output/%s/fit%s.csv' % (exp, suffix))

	# Summarize the data and perform ttests on the model parameters
	for dv in ['t0', 'speed', 'lim1', 'lim2']:
		print'\nAnalyzing %s' % dv
		aConst = dm['%sConst' % dv]
		aOnset = dm['%sOnset' % dv]
		print 'Constant: M = %f, SE = %f' % (aConst.mean(), \
			aConst.std() / np.sqrt(N))
		print 'Onset: M = %f, SE = %f' % (aOnset.mean(), \
			aOnset.std() / np.sqrt(N))
		t, p = ttest_rel(aConst, aOnset)
		print 'Const vs onset, t = %.4f, p = %.4f' % (t, p)
Beispiel #9
0
def getDM(exp, driftCorr = True, excludeErrors = True, saccTooFast = None, saccTooSlow = None,\
		rtTooFast = None, rtTooSlow = None, rtVar = 'rtFromStim', \
		exclFailedChecks = True, \
		fixCheck1TooLong = 1000, fixCheck2TooLong = 1000, cutoffHeavy = 0, \
		onlyControl = True, excludeFillers = True):
	
	"""
	Applies several exclusion criteria to obtain a filtered dm.
	
	Arguments:
	dm					--- data matrix
	exp 				--- {"004A", "004B"}, string indicating whether first or second
							experiment is analysed
	
	Keyword arguments:
	excludeErrors		--- Boolean indicating whether error trials should be
							excluded. Default = False.
	saccTooFast			--- Cutoff for exclusion of too-fast saccades. Set to None
							to deactivate this filter. Default = 80.
	saccTooSlow 			--- Cutoff for exclusion of too-slow saccades. Set to None
							to deactivate this filter.
	rtTooFast			--- Cutoff for exclusion of too-fast RTs. Set to None to
							deactivate this filter.
	rtTooSlow			--- Cutoff for exclusion of too-slow RTs. Set to None to 
							deactivate this filter.
	rtVar				--- rt variable to use for excluding too fast and/or
							too slow response times.
	exclFailedChecks	--- Boolean indicating whether or not to excude trials on
							which one or more fix checks failed. Default = False
	fixCheckTooLong1	--- Cutoff for excluding too long fixation checks. Set
							to None to deactivate this filter. Default = 700, 
							based on looking at plt.hist(dm['durCheck1'])
	fixCheckTooLong2	--- Cutoff for excluding too long fixation check on 
							object. Set to None to deactivate. Default = 450,
							based on looking at plt.hist(dm['durCheck2'])
	drifCorr			--- 
	cutoffHeavy			--- minimum deviation necessary to indicate one side of the object
							as heavier. In px. Default = 8.
	onlyControl			--- indicates whether only trials in which manipulation was not 
							manipulated, should be included. Default = True.
	excludeFillers		--- Default = True.
	"""


	if driftCorr:
		fName = "selected_dm_%s_WITH_drift_corr.csv" % exp
	else:
		fName = "selected_dm_%s_NO_drift_corr.csv" % exp
	
	if exp == "004C":

		
		data = "./dm_004C_simulation.csv"
		
		a = np.genfromtxt(data, dtype=None, delimiter=",")
		dm = DataMatrix(a)
		
		# Add some important column headers:
		dm = dm.addField("file", dtype = str)
		dm = dm.addField("accuracy")
		dm = dm.addField("contrast_side", dtype = str)

		dm["file"] = "simulation"
		dm["accuracy"] = 1

		dm["contrast_side"] = "test"
		dm["contrast_side"][np.where(dm["mask_side"] == "right")] = "_left"
		dm["contrast_side"][np.where(dm["mask_side"] == "control")] = "control"
		dm["contrast_side"][np.where(dm["mask_side"] == "left")] = "right"
		
		
		
	else:

		dm = ascParser.parseAsc(exp = exp, driftCorr = driftCorr)
	
	# Start by applying some general selections (such that 
	# the reported exclusion percentages will not differ depending
	# on when you execute those):

	# Exclude practice trials:
	dm = dm.select("rep != 'practice'")
	
	# For the second experiment, exclude Dash and Sebastiaan:
	if exp == "004B":
	
		# Exclude Sebastiaan:
		dm = dm.select('file != "00401.asc"')
		# Exclude Dash because he's left handed:
		dm = dm.select('file != "00402.asc"')
	
	if onlyControl:
		dm = dm.select("mask_side == 'control'")
	
	if excludeFillers:
		dm = dm.select("symm == 'asymm'")

	if excludeErrors:
		dm = dm.select('accuracy == 1')
		
	# 'Real' selections:
	
	# During parsing, tirals on which the variable 'response' did not contain
	# an int were given the value -1. Otherwise the dm will make all the 
	# 'response' values strings. Therefore, start by excluding those eventual
	# -1's:
	dm = dm.select("response != -1")


	# Remove all trials on which saccLat1 doesn't have a value:
	dm = dm.select("saccLat1 != ''")

	# Negative initial saccade latencies should not happen:
	dm = dm.select('saccLat1 > 0.')

	# Add column header indicating whether drift correction was used:
	dm = dm.addField("driftCorr", dtype = str)
	dm["driftCorr"] = driftCorr
	
	# Add a column header indicating which experiment is analysed:
	dm = dm.addField("exp", dtype = str)
	dm["exp"] = exp
		
	# Add variable indicating whether CoG is to the left or to the
	# right:
	# For objects with handle right, and without mask applied: 
	# - negative xCoG means: heavier on the left
	# - pos means: heavier on the right
	dm = dm.addField('heavySide', dtype = str)
	dm["heavySide"] = 'control'
	dm["heavySide"][np.where(dm["xCoG"] >= cutoffHeavy)] = 'right__'
	dm["heavySide"][np.where(dm["xCoG"] <= -cutoffHeavy)] = 'left__'


	# Some stuff we can't do for the simulation, because those columns don't 
	# exist:
	if exp != "004C":
		# Add variable indicating experimental half (first or second):
		dm = dm.addField("half", dtype = str)
		dm["half"] = "first"
		dm["half"][np.where(dm["block_count"] >= 3)] = "second"
		
	if saccTooFast != None:
		dm = dm.select('saccLat1 > %s'%saccTooFast)
	
	if saccTooSlow != None:
		dm = dm.select('saccLat1 < %s'%saccTooSlow)

	if rtTooFast != None:
		dm = dm.select('%s > %s'%(rtVar,rtTooFast))
	
	if rtTooSlow != None:
		dm = dm.select('%s < %s'%(rtVar,rtTooSlow))
	
	# Filter on screen coordinates:
	# Y:
	if exp != "004C":
		dm = dm.select("endYRaw1 < %s" % constants.screenH)
		dm = dm.select("endYRaw1 > 0")
		# X:
		dm = dm.select("endXRaw1 < %s" % constants.screenW)
		dm = dm.select("endXRaw1 > 0")
		
		# Re-code initial y coordinates such that we can use one cutoff
		# for both upwards and downwards saccade to see whether they were in
		# the right direction (i.e. > center coordinate):
		dm = dm.addField("sacc_dir")
		dm["sacc_dir"] = dm["endYRaw1"]
		dm["sacc_dir"][dm.where("visual_field == 'upper'")] = \
			dm["endYRaw1"][dm.where("visual_field == 'upper'")]+\
			constants.yCen
			
		# Select saccades that were in the right vertical direction:
		dm.select("sacc_dir > %s" % str(constants.yCen))
	
	# Exclude trials on which a fixation check failed or took too long:
	if exp == "004A":
		
		if exclFailedChecks:
			# Note why those will probably never lead to exclusions anymore: 
			# in those cases durCheck1 or durCheck2 would have the value -1000 (because they 
			# couldnt be calculated) and therefore are already excluded above.
			dm = dm.select('checkFixDotFailed == "False"')
			dm = dm.select('checkObjectFailed == "False"')

		if fixCheck1TooLong != None:
			dm = dm.select('durCheck1 < %s' % fixCheck1TooLong)
		if fixCheck2TooLong != None:
			dm = dm.select('durCheck2 < %s' % fixCheck2TooLong)

	if exp != "004C":
		# Negative new RT's should not happen:
		dm = dm.select('rtFromStim > 0')

	dm.save(fName)
	
	return dm
def corr(dm):

	"""
	Plots the between-subjects correlation between IOR and facilitation in
	object-centered and retinotopic conditions.

	Arguments:
	dm		--	A DataMatrix.
	"""

	#dv = 'response_time'
	dv = 'iRt'
	dm = dm.select('correct == 1')

	l = [ ['ObjCue0', 'ObjCue1000', 'SpaCue0', 'SpaCue1000'] ]
	for _dm in dm.group('subject_nr'):

		_dm0 = _dm.select('postRotDelay == 0', verbose=False)
		_dm1000 = _dm.select('postRotDelay == 1000', verbose=False)

		Obj0Inv = _dm0.select('cond == "object-based"', verbose=False) \
			.select('valid == "{1}invalid"', verbose=False)[dv] \
			.mean()
		Obj0Val = _dm0.select('cond == "object-based"', verbose=False) \
			.select('valid == "{0}valid"', verbose=False)[dv] \
			.mean()
		Obj1000Inv = _dm1000.select('cond == "object-based"', verbose=False) \
			.select('valid == "{1}invalid"', verbose=False)[dv] \
			.mean()
		Obj1000Val = _dm1000.select('cond == "object-based"', verbose=False) \
			.select('valid == "{0}valid"', verbose=False)[dv] \
			.mean()
		Spa0Inv = _dm0.select('cond == "spatial"', verbose=False) \
			.select('valid == "{1}invalid"', verbose=False)[dv] \
			.mean()
		Spa0Val = _dm0.select('cond == "spatial"', verbose=False) \
			.select('valid == "{0}valid"', verbose=False)[dv] \
			.mean()
		Spa1000Inv = _dm1000.select('cond == "spatial"', verbose=False) \
			.select('valid == "{1}invalid"', verbose=False)[dv] \
			.mean()
		Spa1000Val = _dm1000.select('cond == "spatial"', verbose=False) \
			.select('valid == "{0}valid"', verbose=False)[dv] \
			.mean()

		if dv == 'iRt':
			Obj0Inv = 1./Obj0Inv
			Obj0Val = 1./Obj0Val
			Obj1000Inv = 1./Obj1000Inv
			Obj1000Val = 1./Obj1000Val
			Spa0Inv = 1./Spa0Inv
			Spa0Val = 1./Spa0Val
			Spa1000Inv = 1./Spa1000Inv
			Spa1000Val = 1./Spa1000Val

		ObjCue0 = Obj0Inv - Obj0Val
		ObjCue1000 = Obj1000Inv - Obj1000Val
		SpaCue0 = Spa0Inv - Spa0Val
		SpaCue1000 = Spa1000Inv - Spa1000Val

		l.append( [ObjCue0, ObjCue1000, SpaCue0, SpaCue1000] )
		print '%s\t%s\t%s\t%s' % (ObjCue0, ObjCue1000, SpaCue0, SpaCue1000)

	_dm = DataMatrix(l)
	_dm.save('output/corr.%s.csv' % dv)

	fig = plt.figure(figsize=(8,8))
	plt.subplots_adjust(wspace=.3, hspace=.3)

	plt.subplot(221)
	regressplot(_dm['ObjCue0'], _dm['SpaCue0'])
	plt.xlim(-200, 200)
	plt.ylim(-200, 200)
	plt.xlabel('Obj. cuing effect / short SOA (ms)')
	plt.ylabel('Ret. cuing effect / short SOA (ms)')

	plt.subplot(222)
	regressplot(_dm['ObjCue1000'], _dm['SpaCue1000'])
	plt.xlim(-200, 200)
	plt.ylim(-200, 200)
	plt.xlabel('Obj. cuing effect / long SOA (ms)')
	plt.ylabel('Ret. cuing effect / long SOA (ms)')

	plt.subplot(223)
	regressplot(_dm['ObjCue0'], _dm['ObjCue1000'])
	plt.xlim(-200, 200)
	plt.ylim(-200, 200)
	plt.xlabel('Obj. cuing effect / short SOA (ms)')
	plt.ylabel('Obj. cuing effect / long SOA (ms)')

	plt.subplot(224)
	regressplot(_dm['SpaCue0'], _dm['SpaCue1000'])
	plt.xlabel('Ret. cuing effect / short SOA (ms)')
	plt.ylabel('Ret. cuing effect / long SOA (ms)')
	plt.xlim(-200, 200)
	plt.ylim(-200, 200)

	plt.savefig('plot/corr.%s.png' % dv)
	plt.savefig('plot/corr.%s.svg' % dv)
	plt.show()
Beispiel #11
0
#!/usr/bin/env python
from saliency import simulateScanpath
from exparser.DataMatrix import DataMatrix
import os
from PIL import Image, ImageDraw

for frame in os.listdir('frames'):
	print frame
	im = Image.open('frames/' + frame)
	dr = ImageDraw.Draw(im)
	l = simulateScanpath(im)
	
	i = 1
	for p in l[1:]:
		t = p[0]
		x = p[1]
		y = p[2]
		dr.ellipse((x-5,y-5,x+5,y+5), outline='red')
		dr.text((x,y), '%d(%.0f)' % (i,t), fill='green')
		i += 1
	im.save('simulation/png/%s' % frame)	
	dm = DataMatrix(l)
	dm.save('simulation/csv/%s.csv' % frame[:-4])	
Beispiel #12
0
	if not os.path.exists(expPath):
		os.makedirs(expPath)
		
	figPath = os.path.join(expPath, "%s_%s.png" % (trialDm["file"][0], \
		str(trialDm["trialId"][0])))
	
	plt.savefig(figPath)
	#plt.show()
	
	plt.clf()
	pylab.close()
	#raw_input()
if __name__ == "__main__":
	
	f = ".cache/dm_sim_select_driftcorr.npy"
	dm = DataMatrix(np.load(f))
	dm = dm.select("gap == 'zero'")
	
	for i in dm.range():
		#if dm["stim_name"][i] != "hammer":
		#	continue
		#if dm["stim_type"][i] != "object":
		#	continue
		#if dm["mask_side"][i] != "control":
		#	continue

		# Save 1 in 40 trials:
		#if i % 100 != 99:
		#	continue
		
		trialDm = dm[i]
Beispiel #13
0
def latencyCorr(dm):

    """
	Determines the correlation between saccade latency and the latency of the
	PLR.

	Arguments:
	dm		--	DataMatrix
	"""

    dm = dm.addField("saccLat2Bin", dtype=float)
    dm = dm.calcPerc("saccLat2", "saccLat2Bin", keys=["subject_nr"], nBin=10)
    # dm = dm.select('cond == "onset"')
    l = [["subject_nr", "cond", "bin", "saccLat", "t0"]]
    colors = TangoPalette.brightColors[:] * 10
    for _dm in dm.group(["subject_nr", "saccLat2Bin"]):
        for cond in ("constant", "onset"):
            __dm = _dm.select("cond == '%s'" % cond, verbose=False)
            dmWhite = __dm.select('saccCol == "white"', verbose=False)
            xAvg, yAvg, errAvg = TraceKit.getTraceAvg(
                __dm,
                signal="pupil",
                phase="postSacc",
                traceLen=postTraceLen,
                baseline=baseline,
                baselineLock=baselineLock,
            )
            xWhite, yWhite, errWhite = TraceKit.getTraceAvg(
                dmWhite,
                signal="pupil",
                phase="postSacc",
                traceLen=postTraceLen,
                baseline=baseline,
                baselineLock=baselineLock,
            )
            yWhite -= yAvg
            opts = fitCurve(xWhite, yWhite, plot=False)
            t0 = opts[0]
            subject = __dm["subject_nr"][0]
            col = colors[int(subject)]
            saccLat = __dm["saccLat2"].mean()
            _bin = __dm["saccLat2Bin"][0]
            plt.plot(saccLat, t0, "o", color=col)
            l.append([subject, cond, _bin, saccLat, t0])
            print subject, t0, saccLat
    dm = DataMatrix(l)
    dm.save("output/%s/latencyCorr.csv" % exp)
    print dm
    # plt.plot(dm['saccLat'], dm['t0'], '.')
    s, i, r, p, se = linregress(dm["saccLat"], dm["t0"])
    print "r = %.4f, p = %.4f" % (r, p)
    plt.plot(dm["saccLat"], i + s * dm["saccLat"])
    plt.show()

    newFig(size=(4.8, 2.4))
    plt.subplots_adjust(bottom=0.2)
    pmX = PivotMatrix(dm, ["cond", "bin"], ["subject_nr"], "saccLat", colsWithin=True, err="se")
    print pmX

    pmY = PivotMatrix(dm, ["cond", "bin"], ["subject_nr"], "t0", colsWithin=True, err="se")
    print pmY

    xM = np.array(pmX.m[-2, 2:-2], dtype=float)
    xErr = np.array(pmX.m[-1, 2:-2], dtype=float)
    xMConst = xM[: len(xM) / 2]
    xMOnset = xM[len(xM) / 2 :]
    xErrConst = xErr[: len(xErr) / 2]
    xErrOnset = xErr[len(xErr) / 2 :]

    yM = np.array(pmY.m[-2, 2:-2], dtype=float)
    yErr = np.array(pmY.m[-1, 2:-2], dtype=float)
    yMConst = yM[: len(yM) / 2]
    yMOnset = yM[len(yM) / 2 :]
    yErrConst = yErr[: len(yErr) / 2]
    yErrOnset = yErr[len(yErr) / 2 :]

    plt.errorbar(
        xMConst, yMConst, xerr=xErrConst, yerr=yErrConst, label="Constant", capsize=0, color=constColor, fmt="o-"
    )
    plt.errorbar(xMOnset, yMOnset, xerr=xErrOnset, yerr=yErrOnset, label="Onset", capsize=0, color=onsetColor, fmt="o-")
    plt.legend(frameon=False)
    plt.xlabel("Saccade latency (ms)")
    plt.ylabel("PLR latency (ms)")
    saveFig("latencyCorr")

    aov = AnovaMatrix(dm, ["cond", "bin"], "t0", "subject_nr")
    print aov
    aov.save("output/%s/aov.latencyCorr.csv" % exp)
Beispiel #14
0
			mDev = gapDm['xNorm%s' % sacc].mean()
			d[stimType, sacc]= mDev
	
	return d

if __name__ == "__main__":
	
	dm = dmSim(cacheId = "dm_sim_raw")
	dm = addCommonFactors.addCommonFactors(dm, \
		cacheId = "dm_sim_common_factors")
	dm = addCoord.addCoord(dm, cacheId = "dm_sim_coord")
	#dm = addLat.addLat(dm, cacheId = "dm_sim_lat_driftcorr")
	dm = selectDm.selectDm(dm, cacheId = "dm_sim_select_driftcorr")
	
	f = ".cache/dm_sim_select_driftcorr.npy"
	dm = DataMatrix(np.load(f))
	
	fig = plt.figure()
	nPlot = 0
	for stimType in dm.unique("stim_type"):
		stimDm = dm.select("stim_type == '%s'" % stimType)
		
		for sacc in (1,2):
			nPlot +=1
			plt.subplot(2,2,nPlot)
			dv = "xNorm%s" % sacc
			plt.title("%s sacc %s" % (stimType, sacc))
			plt.hist(stimDm[dv], bins = 5)
	plt.savefig("Distribution_simulated_saccades.png")
			
Beispiel #15
0
def getDM(driftCorr, excludeErrors = False, saccTooFast = 80, saccTooSlow = None,\
		rtTooFast = None, rtTooSlow = None, rtVar = 'rtFromStim'):
	
	"""
	Applies several exclusion criteria to obtain a filtered dm.
	
	Arguments:
	dm		--- data matrix
	
	Keyword arguments:
	excludeErrors		--- Boolean indicating whether error trials should be
							excluded. Default = False.
	saccTooFast			--- Cutoff for exclusion of too-fast saccades. Set to None
							to deactivate this filter. Default = 80.
	saccTooSlow 			--- Cutoff for exclusion of too-slow saccades. Set to None
							to deactivate this filter.
	rtTooFast			--- Cutoff for exclusion of too-fast RTs. Set to None to
							deactivate this filter.
	rtTooSlow			--- Cutoff for exclusion of too-slow RTs. Set to None to 
							deactivate this filter.
	rtVar				--- rt variable to use for excluding too fast and/or
							too slow response times.
	drifCorr			--- 
	"""

	# Declare constants:
	#src = '/home/lotje/python-libs/studies/_004'

	if driftCorr:
		fName = "selected_dm_WITH_drift_corr.csv"
	else:
		fName = "selected_dm_NO_drift_corr.csv"
	
	if '--shortcut' in sys.argv:
		
		
		a = np.genfromtxt(fName, dtype=None, delimiter=",")
		dm = DataMatrix(a)
		
		#dm = CsvReader(fName, delimiter=',').dataMatrix()

		return dm
		
	dm = ascParser004B.parseAsc(driftCorr = driftCorr)
	
	# Exclude Sebastiaan:
	dm = dm.select('file != "00401.asc"')
	
	# Exclude Dash because he's left handed:
	dm = dm.select('file != "00402.asc"')
	
	
	# Add column header indicating whether drift correction was used:
	dm = dm.addField("driftCorr", dtype = str)
	dm["driftCorr"] = driftCorr
	
	# Make a new variable (instead of 'mask_side') that indicates the
	# highest contrast side:
	dm = dm.addField('contrast_side', dtype = str)
	dm['contrast_side'][np.where(dm['mask_side'] == "right")] = "_left"
	dm['contrast_side'][np.where(dm['mask_side'] == "left")] = "right"
	dm['contrast_side'][np.where(dm['mask_side'] == "control")] = "control"
	
	# Add variable indicating whether CoG is to the left or to the
	# right:
	# For objects with handle right, and without mask applied: 
	# - negative xCoG means: heavier on the left
	# - pos means: heavier on the right
	dm = dm.addField('heavySide', dtype = str)
	dm["heavySide"] = 'left'
	dm["heavySide"][np.where(dm["xCoG"] >= 0)] = 'right'

	# Add variable indicating experimental half (first or second):
	dm = dm.addField("half", dtype = str)
	dm["half"] = "first"
	dm["half"][np.where(dm["block_count"] >= 3)] = "second"

	# Exclude practice trials:
	dm = dm.select("rep != 'practice'")
	
	# During parsing, tirals on which the variable 'response' did not contain
	# an int were given the value -1. Otherwise the dm will make all the 
	# 'response' values strings. Therefore, start by excluding those eventual
	# -1's:
	dm = dm.select("response != -1")

	# Saccade latencies of 0 (or -1) should not happen:
	# If no saccade is detected during a trial, 'saccLat' is changed from -1000
	# to -1 during parsing:
	dm = dm.select('saccLat1 > 0')
	
	# Negative new RT's should not happen:
	dm = dm.select('rtFromStim > 0')
	
	# Add values indicating whether the eyes landed towards the handle (positive
	# values) or towards the other side of the object (negative values):
	# Also, make sure all values are eventually converted to visual degrees:
	
	# If first landing position is empty, skip the trial:
	dm = dm.select("endX1 != ''")
	
	# Without any correction:
	dm = dm.addField("pxTowardsHandle")
	dm = dm.addField("degrTowardsHandle")
	indicesRight = np.where(dm["handle_side"] == 'right')
	indicesLeft = np.where(dm["handle_side"] == 'left')
	dm["pxTowardsHandle"][indicesRight] = (dm["endX1"][indicesRight])
	dm["pxTowardsHandle"][indicesLeft] = dm["endX1"][indicesRight]*-1
	dm["degrTowardsHandle"] = dm["pxTowardsHandle"]/studies._004.constants.ratioPxDegr

	## With CoG correction based on the original bitmap (without mask):
	#dm = dm.addField("pxTowardsHandleCorr")
	#dm = dm.addField("degrTowardsHandleCorr")
	#indicesRight = np.where(dm["handle_side"] == 'right')
	#indicesLeft = np.where(dm["handle_side"] == 'left')
	#dm["pxTowardsHandleCorr"][indicesRight] = (dm["endXCorr"][indicesRight])
	#dm["pxTowardsHandleCorr"][indicesLeft] = dm["endXCorr"][indicesRight]*-1
	#dm["degrTowardsHandleCorr"] = dm["pxTowardsHandleCorr"]/constants.ratioPxDegr

	## Wit CoG correction with taking mask into account::
	#dm = dm.addField("pxTowardsHandleCorrMask")
	#dm = dm.addField("degrTowardsHandleCorrMask")
	#indicesRight = np.where(dm["handle_side"] == 'right')
	#indicesLeft = np.where(dm["handle_side"] == 'left')
	#dm["pxTowardsHandleCorrMask"][indicesRight] = \
		#(dm["endXCorrMask"][indicesRight])
	#dm["pxTowardsHandleCorrMask"][indicesLeft] = \
		#dm["endXCorrMask"][indicesRight]*-1
	#dm["degrTowardsHandleCorrMask"] = \
		#dm["pxTowardsHandleCorrMask"]/constants.ratioPxDegr

	# Convert landing positions to visual degrees:
	dm = dm.addField("endXDegr")
	#dm = dm.addField("endXCorrDegr")
	#dm = dm.addField("endXCorrMaskDegr")
	dm["endXDegr"] = dm["endX1"]/studies._004.constants.ratioPxDegr
	#dm["endXCorrDegr"] = dm["endXCorr"]/constants.ratioPxDegr
	#dm["endXCorrMaskDegr"] = dm["endXCorrMask"]/constants.ratioPxDegr

	# Convert starting position to visual degrees:
	dm = dm.addField("startX1Degr")
	dm["startX1Degr"] = dm["startX1"]/studies._004.constants.ratioPxDegr
	
	#dm = dm.addField("rtFromLanding")
	#dm['rtFromLanding'] = dm['rtFromStim']-dm['saccLandingTime1']
	
	if saccTooFast != None:
		dm = dm.select('saccLat1 > %s'%saccTooFast)
	if saccTooSlow != None:
		dm = dm.select('saccLat1 < %s'%saccTooSlow)

	if rtTooFast != None:
		dm = dm.select('%s > %s'%(rtVar,rtTooFast))
	
	if rtTooSlow != None:
		dm = dm.select('%s < %s'%(rtVar,rtTooSlow))
	
	
	if excludeErrors:
		dm = dm.select('accuracy == 1')
	
	dm.save(fName)
	
	return dm