示例#1
0
def landing_analysis_for_crash_comparison(dataset, keys=None):
    fig = plt.figure()
    ax = fig.add_subplot(111)
    
    if keys is None:
        classified_keys = fa.get_classified_keys(dataset)
        keys = classified_keys['straight']
        keys = dataset.trajecs.keys()
        
    for key in keys:
        trajec = dataset.trajecs[key]
        ftp = np.arange(trajec.frames[0]-25, trajec.frames[-1]).tolist()
        ax.plot( np.log(trajec.angle_subtended_by_post[ftp]), trajec.speed[ftp], color='black', linewidth=0.5, alpha=0.05)

    keys_to_highlight = ['2_29065', '2_31060', '8_10323', '6_715']
    for key in keys:
    
        color = 'gray'
        dotcolor = 'blue'
        if key in keys_to_highlight:
            color = 'black'
            dotcolor = 'purple'
    
        trajec = dataset.trajecs[key]
        ftp = np.arange(trajec.frames[0]-25, trajec.frames[-1]).tolist()
        ax.plot( np.log(trajec.angle_subtended_by_post[ftp]), trajec.speed[ftp], color=color, linewidth=0.5, alpha=1)
        ax.plot( np.log(trajec.angle_at_deceleration), trajec.speed_at_deceleration, '.', color=dotcolor, alpha=1)
        
    fit, Rsq, x, y, yminus, yplus = fa.get_angle_vs_speed_curve(dataset, plot=False)
    ax.plot( x, y, color='purple')
    ax.fill_between(x, yplus, yminus, color='purple', linewidth=0, alpha=0.2)
        
    fa.fix_angle_log_spine(ax, histograms=False)
    fig.savefig('landing_for_crash_comparison.pdf', format='pdf')
示例#2
0
def speed_histogram(dataset, keys=None):

    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    
    
    if keys is None:
        classified_keys = fa.get_classified_keys(dataset)
        keys = dataset.trajecs.keys()
        
    speeds = []    
    for key in keys:
        trajec = dataset.trajecs[key]
        
        if trajec.behavior == 'flyby':
            frames = trajec.frames_of_flyby
        else:
            frames = trajec.frames
            
        speeds.extend(trajec.speed[frames])
        
        
    bins = np.linspace(0, 0.6, 50) 
    ax.hist(speeds, bins=bins)
    fig.savefig('speeds.pdf', format='pdf')
def landing_spagetti_plots(dataset, gain=[170000], keys=None):
    fig = plt.figure()
    ax = fig.add_subplot(111)
    
    fig2 = plt.figure()
    ax2 = fig2.add_subplot(111)
    
    fig3 = plt.figure()
    ax3 = fig3.add_subplot(111)
    
    if keys is None:
        classified_keys = fa.get_classified_keys(dataset)
        keys = classified_keys['straight']
        #keys = dataset.trajecs.keys()
        
    #keys_to_highlight = [keys[2], keys[0], keys[4], keys[6]]
    keys_to_highlight = ['2_29065', '2_31060', '8_10323', '6_715']
    points_at_deceleration = True
        
    for key in keys:
        trajec = dataset.trajecs[key]
        ftp = np.arange(trajec.frames[0]-25, trajec.frame_of_landing-1).tolist()
        #ftp = np.arange(trajec.frame_at_deceleration-10, trajec.frame_of_landing-1).tolist()
        if key in keys_to_highlight:
            color = 'black'
            zorder = 10
        else:
            color = 'blue'
            zorder = 1
        ax.plot( np.log(trajec.angle_subtended_by_post[ftp]), trajec.speed[ftp], color=color, linewidth=0.5, alpha=1, zorder=zorder)
        if points_at_deceleration and key in keys_to_highlight:
            ax.plot( np.log(trajec.angle_at_deceleration), trajec.speed_at_deceleration, '.', color='black', alpha=1, zorder=zorder)
        
        ax3.plot( np.log(trajec.angle_subtended_by_post[ftp]), trajec.speed[ftp], color='black', linewidth=0.5, alpha=1)
        
        if 0:
            # simulate
            angle, speed, expansion = sim_deceleration(trajec, gain)
            if speed[0] > 0.1:        
                ax2.plot( np.log(angle), speed, color='black', linewidth=0.5, alpha=1)
                ax3.plot( np.log(angle), speed, color='black', linewidth=0.5, alpha=1)
                f = np.where( np.abs(speed-speed[0])>0 )[0][0]
                
                #ax2.plot( np.log(angle[f]), speed[f], '.', color='blue')
            
    fit, Rsq, x, y, yminus, yplus = fa.get_angle_vs_speed_curve(dataset, plot=False)
    ax2.plot( x, y, color='purple', alpha=1)
    ax2.fill_between(x, yplus, yminus, color='purple', linewidth=0, alpha=0.2)

    ax.plot( x, y, color='purple', alpha=1)
    ax.fill_between(x, yplus, yminus, color='purple', linewidth=0, alpha=0.2)
        
    fa.fix_angle_log_spine(ax, histograms=False)
    fig.savefig('deceleration_real.pdf', format='pdf')
    
    fa.fix_angle_log_spine(ax2, histograms=False)
    fig2.savefig('deceleration_sim.pdf', format='pdf')
    
    fa.fix_angle_log_spine(ax3, histograms=False)
    fig3.savefig('deceleration_comparison.pdf', format='pdf')
