示例#1
0
def main(ps,
         nbins,
         nboots,
         ignore_dur,
         doPlotPmf,
         doPlotElb,
         outdir,
         isLongDur,
         nElbows,
         enforceZeroSlope,
         resample=None,
         ignoreElbs=False):
    firstElbow = (136.0, 171.0) if ignoreElbs else False
    secondElbow = (
        983.0, 1267.0
    ) if ignoreElbs else False  # ignores data past these times in (2d, 3d)
    df = load(ps, None, 'both' if isLongDur else False, nbins, secondElbow,
              firstElbow)
    if resample:
        df = resample_by_grp(df, resample)
    durmap = make_durmap(df)
    rows1, rows2 = [], []
    for dotmode, df_dotmode in df.groupby('dotmode'):
        if ignore_dur:
            r1, r2 = make_rows(df_dotmode, dotmode, durmap, 0, nboots)
            rows1.extend(r1)
            rows2.extend(r2)
        else:
            for di, df_durind in df_dotmode.groupby('duration_index'):
                r1, r2 = make_rows(df_durind, dotmode, durmap, di, nboots)
                rows1.extend(r1)
                rows2.extend(r2)

    df_pts = pd.DataFrame(
        rows1, columns=['subj', 'dotmode', 'di', 'dur', 'x', 'y', 'ntrials'])
    df_fts = pd.DataFrame(rows2,
                          columns=[
                              'subj', 'dotmode', 'di', 'dur', 'bi', 'thresh',
                              'loc', 'scale', 'lapse'
                          ])
    df_fts['dur'] = 1000 * df_fts['dur']
    df_fts['sens'] = 1 / df_fts['thresh']

    if not ignore_dur and nElbows >= 0:
        df_elbs = find_elbows_per_boots(df_fts, nElbows, enforceZeroSlope)
    else:
        df_elbs = pd.DataFrame()
    if doPlotPmf:
        plot_logistics(df_pts, df_fts)
    if doPlotElb and not ignore_dur:
        plot_threshes(df_fts, df_elbs)
    if outdir is not None:
        subj = ps['subj'] if ps['subj'] is not None else 'ALL'
        df_pts['subj'] = subj
        df_fts['subj'] = subj
        df_elbs['subj'] = subj
        to_csv(nbins, nboots, subj, df_pts, df_fts, df_elbs, outdir,
               ignore_dur)
示例#2
0
def load(min_dur=0.3, max_dur=1.2, min_coh=0.03, max_coh=0.5):
    fltrs = [
        pd_io.make_gt_filter('real_duration', min_dur),
        pd_io.make_lt_filter('real_duration', max_dur)
    ]
    fltrs.extend([
        pd_io.make_gt_filter('coherence', min_coh),
        pd_io.make_lt_filter('coherence', max_coh)
    ])
    return pd_io.load(None, fltrs, 'both')
def plot(args, isLongDur=False):
    df = load(args, None, isLongDur)
    subj = subj_label(df, '')
    for dotmode, df_dotmode in df.groupby('dotmode'):
        fig = plt.figure()
        ax = plt.subplot(111)
        title = '{0}, {1}'.format(dotmode, subj)
        plot_inner(ax, df_dotmode)
        plot_info(ax, title)
        plt.show()
def plot(args, isLongDur=False):
    df = load(args, None, isLongDur)
    subj = subj_label(df, '')
    for dotmode, df_dotmode in df.groupby('dotmode'):
        fig = plt.figure()
        ax = plt.subplot(111)
        title = '{0}, {1}'.format(dotmode, subj)
        plot_inner(ax, df_dotmode)
        plot_info(ax, title)
        plt.show()
