Esempio n. 1
0
    def staircase(self):
        df = self._get_staircase()
        agg_thres = stats.aggregate(df,
                                    values='thres',
                                    rows='session',
                                    unstack=True)
        agg = stats.aggregate(df,
                              values='oridiff',
                              subplots='session',
                              rows='trialno',
                              cols='pos')
        if self.rp['plot'] or self.rp['saveplot']:
            plt = plot.Plot(nrows=2, ncols=2, sharex=True, sharey=True)
            ax = plt.plot(agg, kind='line', ylabel='step')
            num_trials = len(agg.columns.levels[1])

            for pno, (sno, thres) in enumerate(agg_thres.mean().iteritems()):
                #import pdb; pdb.set_trace()
                ax = plt.get_ax(pno)
                ax.set_title('session %d' % sno)
                ax.axhline(y=thres, color='.2', ls='--', lw=2, marker='None')
                print thres
                ax.text(num_trials - 15,
                        thres + .5,
                        'average threshold = %.2f' % thres,
                        fontsize=8)

            print agg_thres
            plt.hide_plots(3)
            if self.rp['plot']: plt.show()
            if self.rp['saveplot']:
                plt.savefig(PATHS['analysis'] + '%s.svg' % self.info['subjid'])

        return agg_thres
Esempio n. 2
0
 def run(self):
     df = self._get_staircase()
     agg_thres = stats.aggregate(df, values='thres', rows='pos', unstack=True)
     agg = stats.aggregate(df, values='oridiff', rows='trialno', cols='pos')
     plt = plot.Plot()
     ax = plt.plot(agg, kind='line', ylabel='step')
     num_trials = len(agg.columns.levels[1])
     thres = agg_thres.mean(1).values[0]
     ax.axhline(y=thres, color = '.2', ls='--', lw=2, marker = 'None')
     print agg_thres
     ax.text(num_trials - num_trials/3., thres+.5,
         'average threshold = %.2f' % thres, fontsize=8)
     plt.show()
     return agg_thres
Esempio n. 3
0
 def get_agg(self, df, kind=None):
     if kind == 'matrix':
         agg = stats.aggregate(df, values='subj_resp', yerr='subjid',
                               subplots='roi', rows='stim1.cond',
                               cols='stim2.cond')
     elif self.rp['method'] in ['corr', 'svm']:
         df['same_diff'] = 'between'
         df['same_diff'][df['stim1.cond'] == df['stim2.cond']] = 'within'
         agg = stats.aggregate(df, values='subj_resp', yerr='subjid',
                               rows='roi', cols='same_diff')
     else:
         agg = stats.aggregate(df, values='subj_resp', yerr='subjid',
                               rows='roi', cols='cond')
     return agg
Esempio n. 4
0
    def run(self):
        pattern = PATHS['data'] + '%s.csv'
        df = self.exp.get_behav_df(pattern=pattern)
        agg_acc = stats.accuracy(df,
                                 cols='context',
                                 values='accuracy',
                                 yerr='subjid',
                                 order='sorted')
        agg_rt = stats.aggregate(df[df.accuracy == 'correct'],
                                 cols='context',
                                 values='rt',
                                 yerr='subjid',
                                 order='sorted')

        plt = plot.Plot(ncols=2)
        if len(df.subjid.unique()) == 1:
            kind = 'bar'
        else:
            kind = 'bean'
        plt.plot(agg_acc, kind=kind, title='accuracy', ylabel='% correct')
        plt.plot(agg_rt, kind=kind, title='response time', ylabel='seconds')

        print agg_acc
        print agg_rt
        plt.show()
Esempio n. 5
0
    def behav(self):
        pattern = PATHS['data'] + '%s.csv'
        df = self.exp.get_behav_df(pattern=pattern)
        agg_acc = stats.aggregate(df, cols='context', values='accuracy',
                                  value_filter='Correct', yerr='subjID')
        agg_rt = stats.aggregate(df[df.accuracy=='Correct'], cols='context',
                                 values='rt', yerr='subjID')

        if self.runParams['plot'] or self.runParams['saveplot']:
            plt = plot.Plot(ncols=2)
            plt.plot(agg_acc, kind='bar')
            plt.plot(agg_rt, kind='bar')

            if self.runParams['plot']: plt.show()
            if self.runParams['saveplot']:
                plt.savefig(PATHS['analysis'] + 'behav.svg')