def plot_tti_wrt_retinal_size(dataset, keys=None, tti_thresh=0.05, plot=False):
    
    if plot:
        fig = plt.figure()
        ax = fig.add_subplot(111)
    
    
    if keys is None:
        classified_keys = fa.get_classified_keys(dataset)
        keys = classified_keys['straight']
        keys = dataset.trajecs.keys()
        
    #keys = keys[0:10]
    
    tti_below_thresh = []
        
    for key in keys:
        trajec = dataset.trajecs[key]
        ftp = np.arange(trajec.frame_at_deceleration-10, trajec.frame_of_landing-1).tolist()
        # simulate
        if plot:
            ax.plot( np.log(trajec.angle_subtended_by_post[ftp]), trajec.time_to_impact[ftp], '.', color='black', alpha=0.3)
            
        #tti_check = (np.sin(angle_subtended/2.)-1) / (np.sin(angle_subtended/2.) + 0.5*1/np.tan(angle_subtended/2.)*expansion)
            
        try:
            tti_below_thresh.append( trajec.angle_subtended_by_post[ np.where( (trajec.time_to_impact < tti_thresh)*(trajec.angle_to_post < 45*np.pi/180.) )[0][0] ])
        except:
            pass
            
    print 
    print 'time to impact below threshold of ', str(tti_thresh), ' sec: '
    print 'mean: ', np.mean(tti_below_thresh)*180/np.pi
    print 'std dev: ', np.std(tti_below_thresh)*180/np.pi
    print 'n: ', len(tti_below_thresh)
    print 'percent: ', len(tti_below_thresh) / float(len(keys))
        
    if plot:
        fa.fix_angle_log_spine(ax, histograms=False, set_y=False)
        ax.set_ylim(0,0.4)
        ticks_y = np.linspace(0,0.4,5,endpoint=True)
        tick_strings_y = [str(s) for s in np.linspace(0,0.4,5,endpoint=True)]
        for i, s in enumerate(tick_strings_y):
            tick_strings_y[i] = s
        ax.set_yticks(ticks_y)
        ax.set_yticklabels(tick_strings_y)
        ax.set_ylabel('time to impact, sec')
        fig.savefig('time_to_impact_vs_angle.pdf', format='pdf')
