コード例 #1
0
ファイル: statistics.py プロジェクト: florisvb/analysis
def t_test_for_evasive_saccades(dataset):
    sac.calc_saccade_stats(dataset)
    
    black_saccade_angle = []
    checkered_saccade_angle = []
    
    keys = dataset.keys_saccade_array
    
    evasive_threshold = 0.836248003234

    for i, key in enumerate(keys):
        trajec = dataset.trajecs[key]
        a = dataset.angle_of_saccade_array[i]
        ap = dataset.angle_prior_array[i]
        
        if np.abs(a-ap) > evasive_threshold:
            if 'black' in trajec.post_type:
                black_saccade_angle.append(dataset.angle_subtended_array[i])
            elif 'checkered' in trajec.post_type:
                checkered_saccade_angle.append(dataset.angle_subtended_array[i])

    black_saccade_angle = np.array(black_saccade_angle)
    checkered_saccade_angle = np.array(checkered_saccade_angle)
    
    if 1:
        fig = plt.figure()
        ax = fig.add_subplot(111)
        bins = np.linspace( np.log(5*np.pi/180.), np.log(180*np.pi/180.), 20)
        bins, hists, curves = floris.histogram(ax, [np.log(black_saccade_angle), np.log(checkered_saccade_angle)], bins=bins, colors=['black', 'teal'], return_vals=True, normed_occurences=True, curve_line_alpha=0)

        deg_ticks = np.array([5, 10, 30, 60, 90, 180])
        deg_tick_strings = [str(d) for d in deg_ticks]
        rad_ticks = deg_ticks*np.pi/180.
        rad_ticks_log = np.log(rad_ticks)
        
        dist_tick_strings = ['(21)', '(10)', '(2.7)', '(0.9)', '(0.4)', '(0)']
        x_tick_strings = []
        for i, d in enumerate(dist_tick_strings):
            x_tick_strings.append( deg_tick_strings[i] + '\n' + dist_tick_strings[i] )
        
        ax.set_xlim(rad_ticks_log[0], rad_ticks_log[-1])
        ax.set_ylim(0,1)
        
        fa.adjust_spines(ax,['left', 'bottom'])
        ax.set_xlabel('Retinal size, deg\n(distance, cm)', labelpad=10)
        ax.set_ylabel('Occurances')
        
        ax.set_xticks(rad_ticks_log.tolist())
        ax.set_xticklabels(x_tick_strings) 
        
        
        fig.subplots_adjust(bottom=0.25, top=0.9, right=0.9, left=0.2)
        filename = 'saccade_histogram_black_vs_checkered' + '.pdf'
        fig.savefig(filename, format='pdf')

    print 't test: ', scipy.stats.ttest_ind(black_saccade_angle, checkered_saccade_angle)
    print 'mann whitney u: ', scipy.stats.mannwhitneyu(black_saccade_angle, checkered_saccade_angle)
    print 'black: ', np.mean(black_saccade_angle), 'n: ', len(black_saccade_angle)
    print 'checkered: ', np.mean(checkered_saccade_angle), 'n: ', len(checkered_saccade_angle)
    print 'total n - 2: ', len(black_saccade_angle) + len(checkered_saccade_angle) - 2
