コード例 #1
0
def recreate_frame(frame: List[List], L: float, grid_step: float) -> Sky:
    sky = Sky(L, grid_step)
    for bird in frame:
        pos, angle, vel, ang_vel = bird
        sky.add_bird(Bird(np.array(pos), vel, ang_vel, angle))

    return sky
コード例 #2
0
def launch_simulation_random(output_file: str,
                             L: float,
                             n_birds: int,
                             vel: float = 1,
                             ang_vel: float = np.pi / 2,
                             interaction_radius: float = 1,
                             eta: float = .5,
                             dt: float = 1,
                             total_time: float = 100,
                             evolve: Callable = None) -> None:
    gridstep = interaction_radius
    sky = Sky(L, gridstep)
    sky.add_n_random_birds(n_birds, vel, ang_vel)
    physics = Physics(sky, interaction_radius, eta)
    Life.simulate(physics,
                  dt,
                  total_time,
                  verbose_prop=.1,
                  output_file=output_file,
                  evolve=evolve)
コード例 #3
0
def launch_two_groups(output_file: str,
                      L: float,
                      n_birds_1: int,
                      n_birds_2: int,
                      radius_1: int,
                      radius_2: int,
                      center_1: list,
                      center_2: list,
                      angle_1: float,
                      angle_2: float,
                      vel: float = 1,
                      ang_vel: float = np.pi / 2,
                      interaction_radius: float = 1,
                      eta: float = .1,
                      dt: float = 1,
                      total_time: float = 100) -> None:
    gridstep = interaction_radius
    sky = Sky(L, gridstep)
    group_1_positions = (np.random.rand(n_birds_1, 2) -
                         .5) * radius_1 + np.array(center_1)
    for i in range(n_birds_1):
        sky.add_bird(Bird(group_1_positions[i], vel, ang_vel, angle_1))
    group_2_positions = (np.random.rand(n_birds_2, 2) -
                         .5) * radius_2 + np.array(center_2)
    for i in range(n_birds_2):
        sky.add_bird(Bird(group_2_positions[i], vel, ang_vel, angle_2))

    physics = Physics(sky, interaction_radius, eta)
    Life.simulate(physics,
                  dt,
                  total_time,
                  verbose_prop=.1,
                  output_file=output_file)
コード例 #4
0
    def process_correlations(self, sky: Sky, L: float) -> None:
        correlations_stochastic_points = self.options["correlations_stochastic_points"]
        dists, corrs = sky.get_angles_correlations(n=correlations_stochastic_points)

        # average over spatial fixed intervals
        space_points = self.options["fit_spatial_points"]
        regular_dists = np.linspace(0, L, space_points)
        regular_corrs = []
        for i in range(len(regular_dists) - 1):
            mask = np.logical_and(dists > regular_dists[i], dists < regular_dists[i + 1])
            if len(corrs[mask]) == 0:  # no points in interval
                mean = 0
            else:
                mean = np.mean(corrs[mask])
            regular_corrs.append(mean)
        regular_corrs = np.array(regular_corrs)

        self.data_holders["correlations"].append(regular_corrs)
コード例 #5
0
 def process_avg_angle(self, sky: Sky) -> None:
     self.data_holders["avg_angle"].append(sky.get_avg_angle())
コード例 #6
0
 def process_avg_speed(self, sky: Sky) -> None:
     self.data_holders["avg_speed"].append(sky.get_avg_speed())
コード例 #7
0
 def __init__(self, sky: Sky, interaction_radius: float, eta: float):
     self.sky = sky
     sky.update_grid()
     self.interaction_radius = interaction_radius
     self.eta = eta