コード例 #1
0
def plot_landing_demo_trajectory(movie_dataset, filename=None):
    movieinfo = movie_dataset.movies['20101110_C001H001S0038']
    nudge = [0, -.003] # for SA1 data
    trajec = movieinfo.trajec
    trajec.key = movieinfo.id
    trajec.frames = np.arange(fa.get_frame_at_distance(trajec, 0.08), trajec.frame_of_landing).tolist()
    fa.prep_trajectory(trajec)
    plot_demo_trajectory(movieinfo, nudge, filename=filename)
    
    legim = movieinfo.frames[movieinfo.legextensionrange[0] - movieinfo.firstframe_ofinterest + 50].uimg
    plt.imsave('legextensionimg', legim, cmap=plt.get_cmap('gray')) 
コード例 #2
0
def plot_flyby_demo_trajectory(movie_dataset, filename=None):
    movieinfo = movie_dataset.movies['20101101_C001H001S0024']
    nudge = [0, -.001] # for SA1 data
    trajec = movieinfo.trajec
    trajec.key = movieinfo.id
    frame_nearest_to_post = np.argmin(trajec.dist_to_stim_r)
    fa.calc_radius_at_nearest(trajec)    
    frames = np.arange(0, frame_nearest_to_post).tolist()
    frame_at_distance = fa.get_frame_at_distance(trajec, 0.08, singleframe=True, frames=frames)
    last_frame = np.min( [frame_nearest_to_post+20, len(trajec.speed)-1]) 
    trajec.frames_of_flyby = np.arange(frame_at_distance, last_frame).tolist()
    trajec.frames = trajec.frames_of_flyby
    fa.prep_trajectory(trajec)
    plot_demo_trajectory(movieinfo, nudge, filename=filename)
コード例 #3
0
ファイル: crash_analysis.py プロジェクト: florisvb/analysis
def make_crash_dataset(movie_dataset, example_dataset):
    dataset_crash = ffa.Dataset(like=example_dataset)
    keys = movie_dataset.get_movie_keys(behavior='landing', crash=True)
    
    for key in keys:
        movie = movie_dataset.movies[key]
        trajec = movie.trajec
        trajec.behavior = movie.behavior
        trajec.key = key
        fa.calc_frame_of_landing(trajec)
        fa.normalize_dist_to_stim_r(trajec)    
        d = np.max(np.max(trajec.dist_to_stim_r_normed, 0.08))
        trajec.frames = np.arange(fa.get_frame_at_distance(trajec, d), trajec.frame_of_landing).tolist()    
        fa.prep_trajectory(trajec)
    
        dataset_crash.trajecs.setdefault(key, trajec)
        
    fa.prep_dataset(dataset_crash)
    
    return dataset_crash
