def analyzesubj(subjname, condrules, dv='rt'): if dv == 'rt': tmpexcconds = behavrtexcconds elif dv == 'acc': tmpexcconds = behavaccexcconds else: print 'Invalid DV: %s' % (dv) return trials = [] sess = readall(subjname) for run in sess: mspec.cleanFld(run, tmpexcconds) mspec.cleanRT(run, condrules, sdtrim) trials.extend(run) inctrials = [t for t in trials if 'include' not in t or t['include']] res = {} for cond in condrules: condtrials = [t for t in inctrials if condrules[cond](t)] if dv == 'rt': res[cond] = mean([t['rt'] for t in condtrials if t['rt']]) elif dv == 'acc': res[cond] = len([t for t in condtrials if t['acc'] == 'hit']) / float(len(condtrials)) return res
def batch(): subjs = [x for x in os.listdir(behavdir) if re.search('^\d{6}\w{2}$', x)] subjs = sorted(subjs) expt = {} for subj in subjs: print 'Working on subject %s...' % (subj) sess = readall(subj) for run in sess: mspec.cleanFld(run, excconds) mspec.cleanRT(run, condrules, sdtrim) specname = '%s/model_%s.m' % (specdir, subj) mspec.writespec(specname, sess, \ condnames, condrules, params=params, modelExc=True) # With polynomial expansion specname = '%s/model_poly_%s.m' % (specdir, subj) mspec.writespec(specname, sess, \ condnames, condrules, params=params_poly, modelExc=True) # specname = '%s/model_fir_%s.m' % (specdir, subj) mspec.writespec(specname, sess, \ condnames, condrules, params=params, modelExc=True, offset=-8*1.25) expt[subj] = sess
def writebehav(): subjs = [x for x in os.listdir(behavdir) if re.search('^\d{6}\w{2}$', x)] subjs = sorted(subjs) expt = {} out = open('%s/behav.m' % (scriptdir), 'w') for subj in subjs: print 'Working on subject %s...' % (subj) sess = readall(subj) for run in sess: run = mspec.addadj(run, 'iti', -1) print run[0].keys() acctrials = [] rttrials = [] for run in sess: accrun = copy.deepcopy(run) mspec.cleanFld(accrun, accexcconds) mspec.cleanRT(accrun, condrules, sdtrim) acctrials.extend(accrun) rtrun = copy.deepcopy(run) mspec.cleanFld(rtrun, rtexcconds) mspec.cleanRT(rtrun, condrules, sdtrim) rttrials.extend(rtrun) for cond in bcondrules: ccond = cond.replace('-', '') acccondtrials = [t for t in acctrials \ if bcondrules[cond](t) and t['include']] meanacc = len([t for t in acccondtrials \ if t['acc'] == 'hit']) / float(len(acccondtrials)) out.write('acc.%s.s%s = %f;\n' % \ (ccond, subj, meanacc)) rtcondtrials = [t for t in rttrials \ if bcondrules[cond](t) and t['include']] meanrt = sum([t['rt'] for t in rtcondtrials]) \ / float(len(rtcondtrials)) out.write('rt.%s.s%s = %f;\n' % \ (ccond, subj, meanrt)) out.close()
def checkomit(): # subjs = [x for x in os.listdir(behavdir) if re.search('^\d{6}\w{2}$', x)] subjs = sorted(subjs) for subj in subjs: sess = readall(subj) for run in sess: mspec.cleanFld(run, behavaccexcconds) mspec.cleanRT(run, condrules, sdtrim) omittrials = [t for t in run if t['task'] == 'simple' and t['acc'] == 'miss'] if omittrials: print len(omittrials)