def toggle(event):

    global scatter_currently_headings
    K = -1.*K_slider.val
    x_0 = x_0_slider.val
    time = stime.val*60.

    wind_mag = windmag_slider.val
    cone_angle = np.radians(cone_angle_slider.val)
    track_heading_angles,dispersing_speeds = f0(intended_heading_angles,wind_mag,wind_angle)

    if scatter_currently_headings:

        intersection_distances,dispersal_distances = f1_wedge(
            track_heading_angles,source_pos,wind_angle,cone_angle)
        success_probabilities = f2(intersection_distances,K,x_0,source_pos,wind_angle)
        plume_assignments = f3(success_probabilities,dispersal_distances)
        dispersal_travel_times,release_to_chosen_plume_distances = f4(
            plume_assignments,dispersal_distances,dispersing_speeds)
        fly_dots.set_offsets(
            scipy.c_[
                release_to_chosen_plume_distances*np.cos(track_heading_angles),
                release_to_chosen_plume_distances*np.sin(track_heading_angles)])
        scatter_currently_headings = not(scatter_currently_headings)
    else:
        fly_dots.set_offsets(
            scipy.c_[
                time*dispersing_speeds*np.cos(track_heading_angles),
                time*dispersing_speeds*np.sin(track_heading_angles)])
        scatter_currently_headings = not(scatter_currently_headings)

    fig1.canvas.draw_idle()
Example #2
0
def update1(val):

    wind_mag = windmag_slider.val
    track_heading_angles, dispersing_speeds = f0(intended_heading_angles,
                                                 wind_mag, wind_angle)

    time = stime.val * 60.
    fly_dots.set_offsets(
        scipy.c_[time * dispersing_speeds * np.cos(track_heading_angles),
                 time * dispersing_speeds * np.sin(track_heading_angles)])
    fig1.canvas.draw_idle()
Example #3
0
import matplotlib.pyplot as plt
import numpy as np
from pompy import models

wind_mag = 1.
wind_angle = np.pi
cone_angle = np.radians(10.)

#Source locations
location_list = [(200, 100), (300, -100), (-100, -200)]
source_pos = np.array([np.array(tup) for tup in location_list])

#fly headings: = np.pi/3 and 4*np.pi/3
intended_heading_angles = np.radians(np.array([60, 110, 200, 240]))

track_heading_angles, dispersing_speeds = f0(intended_heading_angles, wind_mag,
                                             wind_angle)

#Convert track_heading_angles to a list of plume intersection locations for each fly
intersection_distances, dispersal_distances = f1_wedge(track_heading_angles,
                                                       source_pos, wind_angle,
                                                       cone_angle)

print('intersection_distances: ')
print(np.array2string(intersection_distances))
print('dispersal_distances: ')
print(np.array2string(dispersal_distances))

#Display plumes
im_extents = (-500, 500, -500, 500)
# gaussianfitPlumes = models.GaussianFitPlume(source_pos,wind_angle,wind_mag)
# conc_im = gaussianfitPlumes.conc_im(im_extents,samples=200)
Example #4
0
def update(val):
    wind_mag = windmag_slider.val
    K = -1. * K_slider.val
    x_0 = x_0_slider.val
    track_heading_angles, dispersing_speeds = f0(intended_heading_angles,
                                                 wind_mag, wind_angle)
    intersection_distances, dispersal_distances = f1(track_heading_angles,
                                                     source_pos, wind_angle)
    success_probabilities = f2(intersection_distances, K, x_0, source_pos,
                               wind_angle)
    plume_assignments = f3(success_probabilities, dispersal_distances)
    dispersal_travel_times = f4(plume_assignments, dispersal_distances,
                                dispersing_speeds)
    arrival_times,chasing_times,\
        which_flies,which_traps = f5(plume_assignments,
            dispersal_travel_times,intersection_distances,fly_speed,release_times)

    #(1) Update the CDF figure
    new_maxes = 400 * np.ones(8)
    trap_counts = np.zeros(8)
    first_hit_times = np.full(8, np.nan)

    for i in range(8):

        row = sim_reorder[i] - 1
        ax = axes[i]
        t_sim = arrival_times[which_traps == i] / 60.

        try:
            (n, bins) = np.histogram(
                t_sim,
                bins=num_bins,  #cumulative=True,
                # histtype='step',
                range=(0, max(t_sim)))
            cum_n = np.cumsum(n)
            lines[i].set_ydata(np.hstack((np.array([
                0,
            ]), cum_n)))
            lines[i].set_xdata(bins)

            new_maxes[i] = max(400., 50 * np.ceil(max(cum_n) / 50.))

        #     xs,ys = cdf_patches[i].get_xy().T
        #     # print(patches[i].get_xy())
        #     old_bbox = cdf_patches[i].get_extents()
        #     print(old_bbox)
        #     [[x0, y0], [x1, y1]] = old_bbox.get_points()
        #     x0 = min(t_sim)
        #     y0 = max(t_sim)
        #
        #     # new_bbox = Bbox([[x0, y0], [x1, y1]])
        #     # cdf_patches[i].set_clip_box(new_bbox)
        #     old_bbox.set_points([[x0, y0], [x1, y1]])
        #     new = cdf_patches[i].get_extents()
        #     print(new)
        #     print('--------')
        #     # cdf_patches[i].set_xy(np.vstack((xs,ys)).T)
        #     # raw_input()
        #     # cdf_patches[i].set_x(min(t_sim))
        #     # cdf_patches[i].set_width(max(t_sim)-min(t_sim))

        # cdf_patches[i].update(min(t_sim),max(t_sim)-min(t_sim))

        except (ValueError):
            lines[i].set_ydata(np.zeros_like(lines[i].get_ydata))

        try:
            trap_counts[i] = max(cum_n)
        except:
            trap_counts[i] = 0

        patch_object = cdf_patches[i]
        patch_object.update(min(t_sim), max(t_sim) - min(t_sim))
        patch_object.rectangle.set_height(ax.get_ylim()[1])
        #print(patch_object.rectangle.get_x())
        #print('---------')
        cdf_steepnesses[i] = trap_counts[i] / (max(t_sim) - min(t_sim))
        first_hit_times[i] = min(t_sim)

    for i, ax in enumerate(axes):
        ax.set_ylim([0, np.max(new_maxes)])

    #(2) update the fly heading display
    time = stime.val * 60.
    fly_dots.set_offsets(
        scipy.c_[time * dispersing_speeds * np.cos(track_heading_angles),
                 time * dispersing_speeds * np.sin(track_heading_angles)])

    #(3) update the trap histogram figure

    trap_cmap_vals = (first_hit_times - vmin) / vmax
    # print('--------')
    # print(trap_cmap_vals)

    for i, trap_patch, trap_count in zip(range(8), trap_patches, trap_counts):
        trap_patch.set_radius(radius_scale * trap_count / max(new_maxes))
        trap_patch.set_alpha(min(cdf_steepnesses[i] / steepness_max, 1.))
        color = tuple(
            np.array(
                (trap_cmap(trap_cmap_vals[i])[:-1])).astype(float).tolist())
        # print(color)
        trap_patch.set_color(color)

    fig1.canvas.draw_idle()
    fig2.canvas.draw_idle()
    fig3.canvas.draw_idle()