コード例 #4
0
def make_behavior_dataset(dataset,
                          filename='dataset_nopost_landing',
                          behavior='landing'):

    REQUIRED_LENGTH = 30
    REQUIRED_DIST = 0.1

    new_dataset = ffa.Dataset(like=dataset)
    if type(behavior) is not list:
        behavior = [behavior]
    for k, trajec in dataset.trajecs.items():
        trajec.key = k
        if trajec.behavior in behavior:

            calc_frame_of_landing(trajec)
            fa.normalize_dist_to_stim_r(trajec)
            saccade_analysis.calc_saccades2(trajec)

            if trajec.behavior == 'landing':
                if trajec.dist_to_stim_r_normed[0] >= REQUIRED_DIST:
                    #if np.max(trajec.positions[:,2]) < 0 and np.min(trajec.positions[:,2]) > -0.15:
                    if np.min(trajec.positions[:, 2]) > -0.15:
                        trajec.frames = np.arange(
                            fa.get_frame_at_distance(trajec, REQUIRED_DIST),
                            trajec.frame_of_landing).tolist()
                        if trajec.frame_of_landing > REQUIRED_LENGTH:
                            if np.max(trajec.positions[trajec.frames, 2]
                                      ) < 0.15:  # no real altitude check
                                #classify(trajec, dfar=REQUIRED_DIST, dnear=0.005)
                                new_dataset.trajecs.setdefault(k, trajec)

                                first_frame = 0
                                trajec.frames_below_post = np.arange(
                                    first_frame,
                                    trajec.frame_of_landing + 1).tolist()

            elif trajec.behavior == 'flyby':
                frame_nearest_to_post = np.argmin(trajec.dist_to_stim_r)
                print k
                if frame_nearest_to_post > 10 and np.max(
                        trajec.dist_to_stim_r[0:frame_nearest_to_post]
                ) > REQUIRED_DIST:
                    if np.min(trajec.positions[:, 2]) > -0.15:
                        if trajec.dist_to_stim_r[frame_nearest_to_post] < 0.1:
                            fs = np.arange(frame_nearest_to_post,
                                           len(trajec.speed)).tolist()
                            try:
                                last_frame = get_frame_at_distance(
                                    trajec, REQUIRED_DIST, frames=fs)
                            except:
                                last_frame = len(trajec.speed) - 1
                            first_frame = fa.get_frame_at_distance(
                                trajec,
                                REQUIRED_DIST,
                                frames=np.arange(
                                    0, frame_nearest_to_post).tolist())

                            trajec.frames = np.arange(first_frame,
                                                      last_frame).tolist()

                            # get frame at 8cm away, prior to nearest approach
                            frame_nearest_to_post = np.argmin(
                                trajec.dist_to_stim_r)
                            trajec.frame_nearest_to_post = frame_nearest_to_post
                            frames = np.arange(0,
                                               frame_nearest_to_post).tolist()
                            trajec.frames_of_flyby = frames
                            frame_at_distance = fa.get_frame_at_distance(
                                trajec, 0.08, singleframe=True, frames=frames)

                            last_frame = np.min([
                                frame_nearest_to_post + 20,
                                len(trajec.speed) - 1
                            ])

                            sacs = [s[0] for s in trajec.sac_ranges]
                            sac_sgns = np.array(sacs) - frame_at_distance
                            sac_negs = np.where(sac_sgns < 0)[0]
                            if len(sac_negs) > 0:
                                sac_neg = sac_negs[0]
                            else:
                                sac_neg = 0
                            first_frame = sac_neg + 1

                            try:
                                trajec.frames_of_flyby = np.arange(
                                    first_frame, last_frame).tolist()
                                new_dataset.trajecs.setdefault(k, trajec)
                            except:
                                print 'ignored key: ', k, first_frame, last_frame

                            new_dataset.trajecs.setdefault(k, trajec)

    fa.save(new_dataset, filename)

    return new_dataset
コード例 #5
0
def prep_movie_trajec(movieinfo):
    trajec = movieinfo.trajec
    trajec.key = movieinfo.id
    trajec.frames = np.arange(fa.get_frame_at_distance(trajec, 0.08), trajec.frame_of_landing).tolist()
    fa.prep_trajectory(trajec)
コード例 #6
0
def make_behavior_dataset(dataset, filename='dataset_nopost_landing', behavior='landing'):

    REQUIRED_LENGTH = 30
    REQUIRED_DIST = 0.1

    new_dataset = ffa.Dataset(like=dataset)
    if type(behavior) is not list:
        behavior = [behavior]
    for k,trajec in dataset.trajecs.items():
        trajec.key = k
        if trajec.behavior in behavior:
            
            calc_frame_of_landing(trajec)
            fa.normalize_dist_to_stim_r(trajec)
            saccade_analysis.calc_saccades2(trajec)
            
            if trajec.behavior == 'landing':
                if trajec.dist_to_stim_r_normed[0] >= REQUIRED_DIST:
                    #if np.max(trajec.positions[:,2]) < 0 and np.min(trajec.positions[:,2]) > -0.15:
                    if np.min(trajec.positions[:,2]) > -0.15:
                        trajec.frames = np.arange(fa.get_frame_at_distance(trajec, REQUIRED_DIST), trajec.frame_of_landing).tolist()
                        if trajec.frame_of_landing > REQUIRED_LENGTH:
                            if np.max(trajec.positions[trajec.frames,2]) < 0.15: # no real altitude check
                                #classify(trajec, dfar=REQUIRED_DIST, dnear=0.005)
                                new_dataset.trajecs.setdefault(k, trajec)
                                
                                first_frame = 0
                                trajec.frames_below_post = np.arange(first_frame, trajec.frame_of_landing+1).tolist()

            elif trajec.behavior == 'flyby':
                frame_nearest_to_post = np.argmin(trajec.dist_to_stim_r)
                print k
                if frame_nearest_to_post > 10 and np.max(trajec.dist_to_stim_r[0:frame_nearest_to_post]) > REQUIRED_DIST:
                    if np.min(trajec.positions[:,2]) > -0.15:
                        if trajec.dist_to_stim_r[frame_nearest_to_post] < 0.1:
                            fs = np.arange(frame_nearest_to_post,len(trajec.speed)).tolist()
                            try:
                                last_frame = get_frame_at_distance(trajec, REQUIRED_DIST, frames=fs)
                            except:
                                last_frame = len(trajec.speed)-1
                            first_frame = fa.get_frame_at_distance(trajec, REQUIRED_DIST, frames=np.arange(0,frame_nearest_to_post).tolist())
                            
                            trajec.frames = np.arange(first_frame, last_frame).tolist()
                            
                            # get frame at 8cm away, prior to nearest approach
                            frame_nearest_to_post = np.argmin(trajec.dist_to_stim_r)
                            trajec.frame_nearest_to_post = frame_nearest_to_post
                            frames = np.arange(0, frame_nearest_to_post).tolist()
                            trajec.frames_of_flyby = frames
                            frame_at_distance = fa.get_frame_at_distance(trajec, 0.08, singleframe=True, frames=frames)
                            
                            last_frame = np.min( [frame_nearest_to_post+20, len(trajec.speed)-1]) 
                            
                            sacs = [s[0] for s in trajec.sac_ranges]
                            sac_sgns = np.array(sacs) - frame_at_distance
                            sac_negs = np.where(sac_sgns<0)[0]
                            if len(sac_negs) > 0:
                                sac_neg = sac_negs[0]
                            else:
                                sac_neg = 0
                            first_frame = sac_neg + 1
                            
                            try:
                                trajec.frames_of_flyby = np.arange(first_frame, last_frame).tolist()
                                new_dataset.trajecs.setdefault(k, trajec)
                            except:
                                print 'ignored key: ', k, first_frame, last_frame
                            
                            new_dataset.trajecs.setdefault(k, trajec)
                            
            
    fa.save(new_dataset, filename)

    return new_dataset
