def preprocess(dm): """ desc: Performs pupil preprocessing, and removes trials where pupil size was unrealistic. """ dm.pupil = series.blinkreconstruct(dm.ptrace_target) dm.pupil.depth = 3000 dm.pupil = series.smooth(dm.pupil, winlen=51) dm.pupil = series.baseline(dm.pupil, dm.pupil, 0, 1) # Remove all trials where pupil size has unrealistic values dm.pupilmax = FloatColumn dm.pupilmin = FloatColumn for row in dm: row.pupilmin = min(row.pupil) row.pupilmax = max(row.pupil) plot.new() # plot.histogram(dm.pupilmin, bins=100, range=(0, 5), color=red[1], alpha=.5) # plot.histogram(dm.pupilmax, bins=100, range=(0, 5), color=green[1], alpha=.5) plt.hist(dm.pupilmin, bins=100, range=(0, 5), color=red[1], alpha=0.5) plt.hist(dm.pupilmax, bins=100, range=(0, 5), color=green[1], alpha=0.5) l0 = len(dm) dm = (dm.pupilmin > PUPILRANGE[0]) & (dm.pupilmax < PUPILRANGE[1]) l1 = len(dm) s = "%d of %d unrealistic values" % (l0 - l1, l0) plt.title(s) plot.save("pupil-peaks") print(s) return dm
def test_smooth(): dm = DataMatrix(length=2) dm.series = SeriesColumn(depth=6) dm.series[0] = range(6) dm.series[1] = [0, 1, 2] * 2 dm.s = series.smooth(dm.series, winlen=3, wintype='flat') check_series( dm.s, [[2. / 3, 1, 2, 3, 4, 4 + 1. / 3], [2. / 3, 1, 1, 1, 1, 1 + 1. / 3]]) check_integrity(dm)
def preprocess(dm): """ desc: Do basic data preprocessing. arguments: dm: type: DataMatrix returns: type: DataMatrix """ dm.pupil.depth = 540 dm.pupil = series.baseline(dm.pupil, baseline=dm.pupil, bl_start=50, bl_end=90) dm.pupil = series.smooth(dm.pupil, winlen=11) dm.rename('snelheid', 'velocity') dm.log_velocity = np.log10(dm.velocity) return dm