示例#5
0
def main(isLongDur=True, nbins=20, resample=5, nboots=1000, doPlot=False):
    df0 = load({}, None, 'both' if isLongDur else False, nbins)
    xss = np.zeros([nboots, nbins])
    yss = np.zeros([nboots, nbins])
    for i in xrange(nboots):
        if resample:
            df = resample_by_grp(df0, resample)
        vals = regress(df, doPlot)
        xs = np.array(vals['2d'])[:,1]
        ys = np.array(vals['3d'])[:,1]
        xss[i, :] = xs
        yss[i, :] = ys
    durinds_to_ignore_2d, ubs_2d = check_different(xss)
    durinds_to_ignore_3d, ubs_3d = check_different(yss)
    print ('2d', zip(durinds_to_ignore_2d, ubs_2d)), ('3d', zip(durinds_to_ignore_3d, ubs_3d))
def fit(args, outdir, nboots, collapseCoh=False, isLongDur=False, resample=None, plot=False):
    df = load(args, None, 'both' if isLongDur else False)
    if resample:
        df = resample_by_grp(df, resample)
    dur_rng = (min_dur, max_dur_longDur) if isLongDur else (min_dur, max_dur)
    subj = subj_label(df)
    durmap = durmap_fcn(df)
    res = {}
    for grp, df_dotmode in df.groupby('dotmode' if collapseCoh else ['dotmode', 'coherence']):
        key = grp if not collapseCoh else (grp, None)
        res = fit_df(df_dotmode, nboots, res, key, dur_rng, durmap)
    df1, df2 = finish_res(res, subj)
    if outdir:
        write_csv(df1, df2, subj, collapseCoh, outdir)
    if plot:
        plot_fit(df1, df2, collapseCoh)
示例#7
0
def main(isLongDur=True, nbins=20, resample=5, nboots=1000, doPlot=False):
    df0 = load({}, None, 'both' if isLongDur else False, nbins)
    xss = np.zeros([nboots, nbins])
    yss = np.zeros([nboots, nbins])
    for i in xrange(nboots):
        if resample:
            df = resample_by_grp(df0, resample)
        vals = regress(df, doPlot)
        xs = np.array(vals['2d'])[:, 1]
        ys = np.array(vals['3d'])[:, 1]
        xss[i, :] = xs
        yss[i, :] = ys
    durinds_to_ignore_2d, ubs_2d = check_different(xss)
    durinds_to_ignore_3d, ubs_3d = check_different(yss)
    print('2d', zip(durinds_to_ignore_2d,
                    ubs_2d)), ('3d', zip(durinds_to_ignore_3d, ubs_3d))
示例#8
0
def main(args, outdir):
    if outdir:
        CURDIR = os.path.dirname(os.path.abspath(__file__))
        BASEDIR = os.path.abspath(os.path.join(CURDIR, '..'))
        OUTDIR = os.path.join(BASEDIR, 'res', 'sequential-effects', outdir)
        outfile = os.path.join(OUTDIR, '{0}-{1}.png'.format(subj, '_'.join(conds)))
    else:
        outfile = None

    df = load(args)
    ds = parse(df)
    print 'Loaded'
    res = calculate(ds)
    print 'Calculated'
    subjs = df['subj'].unique()
    plot(res, subjs[0] if len(subjs) == 1 else 'ALL', outfile)