コード例 #2
0
def get_slipangles_for_movie_dataset(movie_dataset):

    keys = movie_dataset.get_movie_keys()

    slipangles = []
    for key in keys:
        movie = movie_dataset.movies[key]
        try:
            tmp = get_slipangles(movie)
            slipangles.extend(tmp)
        except:
            print key
            
    slipangles_in_degrees = np.array(slipangles)*180/np.pi
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    bins = np.linspace(-90, 90, 20, endpoint=True)
    #ax.hist(slipangles_in_degrees, bins=bins, edgecolor='none', facecolor='purple')
    bins, hists, curves = floris.histogram(ax, [slipangles_in_degrees], bins=bins, colors='black', bin_width_ratio=0.9, edgecolor='none', bar_alpha=0.8, curve_fill_alpha=0, curve_line_alpha=0, return_vals=True)

    ax.set_xlim(-90,90)
    ax.set_ylim(0, 250)
    fa.adjust_spines(ax, ['left', 'bottom'])
    xticks = [-90, -45, 0, 45, 90]
    ax.set_xticks(xticks)

    ax.set_xlabel('Slip angle')
    ax.set_ylabel('Occurences')
    N = len(slipangles)
    n = len(keys)
    string = 'N='+str(N)+'\nn='+str(n)
    ax.text(45,60,string)
        
    fig.savefig('slipangles_nosaccade.pdf', format='pdf')
                
    return slipangles
コード例 #3
0
def run(neural_delay=0.05):
    
    initial_retinal_size = 15*np.pi/180.
    expansion = np.array([143, 250, 330, 500, 1000, 1430, 2000, 5000])*np.pi/180.
    delay = np.array([0.3, .22, .21, .16, .11, .105, .1, .1])
    angle_subtended = initial_retinal_size + (delay-neural_delay)*expansion
    
    tti = np.abs(np.sin(angle_subtended/2.)-1) / (0.5*1/np.tan(angle_subtended/2.)*expansion)
    print tti
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    
    ax.plot( angle_subtended[0:5], expansion[0:5], '.', color='blue' ) 
    ax.plot( angle_subtended[5:], expansion[5:], '.', color='red' ) 
    
    deg_ticks = np.array([0, 45, 90, 135])
    deg_tick_strings = [str(d) for d in deg_ticks]
    rad_ticks = deg_ticks*np.pi/180.
    
    
    ## plot paramters    
    ax.set_ylim([0,50])
    ax.set_xlim(rad_ticks[0], rad_ticks[-1])
    ax.set_autoscale_on(False)
    
    fa.adjust_spines(ax, ['left', 'bottom'])
    ax.set_xlabel('position on retina, deg')
    ax.set_ylabel('expansion threshold, rad/s')
    
    ax.set_xticks(rad_ticks)
    ax.set_xticklabels(deg_tick_strings)
    
    filename = 'tammero_data_landing.pdf'
    fig.savefig(filename, format='pdf')

    print np.mean(angle_subtended[0:5])*180/np.pi
