def checkMissing(dm, checkCue=True, checkPostSacc=True): """ Checks whether there is missing data in the pupil traces, and filters trials with missing data out. Arguments: dm -- DataMatrix Keyword arguments: checkCue -- Indicates whether the cue phase should be checked. (default=True) checkPostSacc -- Indicates whether the postSacc phase should be checked. (default=True) Returns: The filtered DataMatrix. """ dm = dm.addField("missing", dtype=int, default=0) count = 0 for i in dm.range(): missing = False if checkCue: a = TraceKit.getTrace( dm[i], signal="pupil", phase="cue", lock="end", baseline=baseline, baselineLock=baselineLock, traceLen=preTraceLen, nanPad=False, ) if np.isnan(a.sum()): missing = True if checkPostSacc: a = TraceKit.getTrace( dm[i], signal="pupil", phase="postSacc", lock="start", baseline=baseline, baselineLock=baselineLock, traceLen=postTraceLen, nanPad=False, ) if np.isnan(a.sum()): missing = True if missing: dm["missing"][i] = 1 count += 1 print "Found %d (of %d) trials with missing data" % (count, len(dm)) dm = dm.select("missing == 0") return dm
def addFixStabInfo(dm, offset): print "Determining fixation stability ..." dm = dm.addField("fixStabX", dtype=float) for i in dm.range(): a = TraceKit.getTrace( dm[i], signal="x", phase="postSacc", lock="start", offset=offset, traceLen=postTraceLen - offset, nanPad=False, ) print "%.4d\tM = %.2f, SD = %.2f" % (i, a.mean(), np.std(a)) dm["fixStabX"][i] = np.std(a) print "Done" return dm
def matchBias(dm): """ Matches trials based on a bias towards the saccade target side. Arguments: dm -- DataMatrix Returns: A matched DataMatrix. """ dm = dm.addField("gazeBias", dtype=float) print "Adding gaze-bias information ..." for i in dm.range(): a = TraceKit.getTrace(dm[i], signal="x", phase="cue", traceLen=preTraceLen, lock="end", nanPad=False) saccSide = dm["saccSide"][i] _a = a[:-50] bias = (_a - 512).mean() if saccSide == "left": bias *= -1 dm["gazeBias"][i] = bias print "All: M = %.4f, SD = %.4f" % (dm["gazeBias"].mean(), dm["gazeBias"].std()) newFig() plt.subplot(2, 1, 1) plt.title("Unbalanced: M = %.4f, SD = %.4f" % (dm["gazeBias"].mean(), dm["gazeBias"].std())) plt.hist(dm["gazeBias"], bins=50, color=blue[1]) plt.axvline(dm["gazeBias"].mean()) # dm = dm.select('gazeBias < 0') dm = dm.balance("gazeBias", 0.1, verbose=True) # newDm = None # for _dm in dm.group('subject_nr'): # print 'Balancing subject_nr %d' % _dm['subject_nr'][0] # if newDm == None: # newDm = _dm.balance('gazeBias', 1) # else: # newDm += _dm.balance('gazeBias', 1) # dm = newDm dm = dm.select("__unbalanced__ == 0") plt.subplot(2, 1, 2) plt.title("Balanced: M = %.4f, SD = %.4f" % (dm["gazeBias"].mean(), dm["gazeBias"].std())) plt.hist(dm["gazeBias"], bins=50, color=blue[1]) plt.axvline(dm["gazeBias"].mean()) print "Antibias: M = %.4f, SD = %.4f" % (dm["gazeBias"].mean(), dm["gazeBias"].std()) saveFig("gazeBias") return dm