示例#9
0
def main():
    def summary(df, key=['subj', 'dotmode', 'isLongDur']):
        rows = []
        for k, dg in df.groupby(key, as_index=False):
            tm = dg['session_index']
            nts = []
            for k1, dh in dg.groupby('session_index'):
                nts.append(len(set(dh['trial_index'])))
            v = '{0} - {1}'.format(
                min(nts), max(nts)) if min(nts) != max(nts) else str(min(nts))
            row = list(k) + [len(set(tm.values)), len(tm), v]
            rows.append(row)
        return pd.DataFrame(rows,
                            columns=key +
                            ['# sessions', '# trials', '# trials/session'])

    # data actually collected
    df1 = load_df()
    df1['isLongDur'] = False
    dfA = summary(df1)
    df2 = load_df(SESSIONS_INFILE_2, TRIALS_INFILE_2)
    df2['isLongDur'] = True
    dft = summary(df2)
    dfA = dfA.append(dft)

    # data used in analysis
    df3 = load({}, None, 'both')
    dfB = summary(df3)

    # combine
    key = ['isLongDur', 'subj', 'dotmode']
    dfA = dfA.sort(key).reset_index()
    dfB = dfB.sort(key).reset_index()
    dfA['# trials analyzed'] = dfB['# trials']
    dfA['# trials/session analyzed'] = dfB['# trials/session']
    keys = [
        "# sessions", "# trials", "# trials analyzed", "# trials/session",
        "# trials/session analyzed"
    ]
    print dfA.set_index(key)[keys].to_csv()
    print dfA.groupby('isLongDur')[keys].sum()
    print dfA.groupby('dotmode')[keys].sum()

    print resample_by_grp(df3)
示例#10
0
def main():
    def summary(df, key=['subj', 'dotmode', 'isLongDur']):
        rows = []  
        for k, dg in df.groupby(key, as_index=False):
            tm = dg['session_index']
            nts = []
            for k1, dh in dg.groupby('session_index'):
                nts.append(len(set(dh['trial_index'])))
            v = '{0} - {1}'.format(min(nts), max(nts)) if min(nts) != max(nts) else str(min(nts))
            row = list(k) + [len(set(tm.values)), len(tm), v]
            rows.append(row)
        return pd.DataFrame(rows, columns=key + ['# sessions', '# trials', '# trials/session'])

    # data actually collected
    df1 = load_df()
    df1['isLongDur'] = False
    dfA = summary(df1)
    df2 = load_df(SESSIONS_INFILE_2, TRIALS_INFILE_2)
    df2['isLongDur'] = True
    dft = summary(df2)
    dfA = dfA.append(dft)

    # data used in analysis
    df3 = load({}, None, 'both')
    dfB = summary(df3)

    # combine
    key = ['isLongDur', 'subj', 'dotmode']
    dfA = dfA.sort(key).reset_index()
    dfB = dfB.sort(key).reset_index()
    dfA['# trials analyzed'] = dfB['# trials']
    dfA['# trials/session analyzed'] = dfB['# trials/session']
    keys = ["# sessions", "# trials", "# trials analyzed", "# trials/session", "# trials/session analyzed"]
    print dfA.set_index(key)[keys].to_csv()
    print dfA.groupby('isLongDur')[keys].sum()
    print dfA.groupby('dotmode')[keys].sum()

    print resample_by_grp(df3)
示例#11
0
def fit(args,
        outdir,
        nboots,
        collapseCoh=False,
        isLongDur=False,
        resample=None,
        plot=False):
    df = load(args, None, 'both' if isLongDur else False)
    if resample:
        df = resample_by_grp(df, resample)
    dur_rng = (min_dur, max_dur_longDur) if isLongDur else (min_dur, max_dur)
    subj = subj_label(df)
    durmap = durmap_fcn(df)
    res = {}
    for grp, df_dotmode in df.groupby(
            'dotmode' if collapseCoh else ['dotmode', 'coherence']):
        key = grp if not collapseCoh else (grp, None)
        res = fit_df(df_dotmode, nboots, res, key, dur_rng, durmap)
    df1, df2 = finish_res(res, subj)
    if outdir:
        write_csv(df1, df2, subj, collapseCoh, outdir)
    if plot:
        plot_fit(df1, df2, collapseCoh)
示例#12
0
def load(min_dur=0.3, max_dur=1.2, min_coh=0.03, max_coh=0.5):
    fltrs = [pd_io.make_gt_filter('real_duration', min_dur), pd_io.make_lt_filter('real_duration', max_dur)]
    fltrs.extend([pd_io.make_gt_filter('coherence', min_coh), pd_io.make_lt_filter('coherence', max_coh)])
    return pd_io.load(None, fltrs, 'both')