def plot_expansion_for_sim_trajec(dataset, gain=[170000], keys=None):
    fig = plt.figure()
    ax = fig.add_subplot(111)
    
    
    if keys is None:
        classified_keys = fa.get_classified_keys(dataset)
        keys = classified_keys['straight']
        #keys = dataset.trajecs.keys()
        
    keys = keys[0:10]
        
    for key in keys:
        trajec = dataset.trajecs[key]
        ftp = np.arange(trajec.frame_at_deceleration-10, trajec.frame_of_landing-1).tolist()
        # simulate
        angle, speed, expansion = sim_deceleration(trajec, gain)
        #ax.plot( np.log(angle), expansion, color='red', linewidth=0.5, alpha=0.5)
        ax.plot( np.log(trajec.angle_subtended_by_post[ftp]), trajec.expansion[ftp], color='black', linewidth=0.5, alpha=0.1)
        ax.plot( np.log(trajec.angle_at_deceleration), trajec.expansion_at_deceleration, '.', color='blue') 
        angle, speed, expansion = sim_deceleration(trajec, gain, constant_vel=True)
        #ax.plot( np.log(angle), expansion, color='green', linewidth=1, alpha=0.5)
        
    angle, expthreshold, expthreshold_tti = test_neural_threshold(save_plot=False, tti=0.05, tti_thresh=6)
    
    ax.plot(np.log(angle), expthreshold, color='blue')
    ax.plot(np.log(angle), expthreshold_tti, color='green')
    
    angle, expthreshold, expthreshold_tti = test_neural_threshold(save_plot=False, tti=0.12, tti_thresh=0.7)
    ax.plot(np.log(angle), expthreshold_tti, color='red')
        
    fa.fix_angle_log_spine(ax, histograms=False, set_y=False)
    exp_limit = 1500
    ax.set_ylim(0,exp_limit/180.*np.pi)
    rad_ticks_y = np.linspace(0,exp_limit*np.pi/180.,5,endpoint=True)
    deg_tick_strings_y = [str(s) for s in np.linspace(0,exp_limit,5,endpoint=True)]
    for i, s in enumerate(deg_tick_strings_y):
        deg_tick_strings_y[i] = s.split('.')[0]
    ax.set_yticks(rad_ticks_y)
    ax.set_yticklabels(deg_tick_strings_y)
    ax.set_ylabel('expansion threshold, deg/s')
    fig.savefig('deceleration_real.pdf', format='pdf')
def landing_srini_plots(dataset, keys=None):
    fig = plt.figure()
    ax = fig.add_subplot(111)
    
    
    if keys is None:
        classified_keys = fa.get_classified_keys(dataset)
        keys = classified_keys['straight']
        #keys = dataset.trajecs.keys()
        
    #keys = [keys[2], keys[0], keys[4], keys[6]]
        
    for key in keys:
        trajec = dataset.trajecs[key]
        ftp = np.arange(trajec.frame_at_deceleration-10, trajec.frame_of_landing-1).tolist()
        ax.plot( trajec.dist_to_stim_r_normed[ftp], trajec.speed[ftp], color='black', linewidth=0.5, alpha=0.2)
        # simulate
        
    ax.set_xlim([0,.1])
            
    fig.savefig('deceleration_linear_scale.pdf', format='pdf')
def get_error_between_sim_and_dataset(gain, *args):
    dataset = args[0]
    sum_error = 0
    
    keys = None
    if keys is None:
        classified_keys = fa.get_classified_keys(dataset)
        keys = classified_keys['straight']
    #keys = [keys[2], keys[0], keys[4], keys[6]]
    #nkeys = 5
    #keys = [keys[i] for i in range(20, nkeys+20)]
    n = 0
    for key in keys:
        trajec = dataset.trajecs[key]
        print trajec.obj_id
        e = get_error_between_sim_and_trajec(gain, trajec)
        if not np.isnan(e):
            sum_error += e
            n += 1             
    
    mean_error = sum_error / float(n)
    
    return mean_error
