def test_rt_chisq(): """Test reaction time chi-square fitting """ # 1D should return single float foo = np.random.rand(30) assert_raises(ValueError, ea.rt_chisq, foo - 1.) assert_equal(np.array(ea.rt_chisq(foo)).shape, ()) # 2D should return array with shape of input but without ``axis`` dimension foo = np.random.rand(30).reshape((2, 3, 5)) for axis in range(-1, foo.ndim): bar = ea.rt_chisq(foo, axis=axis) assert_true(np.all(np.equal(np.delete(foo.shape, axis), np.array(bar.shape))))
def test_rt_chisq(): """Test reaction time chi-square fitting.""" # 1D should return single float foo = np.random.RandomState(0).rand(30) pytest.raises(ValueError, ea.rt_chisq, foo - 1.) assert_equal(np.array(ea.rt_chisq(foo, warn=False)).shape, ()) # 2D should return array with shape of input but without ``axis`` dimension foo = np.random.rand(30).reshape((2, 3, 5)) for axis in range(-1, foo.ndim): bar = ea.rt_chisq(foo, axis=axis, warn=False) assert_array_equal(np.delete(foo.shape, axis), np.array(bar.shape)) foo_bad = np.concatenate((np.random.rand(30), [100.])) with pytest.warns(UserWarning, match='likely bad'): bar = ea.rt_chisq(foo_bad)
def test_rt_chisq(): """Test reaction time chi-square fitting.""" # 1D should return single float foo = np.random.rand(30) assert_raises(ValueError, ea.rt_chisq, foo - 1.) assert_equal(np.array(ea.rt_chisq(foo)).shape, ()) # 2D should return array with shape of input but without ``axis`` dimension foo = np.random.rand(30).reshape((2, 3, 5)) for axis in range(-1, foo.ndim): bar = ea.rt_chisq(foo, axis=axis) assert_true( np.all(np.equal(np.delete(foo.shape, axis), np.array(bar.shape)))) foo_bad = np.concatenate((np.random.rand(30), [100.])) with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') bar = ea.rt_chisq(foo_bad) assert_equal(len(w), 1) # warn that there was a likely bad value
def test_rt_chisq(): """Test reaction time chi-square fitting.""" # 1D should return single float foo = np.random.rand(30) assert_raises(ValueError, ea.rt_chisq, foo - 1.) assert_equal(np.array(ea.rt_chisq(foo)).shape, ()) # 2D should return array with shape of input but without ``axis`` dimension foo = np.random.rand(30).reshape((2, 3, 5)) for axis in range(-1, foo.ndim): bar = ea.rt_chisq(foo, axis=axis) assert_true(np.all(np.equal(np.delete(foo.shape, axis), np.array(bar.shape)))) foo_bad = np.concatenate((np.random.rand(30), [100.])) with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') bar = ea.rt_chisq(foo_bad) assert_equal(len(w), 1) # warn that there was a likely bad value
def chsq_rt(x): # peak of chi squared distribution fit to data y = np.array(x) y = y[np.logical_not(np.isnan(y))] if y.size == 0: return np.nan else: return efa.rt_chisq(y)
# corrects = list() raw_rt = list() for d in exp_data: assert 'TONE_' in d['trial_id'][0][0] # prevent stupidity # code hits 0, false alarms 1, misses 2, correct rejections 3 ti = ((d['trial_id'][0][0] == 'TONE_0') * 2 + (len(d['keypress']) == 0)) corrects.append(True if ti in [0, 3] else False) raw_rt.extend([float(d['keypress'][-1][1]) - float(d['flip'][0][0])] if ti == 0 else []) hmfx[si, ti] += 1 raw_rt = np.array(raw_rt) raw_rt = raw_rt[raw_rt < 5.0] # cut off due to trial_ok not being recorded assert len(raw_rt) > 20 avg_rt[si] = rt_chisq(raw_rt) hitrate = hmfx[si, 0] / float(np.sum(hmfx[si, :2])) farate = hmfx[si, 2] / float(np.sum(hmfx[si, 2:])) print(' RT/HR/FAR: %s, %s, %s' % (avg_rt[si], hitrate, farate)) assert np.sum(corrects) == np.sum(hmfx[si, [0, 3]]) assert hmfx[si].sum() == 300 # # read in pupillometry data for PRF # fnames = glob.glob(op.join(work_dir, 'data', subj + '_2014*', '*.edf')) fnames.sort() assert len(fnames) == 5 # screen luminance and 4x beeps raws = list() events = list() for fname in fnames[1:]: raw = pyeparse.RawEDF(fname)
# corrects = list() raw_rt = list() for d in exp_data: assert 'TONE_' in d['trial_id'][0][0] # prevent stupidity # code hits 0, false alarms 1, misses 2, correct rejections 3 ti = ((d['trial_id'][0][0] == 'TONE_0') * 2 + (len(d['keypress']) == 0)) corrects.append(True if ti in [0, 3] else False) raw_rt.extend([float(d['keypress'][-1][1]) - float(d['flip'][0][0]) ] if ti == 0 else []) hmfx[si, ti] += 1 raw_rt = np.array(raw_rt) raw_rt = raw_rt[raw_rt < 5.0] # cut off due to trial_ok not being recorded assert len(raw_rt) > 20 avg_rt[si] = rt_chisq(raw_rt) hitrate = hmfx[si, 0] / float(np.sum(hmfx[si, :2])) farate = hmfx[si, 2] / float(np.sum(hmfx[si, 2:])) print(' RT/HR/FAR: %s, %s, %s' % (avg_rt[si], hitrate, farate)) assert np.sum(corrects) == np.sum(hmfx[si, [0, 3]]) assert hmfx[si].sum() == 300 # # read in pupillometry data for PRF # fnames = glob.glob(op.join(work_dir, 'data', subj + '_2014*', '*.edf')) fnames.sort() assert len(fnames) == 5 # screen luminance and 4x beeps raws = list() events = list() for fname in fnames[1:]: raw = pyeparse.RawEDF(fname)