예제 #1
0
def plot_order_vs_time(DIR, colA, colB, df=pd.DataFrame(), fn=''):
    if len(df) < 1:
        df = pd.read_pickle(DIR +
                            'track/frame_means_rotation_polarization.pickle')
    if not 'coheXXXXXrence' in df.columns:  #FIXME
        ret, df = stim_handling.synch_coherence_with_rotation(DIR)
        if ret == 0:
            print DIR.split('/')[-1], 'logged stim does not match timestamps'
            return
    df = df[df['FrameNumber'].notnull()]
    fig = plt.figure()
    fig.suptitle(DIR.split('/')[-2])
    subs = ['coherence', colA, colB]
    colourlist = ['black', 'red', 'blue']
    ylabs = ['% Clockwise', 'Order', 'Order']
    ax1 = fig.add_subplot(311)
    ax2 = fig.add_subplot(312, sharex=ax1)
    ax3 = fig.add_subplot(313, sharex=ax1)
    axes = [ax1, ax2, ax3]
    for REP in range(len(subs)):
        ax = axes[REP]
        fig.add_axes(ax)
        plt.plot(df.Time, df[subs[REP]].values, color=colourlist[REP])
        ax.set_title(subs[REP])
        ax.set_ylabel(ylabs[REP])
        if REP < 2:
            plt.setp(ax.get_xticklabels(), visible=False)
        else:
            ax.set_xlabel('Time (s)')
        if subs[REP] == 'dRotation':
            ax.set_ylim(-1, 1)
            ax.set_yticks([-1, 0, 1])
            plt.axhline(y=0.0, color='k', linestyle='-')
        elif subs[REP] == 'coherence':
            ax.set_ylim(-0.1, 1.1)
            ax.set_yticks([0, 0.5, 1])
            axR = ax.twinx()
            plt.plot(df['Time'], df['speed'] * df['dir'] * 1000.0, color='r')
            axR.set_ylabel('speed', color='r')
            axR.tick_params('y', colors='r')
            axR.set_ylim(-110, 110)
            axR.set_yticks([-100, 0, 100])
        else:
            ax.set_ylim(0, 1)
            ax.set_yticks([0, 0.5, 1])
    #ax.legend(loc=0)
    #plt.colorbar()
    plt.savefig(DIR + 'track/vsTime_' + fn + colA + '_' + colB + '.svg',
                bbox_inches='tight',
                pad_inches=0)
    plt.savefig(DIR + 'track/vsTime_' + fn + colA + '_' + colB +
                '.png')  #, bbox_inches='tight',pad_inches = 0)
    plt.close('all')
    return
예제 #2
0
def setup(filelist, prestim_frames=400, **kwargs):
    stores = []
    framenums = []
    for vid in filelist:
        pf = pd.read_pickle(vid + '/track/perframe_stats.pickle')
        log = stims.get_logfile(vid)
        store = imgstore.new_for_filename(vid + '/metadata.yaml')
        stores.append(store)
        ret, pf2 = stims.synch_coherence_with_rotation(pf, log,
                                                       store)  #sync_reversals

        pf3 = sync_by_stimStart(pf2)
        startframe = pf3.loc[pf3['stimStart'].idxmax() - prestim_frames,
                             'FrameNumber']

        framenums.append(startframe)
    return filelist, stores, framenums
예제 #3
0
def run(DIR):
    TRACK_DIR = slashdir(DIR) + 'track/'
    frame_means = pd.read_pickle(TRACK_DIR + 'frame_means_rotation_polarization.pickle')

    #if not 'coherence' in frame_means.columns:
    ret, frame_means = stim_handling.synch_coherence_with_rotation(DIR)
    if ret == 0:
        print DIR.split('/')[-1], 'logged stim does not match timestamps'
        if os.path.exists(TRACK_DIR + 'centroid_rotation.pickle'):
            os.remove(TRACK_DIR + 'centroid_rotation.pickle')
        return    
    frame_means['timedelta'] = pd.to_timedelta(frame_means['Time'], unit='s')
    frame_means.index = frame_means['timedelta']
    frame_means = frame_means.resample('1s').median()

    frame_means['cRotation'] = get_centroid_rotation(DIR, frame_means, 10) 
    frame_means['stateDepRotOrder'] = stateDependentRotationOrder(frame_means)
    frame_means.to_pickle(TRACK_DIR + 'centroid_rotation.pickle')
    plot_order_vs_time(slashdir(DIR),   'dRotation','cRotation', 'stateDepRotOrder', df=frame_means)  
    return
예제 #4
0
    DATA = pd.DataFrame()

    for handle in HANDLES:
        for directory in DIRECTORIES:
            for fn in glob.glob(
                    directory + '*' + handle +
                    '*/track/frame_means_rotation_polarization.pickle'):
                gonogo = True
                for x in EXCLUDE:
                    if x in fn:
                        gonogo = False
                if gonogo:
                    print 'processing: ', fn
                    try:
                        ret, df = stim_handling.synch_coherence_with_rotation(
                            fn.rsplit('/', 2)[0])
                        if ret == 0:
                            print fn.split('/')[
                                -3], 'logged stim does not match timestamps'
                            if os.path.exists(
                                    fn.rsplit('/')[0] +
                                    '/centroid_rotation.pickle'):
                                os.remove(
                                    fn.rsplit('/')[0] +
                                    '/centroid_rotation.pickle')
                            continue
                        else:
                            #df = pd.read_pickle(fn)
                            expid, groupsize, _, expdate, exptime = fn.rsplit(
                                '/', 3)[1].split('_')
                            df['cRotation'] = centroid_rotation.get_centroid_rotation(
    groupData = pd.DataFrame()
    for DIR in DIRS:
        for fn in glob.glob('/media/recnodes/' + DIR +
                            '/coherencetestangular_' + str(groupsize) +
                            '_dotbot_*/track/perframe_stats.pickle'):
            try:
                if fn.split('/track/perframe_stats')[0] in blacklist:
                    print "excluding", fn
                    continue
                elif '20171219' in fn:
                    print "excluding", fn
                    continue
                print fn
                ret, pf = stims.synch_coherence_with_rotation(
                    pd.read_pickle(fn),
                    stims.get_logfile(fn.rsplit('/', 2)[0]),
                    imgstore.new_for_filename(
                        fn.rsplit('/', 2)[0] + '/metadata.yaml'))
                pf['dir'] = pd.to_numeric(pf['dir'], errors='coerce')
                pf['coh'] = pf['coh'].fillna(method='pad').fillna(
                    method='backfill')
                pf['coh'] = min(coherences,
                                key=lambda x: abs(x - pf['coh'].median()))

                pf = sync_by_stimStart(pf)
                fileID = fn.split('/')[-3].split('.')[0].split('_', 3)[-1]
                aligned = align_by_stim(pf, fileID)
                aligned['groupsize'] = groupsize
                groupData = pd.concat([groupData, aligned], axis=0)
            except Exception as E:
                print "ERROR", fn, '\n', E