コード例 #4
0
def plot_touchdown_velocity(movie_dataset):

    landing_keys = movie_dataset.get_movie_keys(behavior="landing")

    legextension_time = []
    touchdown_velocities = []
    touchdown_position = []
    sitting_position = []
    touchdown_time = []
    angle = []
    for key in landing_keys:
        movie = movie_dataset.movies[key]
        try:
            s = movie.scaled
        except:
            s = None
            print key, ": excepted"
        if (
            movie.landingframe is not None
            and "touchandgo" not in movie.subbehavior
            and movie.trajec is not None
            and s is not None
        ):
            touchdown_velocities.append(movie.scaled.speed[movie.landingframe_relative])
            touchdown_position.append(movie.scaled.dist_to_post[movie.landingframe_relative][0])
            sitting_position.append(np.min(movie.scaled.dist_to_post))
            legextensionframe = movie.legextensionrange[0] - movie.firstframe_ofinterest
            touchdown_time.append(movie.timestamps[movie.landingframe_relative] - movie.timestamps[legextensionframe])

            legextensionframe = movie.legextensionrange[0] - movie.firstframe_ofinterest
            legextension_time.append(movie.timestamps[legextensionframe])

            a = movie.scaled.signed_angletopost[movie.landingframe_relative]
            while a < -np.pi:
                a += np.pi
            while a > np.pi:
                a -= np.pi
            angle.append(a)
        else:
            print key

    print "n: ", len(touchdown_velocities)

    time_after_leg_extension = np.array(touchdown_time) * 1000

    fig = plt.figure()
    ax = fig.add_subplot(111)
    ma = np.min(time_after_leg_extension)
    mi = np.max(time_after_leg_extension)
    # bins = np.linspace(ma, mi, 10, endpoint=True)
    bins, hists, curves = floris.histogram(
        ax,
        [time_after_leg_extension],
        bins=10,
        colors="black",
        bin_width_ratio=0.9,
        edgecolor="none",
        bar_alpha=0.8,
        curve_fill_alpha=0,
        curve_line_alpha=0,
        return_vals=True,
        show_smoothed=False,
    )
    ax.set_ylim(0, np.max(hists))
    ax.set_xlim(0, 400)
    ax.set_autoscale_on(False)
    fa.adjust_spines(ax, ["left", "bottom"])
    ax.set_xlabel("Time to touchdown, ms")
    ax.set_ylabel("Occurences")
    filename = "time_to_touchdown_at_leg_ext.pdf"
    fig.savefig(filename, format="pdf")
    print "mean time to touchdown after leg ext: ", np.mean(touchdown_velocities)

    touchdown_velocities = np.array(touchdown_velocities)
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.hist(touchdown_velocities)
    filename = "touchdown_velocities.pdf"
    fig.savefig(filename, format="pdf")
    print "mean touchdown velocity: ", np.mean(touchdown_velocities), "+/-", np.std(touchdown_velocities)

    dist_travelled_in_touchdown = np.array(touchdown_position) - np.array(sitting_position)
    indices = np.where(dist_travelled_in_touchdown > 0)[0].tolist()
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.hist(dist_travelled_in_touchdown[indices])
    filename = "touchdown_dist_travelled.pdf"
    fig.savefig(filename, format="pdf")
    print "mean dist travelled: ", np.mean(dist_travelled_in_touchdown)

    time_travelled_in_touchdown = np.array(touchdown_time)
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.hist(time_travelled_in_touchdown)
    filename = "time_travelled_in_touchdown.pdf"
    fig.savefig(filename, format="pdf")

    angle = np.array(angle) * 180 / np.pi
    fig = plt.figure()
    ax = fig.add_subplot(111)
    bins = np.linspace(-90, 90, 20)
    ax.hist(angle, bins=bins)
    filename = "angle_to_post_at_touchdown.pdf"
    fig.savefig(filename, format="pdf")

    accel = touchdown_velocities[indices] ** 2 / (2 * dist_travelled_in_touchdown[indices])
    mass = 0.001
    force = accel * mass
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.hist(force * 10 ** 4)
    filename = "touchdown_deceleration.pdf"
    fig.savefig(filename, format="pdf")
    print "mean touchdown deceleration: ", np.mean(accel)
    print "mean touchdown force: ", np.mean(force)