コード例 #7
0
ファイル: trajectory_plots.py プロジェクト: florisvb/analysis
def radial_trajectory_plot(dataset, filename='radial_trajectory_plot.pdf', keys=None, dataset_type='landing', nkeys=None, highlight_trajecs=False, behavior=['landing', 'flyby'], show_saccades=True, alpha2=1, color2='gray'):
    radius = 0.009565
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.set_ylim(-.15,.15)
    ax.set_xlim(0, .25)
    ax.set_autoscale_on(False)
    if keys is None:
        #keys = dataset.trajecs.keys()
        keys = fa.get_keys_for_behavior(dataset, behavior=behavior)
        if len(keys) > 300:
            keys = keys[0:300]
        
    if highlight_trajecs:
        if dataset_type == 'landing':
            keys_to_highlight = ['5_15269', '24_68713', '10_78813', '1_27887']
        elif dataset_type == 'flyby':
            keys_to_highlight = ['10_80113']
        else:
            keys_to_highlight = ['32_8003']
    else:
        keys_to_highlight = []
    
    if nkeys is not None:
        if nkeys < len(keys):
            keys = keys[0:nkeys]
            for key in keys_to_highlight:
                if key not in keys:
                    keys.append(key)
    
    print keys_to_highlight
    for key in keys:
        trajec = dataset.trajecs[key]    
        r = trajec.dist_to_stim_r + radius
        
        if trajec.behavior == 'landing':
            initial_frame = fa.get_frame_at_distance(trajec, 0.25)
            frames = np.arange(initial_frame, trajec.frame_of_landing).tolist()
        else:
            #try:
            #    #frames = trajec.frames_below_post
            #    frames = np.arange(0,trajec.frame_of_landing).tolist()
            #except:
            frames = np.arange(0,trajec.frames_of_flyby[-1]).tolist()
        
        if key in keys_to_highlight:
            alpha = 1
            linewidth = 1
            color = 'black'
            zorder = 500
            #ax.plot(r[:], trajec.positions[:,2], '-', color='black', alpha=1, linewidth=linewidth, zorder=zorder)
            ax.plot(r[:], trajec.positions[:,2], '-', color=color, alpha=alpha, linewidth=linewidth, zorder=zorder)
            ax.plot(r[frames], trajec.positions[frames,2], '-', color='blue', alpha=alpha, linewidth=linewidth, zorder=zorder)
            print 'plotted key to highlight'
        else:
            linewidth = 0.5
            zorder = 100
            ax.plot(r[frames], trajec.positions[frames,2], '-', color=color2, alpha=alpha2, linewidth=linewidth, zorder=zorder)
        
        if show_saccades:
            if len(trajec.sac_ranges) > 0:
                for sac_range in trajec.sac_ranges:
                    if sac_range == trajec.last_saccade_range:
                        ax.plot(r[sac_range], trajec.positions[sac_range,2], '-', color='red', alpha=alpha2, linewidth=linewidth, zorder=zorder+1)
                    elif len(trajec.last_saccade_range) > 0:
                        if sac_range[0] in frames:
                            if sac_range[0] < trajec.last_saccade_range[0]:
                                ax.plot(r[sac_range], trajec.positions[sac_range,2], '-', color='blue', alpha=alpha2, linewidth=linewidth, zorder=zorder+1)
                        
    if dataset_type != 'nopost':
        post = patches.Rectangle( (0, -0.15), radius, 0.15, facecolor='black', edgecolor='none', alpha=1)
        ax.add_artist(post)
    
    
    prep_radial_spagetti_for_saving(ax)
    filename = 'radial_spagetti' + dataset_type + '.pdf'
    fig.savefig(filename, format='pdf')
