def get_pupil_data(sub, run): """Get a preprocessed pupil trace for one subject and one avmovie run """ dm = io.readtxt(TRACE_SRC.format(sub=sub, run=run)) dm = ops.auto_type(dm) dm.pupil_size @= lambda i: np.nan if i == 0 else i dm.luminance @= lambda i: np.nan if i == 0 else i dm.pupil_size = srs._interpolate(ops.z(dm.pupil_size)) dm.luminance = srs._interpolate(ops.z(dm.luminance)) if REMOVE_LUMINANCE_FROM_PUPIL: i, s1, s2 = np.polyfit(dm.pupil_size, dm.luminance, deg=2) dm.pupil_size -= i + s1 * dm.luminance + s2 * dm.luminance ** 2 return deconv_hrf(flt(dm.pupil_size))
def test_z(): dm = DataMatrix(length=5) dm.a = range(-2, 3) dm.z = ops.z(dm.a) for x, y in zip(dm.z, [-1.26, -0.63, 0, .63, 1.26]): assert (abs(x - y) < .1)
def process_frame(run, frame, lm, cm): dm = DataMatrix(length=len(SUBJECTS)) dm.frame = frame dm.sub = IntColumn dm.x = FloatColumn dm.y = FloatColumn dm.pupil = FloatColumn dm.luminance = FloatColumn dm.change = FloatColumn print('Run {}, frame {}'.format(run, frame)) for row, sub in zip(dm, SUBJECTS): _dm = _get_subject_data(sub, run) _dm.pupil = ops.z(_dm.pupil) try: _row = (_dm.frame == frame)[0] except IndexError: continue row.sub = sub x = min(1279, max(0, _row.x)) y = min(546, max(0, _row.y)) if not x and not y: row.x = np.nan row.y = np.nan row.pupil = np.nan row.luminance = np.nan row.change = np.nan else: row.x = x row.y = y row.pupil = _row.pupil row.luminance = lm[int(y), int(x)] row.change = cm[int(y), int(x)] return dm
def test_z(): dm = DataMatrix(length=5) dm.a = range(-2,3) dm.z = ops.z(dm.a) for x, y in zip(dm.z, [-1.26, -0.63, 0, .63, 1.26]): assert(abs(x-y) < .1)
def test_z(): dm = DataMatrix(length=5) dm.a = range(-2, 3) dm.z = ops.z(dm.a) for test, ref in zip(dm.z, [-1.26, -0.63, 0, .63, 1.26]): assert (math.isclose(test, ref, abs_tol=.01)) # Add a non-numeric value, which should be ignored and its z value should # be NAN. dm.length = 6 dm.z = ops.z(dm.a) assert (dm.z[5] != dm.z[5]) for test, ref in zip(dm.z[:-1], [-1.26, -0.63, 0, .63, 1.26]): assert (math.isclose(test, ref, abs_tol=.01)) # If there is no variability, the z-scores should be NAN dm.a = 2 dm.z = ops.z(dm.a) assert (all(ref != ref for ref in dm.z))
def get_trace_data(sub, run, tracename): """A generic function to get a simple trace.""" dm = io.readtxt(TRACE_SRC.format(sub=sub, run=run)) dm = ops.auto_type(dm) dm[tracename] @= lambda i: np.nan if i == 0 else i dm[tracename] = srs._interpolate(ops.z(dm[tracename])) return deconv_hrf(flt(dm[tracename]))