Esempio n. 6
0
    def thresholds(self):
        df = self._get_staircase()
        agg_thres = stats.aggregate(df, values='thres', cols='pos',
                                    yerr='subjid')
        plt = plot.Plot()
        plt.plot(agg_thres, kind='bar', title='orientation thresholds',
                 ylabel='orientation threshold, deg')
        print agg_thres.mean()
        plt.show()

        return agg_thres
Esempio n. 7
0
    def run(self):
        pattern = PATHS['data'] + '%s.csv'
        df = self.exp.get_behav_df(pattern=pattern)
        agg_acc = stats.accuracy(df, cols='context', values='accuracy',
                                 yerr='subjid', order='sorted')
        agg_rt = stats.aggregate(df[df.accuracy=='correct'], cols='context',
                                 values='rt', yerr='subjid', order='sorted')

        plt = plot.Plot(ncols=2)
        if len(df.subjid.unique()) == 1:
            kind = 'bar'
        else:
            kind = 'bean'
        plt.plot(agg_acc, kind=kind, title='accuracy', ylabel='% correct')
        plt.plot(agg_rt, kind=kind, title='response time', ylabel='seconds')

        print agg_acc
        print agg_rt
        plt.show()
Esempio n. 8
0
nsampl = 10
k = n*nsampl
df = stats.df_fromdict(
    [('subplots', ['session1', 'session2']),
     ('cond', [1, 2]),
     ('name', ['condition one', 'condition two']),
     ('levels', ['small', 'medium', 'large']),
     ('subjID', ['subj%d' % (i+1) for i in range(n)])],
     repeat=nsampl
    )
df['rt'] = 0.5
df.rt[df.cond==1] = np.random.random(12*k) * 1.2
df.rt[df.cond==2] = np.random.random(12*k)
#df['accuracy'] = ['correct','correct','incorrect','incorrect']*k*9

agg = stats.aggregate(df, subplots='subplots', rows='levels',
            cols='cond', yerr='subjID', values='rt')
plt1 = plot.Plot(figsize=(6,3))
plt1.plot(agg, kind='bar')
plt1.tight_layout()

plt2 = plot.Plot(figsize=(6,3))
plt2.plot(agg, kind='line')
plt2.tight_layout()

plt3 = plot.Plot(figsize=(8,4))
plt3.plot(agg, kind='bean')
plt3.tight_layout()

agg = stats.aggregate(df, subplots='subplots', rows='subjID',
            cols='name', values='rt')
plt4 = plot.Plot(figsize=(6,3))
Esempio n. 9
0
nsampl = 10
k = n * nsampl
df = stats.df_fromdict([('subplots', ['session1', 'session2']),
                        ('cond', [1, 2]),
                        ('name', ['condition one', 'condition two']),
                        ('levels', ['small', 'medium', 'large']),
                        ('subjID', ['subj%d' % (i + 1) for i in range(n)])],
                       repeat=nsampl)
df['rt'] = 0.5
df.rt[df.cond == 1] = np.random.random(12 * k) * 1.2
df.rt[df.cond == 2] = np.random.random(12 * k)
#df['accuracy'] = ['correct','correct','incorrect','incorrect']*k*9

agg = stats.aggregate(df,
                      subplots='subplots',
                      rows='levels',
                      cols='cond',
                      yerr='subjID',
                      values='rt')
plt1 = plot.Plot(figsize=(6, 3))
plt1.plot(agg, kind='bar')
plt1.tight_layout()

plt2 = plot.Plot(figsize=(6, 3))
plt2.plot(agg, kind='line')
plt2.tight_layout()

plt3 = plot.Plot(figsize=(8, 4))
plt3.plot(agg, kind='bean')
plt3.tight_layout()

agg = stats.aggregate(df,