コード例 #5
0
ファイル: statistics.py プロジェクト: florisvb/analysis
def t_test_for_leg_ext(movie_dataset, behavior='landing'):
    
    black_legext_angle = []
    checkered_legext_angle = []
    
    keys = movie_dataset.movies.keys()
    
    n = 0
    for movieid in keys:
        movie = movie_dataset.movies[movieid]
        if movie.behavior == behavior:        
            if movie.legextensionrange is not None:
                legextensionframe = movie.legextensionrange[0] - movie.firstframe_ofinterest
                #sa1_time = movie.timestamps[legextensionframe]
                #flydra_frame = get_flydra_frame_at_timestamp(movie.trajec, sa1_time)
                
                try:
                    tmp = movie.scaled
                    tmp = True
                except:
                    tmp = False
                
                if 'crash' not in movie.subbehavior and tmp and legextensionframe < movie.landingframe_relative: #tmp: #movie.trajec.classification == 'straight':
                    if 'black' in movie.posttype:
                        black_legext_angle.append(movie.scaled.angle_subtended_by_post[legextensionframe][0])
                    elif 'checkered' in movie.posttype:
                        checkered_legext_angle.append(movie.scaled.angle_subtended_by_post[legextensionframe][0])
                    n += 1
        
    black_legext_angle = np.array(black_legext_angle)
    checkered_legext_angle = np.array(checkered_legext_angle)
    
    if 1:
        fig = plt.figure()
        ax = fig.add_subplot(111)
        bins = np.linspace( np.log(5*np.pi/180.), np.log(180*np.pi/180.), 16)
        bins, hists, curves = floris.histogram(ax, [np.log(black_legext_angle), np.log(checkered_legext_angle)], bins=bins, colors=['black', 'teal'], return_vals=True, normed_occurences=False, curve_line_alpha=0, show_smoothed=True)

        deg_ticks = np.array([5, 10, 30, 60, 90, 180])
        deg_tick_strings = [str(d) for d in deg_ticks]
        rad_ticks = deg_ticks*np.pi/180.
        rad_ticks_log = np.log(rad_ticks)
        
        dist_tick_strings = ['(21)', '(10)', '(2.7)', '(0.9)', '(0.4)', '(0)']
        x_tick_strings = []
        for i, d in enumerate(dist_tick_strings):
            x_tick_strings.append( deg_tick_strings[i] + '\n' + dist_tick_strings[i] )
        
        ax.set_xlim(rad_ticks_log[0], rad_ticks_log[-1])
        ax.set_ylim(0,10)
        
        fa.adjust_spines(ax,['left', 'bottom'])
        ax.set_xlabel('Retinal size, deg\n(distance, cm)', labelpad=10)
        ax.set_ylabel('Occurances')
        
        ax.set_xticks(rad_ticks_log.tolist())
        ax.set_xticklabels(x_tick_strings) 
        
        
        fig.subplots_adjust(bottom=0.25, top=0.9, right=0.9, left=0.2)
        filename = 'legext_histogram_black_vs_checkered' + '.pdf'
        fig.savefig(filename, format='pdf')
        
    print 'T-test', scipy.stats.ttest_ind(black_legext_angle, checkered_legext_angle)
    print 'Mann Whitney U', scipy.stats.mannwhitneyu(black_legext_angle, checkered_legext_angle)
    print 'black: ', np.mean(black_legext_angle), 'n: ', len(black_legext_angle)
    print 'checkered: ', np.mean(checkered_legext_angle), 'n: ', len(checkered_legext_angle)
    print 'total n - 2: ', len(black_legext_angle) + len(checkered_legext_angle) - 2