示例#8
0
def flyby_xy_spagetti(dataset, keys=None, show_all_poi=False, filename='flyby_xy_spagetti.pdf', nkeys=300, alpha2=1, color2='gray', show_saccades=True, keys_to_highlight=None, show_deceleration=False):
    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 = classified_keys['straight']
        keys = dataset.trajecs.keys()
        
    keys_with_saccades = []
    keys_without_saccades = []
    for key in keys:
        trajec = dataset.trajecs[key]    
        if len(trajec.sac_ranges) > 0:
            keys_with_saccades.append(key)
        else:
            keys_without_saccades.append(key)
    '''
    key_to_highlight = None
    k = -1
    while key_to_highlight is None:
        k += 1
        trajec = dataset.trajecs[keys[k]]    
        if len(trajec.saccades) > 0:
            key_to_highlight = keys[k]
    '''
    
    if keys_to_highlight is None:
        keys_to_highlight = ['10_80113']
        
    print keys_to_highlight

    if len(keys) > nkeys:
        keys = keys[0:nkeys]
        keys.extend(keys_to_highlight)

    for key in keys:
        trajec = dataset.trajecs[key]    
        
        if key in keys_to_highlight:
            alpha = 1
            linewidth = 1
            color = 'black'
            zorder = 500
            ax.plot(trajec.positions[:,0], trajec.positions[:,1], '-', color='black', alpha=1, linewidth=linewidth, zorder=zorder)
            frames = np.arange(0,trajec.frames_of_flyby[-1]).tolist()
            ax.plot(trajec.positions[frames,0], trajec.positions[frames,1], '-', color='green', alpha=1, linewidth=linewidth, zorder=zorder)
        else:
            linewidth = 0.5
            zorder = 100
            
            frames = np.arange(0,trajec.frames_of_flyby[-1]).tolist()
            ax.plot(trajec.positions[frames,0], 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[0] < trajec.frame_nearest_to_post:
                    #if 1:
                        ax.plot(trajec.positions[sac_range,0], trajec.positions[sac_range,1], '-', color=color, alpha=alpha2, linewidth=linewidth, zorder=zorder+1)
                        #sac = patches.Circle( (trajec.positions[sac_range[0],0], trajec.positions[sac_range[0],1]), radius=0.001, facecolor='red', edgecolor='none', alpha=alpha2, zorder=zorder+1)
                        #ax.add_artist(sac)
                        
        if show_deceleration:
            dec = patches.Circle( (trajec.positions[trajec.frame_at_deceleration,0], trajec.positions[trajec.frame_at_deceleration,1]), radius=0.001, facecolor='purple', edgecolor='none', color='purple', linewidth=2, alpha=alpha2, zorder=zorder+1)
            ax.add_artist(dec)
            
    
    
    
    
    post = patches.Circle( (0, 0), radius=0.009565, facecolor='black', edgecolor='none', alpha=1)
    ax.add_artist(post)
    #ax.text(0,0,'post\ntop view', horizontalalignment='center', verticalalignment='center')
    
    
    #post = patches.Circle( (0, 0), radius=0.028, facecolor='none', edgecolor='red', alpha=1, linewidth=0.15, linestyle='dashed')
    #ax.add_artist(post)
    
    prep_xy_spagetti_for_saving(ax)
    fig.savefig(filename, format='pdf')
示例#9
0
def flyby_xy_spagetti_types(dataset_flyby):
    classified_keys_flyby = fa.get_classified_keys(dataset_flyby)
    flyby_xy_spagetti(dataset_flyby, keys=classified_keys_flyby['flyby'][100:300], filename='flyby_xy_spagetti_random.pdf')
    flyby_xy_spagetti(dataset_flyby, keys=classified_keys_flyby['straight'], filename='flyby_xy_spagetti_straight.pdf')
示例#10
0
def landing_xy_spagetti_types(dataset):
    
    classified_keys = fa.get_classified_keys(dataset)
    
    for key_class in classified_keys.keys():
        landing_xy_spagetti(dataset, keys=None, show_all_poi=False, key_class=key_class)