コード例 #8
0
ファイル: trajectory_plots.py プロジェクト: florisvb/analysis
def landing_xy_spagetti(dataset, keys=None, show_all_poi=False, alpha2=1, color2='gray', show_saccades=True):
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.set_ylim(-.15,.15)
    ax.set_xlim(-.25, .25)
    ax.set_autoscale_on(False)
    if keys is None:
        #classified_keys = fa.get_classified_keys(dataset)
        keys = dataset.trajecs.keys()
    
    #keys_to_highlight = [keys[33]]
    # straight: 2_29065, 2_3954, 5_15269
    # curve in: 24_68713
    # multiple saccades: 1_27887
    # hover loop: 10_78813
    
    #keys_to_highlight = ['5_15269', '24_68713', '10_78813', '1_27887']
    #keys_to_highlight = ['5_15269']
    #keys = keys_to_highlight
    keys_to_highlight = []
    print keys_to_highlight
    
    for key in keys:
        trajec = dataset.trajecs[key]    
        
        if key == '24_68713':
            flip = -1
        else:
            flip = 1
            
        initial_frame = fa.get_frame_at_distance(trajec, 0.25)
        frames = np.arange(initial_frame, len(trajec.speed)-1).tolist()
        #frames = np.arange(initial_frame, trajec.frame_of_landing).tolist()
            
        if key in keys_to_highlight:
            alpha = 1
            linewidth = 1
            color = 'black'
            zorder = 500
            ax.plot(flip*trajec.positions[frames,0], flip*trajec.positions[frames,1], '-', color=color, alpha=alpha, linewidth=linewidth, zorder=zorder)
        else:
            linewidth = 0.5
            zorder = 100
            
            ax.plot(flip*trajec.positions[frames,0], flip*trajec.positions[frames,1], '-', color=color2, alpha=alpha2, linewidth=linewidth, zorder=zorder)
            
        if show_saccades:
            if len(trajec.sac_ranges) > 0:
                for sac_range in trajec.sac_ranges:
                
                    if sac_range == trajec.last_saccade_range:
                        color = 'red'
                    else:
                        color = 'blue'    
                    
                    if sac_range[-1] in frames and sac_range[-1] < trajec.frame_of_landing:
                        ax.plot(flip*trajec.positions[sac_range,0], flip*trajec.positions[sac_range,1], '-', color=color, alpha=alpha2, linewidth=linewidth, zorder=zorder+1)
                        #sac = patches.Circle( (flip*trajec.positions[sac_range[0],0], flip*trajec.positions[sac_range[0],1]), radius=0.001, facecolor='red', edgecolor='none', alpha=alpha2, zorder=zorder+1)
                        #ax.add_artist(sac)
        
    '''
    trajec_to_highlight = dataset.trajecs[key_to_highlight]
    d = trajec_to_highlight.frame_at_deceleration   
    dec = patches.Circle( (trajec_to_highlight.positions[d,0], trajec_to_highlight.positions[d,1]), radius=0.002, facecolor='blue', edgecolor='none', alpha=1, zorder=100)
    ax.add_artist(dec)
    if len(trajec_to_highlight.saccades) > 0:
        for s in trajec_to_highlight.saccades:
            #s = trajec_to_highlight.saccades[-1]
            sac = patches.Circle( (trajec_to_highlight.positions[s,0], trajec_to_highlight.positions[s,1]), radius=0.002, facecolor='red', edgecolor='none', alpha=1, zorder=100)
            ax.add_artist(sac)
    '''
    
    post = patches.Circle( (0, 0), radius=0.009565, facecolor='black', edgecolor='none', alpha=1, zorder=1000)
    ax.add_artist(post)
    #ax.text(0,0,'post\ntop view', horizontalalignment='center', verticalalignment='center')
    
    prep_xy_spagetti_for_saving(ax)
    
    filename = 'landing_xy_spagetti' + '.pdf'
    fig.savefig(filename, format='pdf')