コード例 #6
0
def test_neural_threshold(save_plot=True, tti=0.12, tti_thresh=0.7, movie_dataset=None):
    fig = plt.figure()
    ax = fig.add_subplot(111)
    
    distfig = plt.figure()
    distax = distfig.add_subplot(111)
    
    radius = 0.009565
    a = np.linspace(0,2.5,100)
    m = -0.21/radius
    b = 0.159/radius
    expthreshold = (m*np.log(a)+b)*(2*np.tan(a/2.)*np.sin(a/2.))
    
    vel = (expthreshold*radius/(2*np.tan(a/2.)*np.sin(a/2.)))[1:]
    print vel
    
    f = np.where(vel<0.07)[0][0]+1
    print f
    expthreshold_clipped = expthreshold[0:f]
    a_clipped = a[0:f]
    a_clipped_flipped = (a_clipped[::-1]-a_clipped[-1])[::-1]
    
    a_clipped_mirrored = np.hstack( (a_clipped_flipped, a_clipped) )
    expthreshold_clipped_mirrored = np.hstack( (expthreshold_clipped[::-1], expthreshold_clipped) )
    
    ax.plot( a_clipped_mirrored, expthreshold_clipped_mirrored, color='blue' )
    ax.fill_between(a_clipped_mirrored, expthreshold_clipped_mirrored, np.ones_like(a_clipped_mirrored)*30, facecolor='blue', edgecolor=None, alpha=0.1 )
    #ax.plot( a_clipped, expthreshold_clipped, color='blue' )
    #ax.plot( a_clipped[::-1]-a_clipped[-1], expthreshold_clipped, color='blue')
    #ax.fill_between( a_clipped, expthreshold_clipped, np.ones_like(a_clipped)*30, facecolor='blue', edgecolor=None, alpha=0.2 )
    #ax.fill_between( a_clipped[::-1]-a_clipped[-1], expthreshold_clipped, np.ones_like(a_clipped)*30, facecolor='blue', edgecolor=None, alpha=0.2 )
    
    # distance plot
    distax.plot( np.log(a), expthreshold, color='blue')
    
    
    
    
    
    
    
    
    
    
    
    
    # for true time to impact model
    #tti = 0.05
    expthreshold_tti = 2*np.tan(a/2.) / tti - tti_thresh
    vel = (expthreshold_tti*radius/(2*np.tan(a/2.)*np.sin(a/2.)))[1:]
    #f = np.where(vel<0.07)[0][0]+1
    expthreshold_tti_clipped = expthreshold_tti#[0:f]
    a_clipped = a#[0:f]
    
    ax.plot( a_clipped, expthreshold_tti_clipped, color='red' )
    ax.plot( a_clipped[::-1]-a_clipped[-1], expthreshold_tti_clipped, color='red')
    
    deg_ticks = np.array([-90, -45, 0, 45, 90])
    deg_tick_strings = [str(d) for d in deg_ticks]
    rad_ticks = [-np.pi, -np.pi/2., 0, np.pi/2., np.pi]
    
    distax.plot( np.log(a), expthreshold_tti, color='red')
    
    ## plot paramters    
    ax.set_ylim([0,1000*np.pi/180.])
    rad_ticks_y = np.linspace(0,1000*np.pi/180.,5,endpoint=True)
    deg_tick_strings_y = [str(s) for s in np.linspace(0,1000,5,endpoint=True)]
    
    for i, s in enumerate(deg_tick_strings_y):
        deg_tick_strings_y[i] = s.split('.')[0]
    
    ax.set_xlim(rad_ticks[0], rad_ticks[-1])
    ax.set_autoscale_on(False)
    
    fa.adjust_spines(ax, ['left', 'bottom'])
    ax.set_xlabel('position on retina, deg')
    ax.set_ylabel('expansion threshold, deg/s')
    
    ax.set_xticks(rad_ticks)
    ax.set_xticklabels(deg_tick_strings)
    ax.set_yticks(rad_ticks_y)
    ax.set_yticklabels(deg_tick_strings_y)
    
    
    if save_plot:
        fig.savefig('neural_threshold.pdf', format='pdf')
        
    if movie_dataset is not None:
        angle_at_leg_extension, bins, data_filtered, xvals = fa.leg_extension_angle_histogram(movie_dataset, plot=False)
        #ax2.plot(xvals, data_filtered, color='green', alpha=0.3)
        data_filtered /= np.max(data_filtered)
        data_filtered *= 7
        distax.fill_between(xvals, data_filtered, np.zeros_like(xvals), color='green', linewidth=0, alpha=0.2)
    
    fa.fix_angle_log_spine(distax, histograms=False, set_y=False)
    ylim_max = 1000
    distax.set_ylim(0,ylim_max/180.*np.pi)
    rad_ticks_y = np.linspace(0,ylim_max*np.pi/180.,5,endpoint=True)
    deg_tick_strings_y = [str(s) for s in np.linspace(0,ylim_max,5,endpoint=True)]
    for i, s in enumerate(deg_tick_strings_y):
        deg_tick_strings_y[i] = s.split('.')[0]
    distax.set_yticks(rad_ticks_y)
    distax.set_yticklabels(deg_tick_strings_y)
    distax.set_ylabel('expansion threshold, deg/s')
    
    if save_plot:
        distfig.savefig('neural_threshold_distance.pdf', format='pdf')
        
    return a, expthreshold, expthreshold_tti