def update(val):

    global scatter_currently_headings

    wind_mag = windmag_slider.val
    K = -1.*K_slider.val
    x_0 = x_0_slider.val
    cone_angle = np.radians(cone_angle_slider.val)
    track_heading_angles,dispersing_speeds = f0(intended_heading_angles,wind_mag,wind_angle)
    intersection_distances,dispersal_distances = f1_wedge(
        track_heading_angles,source_pos,wind_angle,cone_angle)

    success_probabilities = f2(intersection_distances,K,x_0,source_pos,wind_angle)
    plume_assignments = f3(success_probabilities,dispersal_distances)
    dispersal_travel_times,release_to_chosen_plume_distances = f4(
        plume_assignments,dispersal_distances,dispersing_speeds)
    arrival_times,chasing_times,\
        which_flies,which_traps = f5(plume_assignments,
            dispersal_travel_times,intersection_distances,fly_speed,release_times)


    #(1) Update the CDF figure
    new_maxes = 400*np.ones(8)
    trap_counts = np.zeros(8)
    first_hit_times = np.full(8,np.nan)

    for i in range(8):

        row = sim_reorder[i]-1
        ax = axes[i]
        t_sim = arrival_times[which_traps==i]/60.

        try:
            (n, bins) = np.histogram(t_sim,bins=num_bins,#cumulative=True,
                # histtype='step',
                range=(0,max(t_sim)))
            cum_n = np.cumsum(n)
            lines[i].set_ydata(np.hstack((np.array([0,]),cum_n)))
            lines[i].set_xdata(bins)

            new_maxes[i] = max(400.,50*np.ceil(max(cum_n)/50.))
            trap_counts[i]=max(cum_n)


        except(ValueError):
            lines[i].set_ydata(np.zeros_like(lines[i].get_ydata))
            trap_counts[i]=0

        patch_object = cdf_patches[i]
        try:
            patch_object.update(min(t_sim),max(t_sim)-min(t_sim))
            patch_object.rectangle.set_height(ax.get_ylim()[1])
            cdf_steepnesses[i] = trap_counts[i]/(max(t_sim)-min(t_sim))
            first_hit_times[i] = min(t_sim)
        except(ValueError):
            pass
        #print(patch_object.rectangle.get_x())
        #print('---------')



    for i,ax in enumerate(axes):
        ax.set_ylim([0,np.max(new_maxes)])

    #(2) update the fly heading display
    time = stime.val*60.


    if scatter_currently_headings:
        fly_dots.set_offsets(
            scipy.c_[
                time*dispersing_speeds*np.cos(track_heading_angles),
                time*dispersing_speeds*np.sin(track_heading_angles)])
    else:
        fly_dots.set_offsets(
            scipy.c_[
                release_to_chosen_plume_distances*np.cos(track_heading_angles),
                release_to_chosen_plume_distances*np.sin(track_heading_angles)])

    #(2a) update the plume wedges
    wedge_points = plot_wedges(source_pos,wind_angle,cone_angle)
    for i,wedge in enumerate(plume_wedges):
        wedge.set_xy(wedge_points[:,i,:])


    #(3) update the trap histogram figure

    trap_cmap_vals = (first_hit_times-vmin)/vmax
    # print('--------')
    # print(trap_cmap_vals)

    for i,trap_patch,trap_count in zip(range(8),trap_patches,trap_counts):
        trap_patch.set_radius(radius_scale*trap_count/max(new_maxes))
        trap_patch.set_alpha(min(cdf_steepnesses[i]/steepness_max,1.))
        color = tuple(np.array((trap_cmap(trap_cmap_vals[i])[:-1])).astype(float).tolist())
        # print(color)
        trap_patch.set_color(color)

    fig1.canvas.draw_idle()
    fig2.canvas.draw_idle()
    fig3.canvas.draw_idle()