Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
def rthist_subj(subjname):
  
  runs = readall(subjname)
  trials = reduce(lambda x, y: x + y, runs, [])

  mspec.cleanFld(trials, behavrtexcconds)
  inctrials = [t for t in trials if t['include']]

  all_rts = array([t['rt'] for t in inctrials])
  mean_rt = all_rts.mean()
  std_rt = all_rts.std()

  for t in inctrials:
    t['zrt'] = (t['rt'] - mean_rt) / std_rt

  rts = {}
  for cond in condrules:
    rts[cond] = [t['zrt'] for t in inctrials if condrules[cond](t)]

  return rts