Exemple #1
0
 def test_neighbour_distance(self):
     """
     TODO: This test contains no asserts and has just been used as a way of eye-balling distances when debug is
     uncommented.
     Create a world with a fixed number of cells, where the expected approximate distance between neighbouring
     nodes is know, so aberrant configurations can be detected
     """
     # Calculate min_dist
     # Create world
     total_cells=50
     w = world.World(total_cells_desired=total_cells)
     starting_node = random.choice(w.all_boundary_nodes)
     for node in w.all_boundary_nodes:
         # Confirm node has neighbours
         self.assertGreater(len(starting_node.neighbours), 0)
         for neighbour in node.neighbours:
             #print("{0} to {1}".format(node.loc, neighbour.loc))
             angular_dist = math.degrees(geographic_utils.radians_between_locations(node.loc, neighbour.loc))
             node_cartesian_pos = geographic_utils.geographic_to_cartesian([np.array(node.loc)])[0]
             neighbour_cartesian_pos = geographic_utils.geographic_to_cartesian([np.array(neighbour.loc)])[0]
             direct_dist = vector_utils.cartesian_distance_2d(node_cartesian_pos, neighbour_cartesian_pos)
Exemple #2
0
 def refine_voronoi_nodes_around_locations(self, new_seed_locations, min_point_dist=0.01, min_angle=2,
                                           max_angle=15, num_child_points=20, failure_limit=5, num_adjacent=1):
     """
     Regenerates voronoi boundary nodes, attempting to add more seed_points around the given location. If
     min_point_dist is smaller than the value originally given when creating World then the cells will be
     smaller/higher resolution, therefore adding detail to the map at the given location.
     Process involves using existing cell centres as seed_points for voronoi process, but adding adding
     additional
     :param new_seed_points: list of [lon,lat] locations to place new sites around i.e. [[lon1, lat1], [lon2, lat2]]
     :param min_point_dist:
     :return:
     """
     cartesian_seed_points = geographic_utils.geographic_to_cartesian(new_seed_locations)
     # Populate self.voronoi_sites with (more) points that will create cells
     pdp.poisson_disk_placement_on_sphere_given_seed_points(self.voronoi_sites, cartesian_seed_points,
                                         min_point_dist, min_angle, max_angle,
                                         num_child_points, failure_limit, num_adjacent)
     # Re-initiate voronoi process
     self.generate_voronoi_nodes()
Exemple #3
0
    def test_geographic_to_cartesian(self):
        north_pole = [0,90]
        south_pole = [0,-90]
        equatorial_loc_a = [0,0] # Near Sao Tome and Principe
        equatorial_loc_b = [180, 0] # Near Phoenix Islands, Pacific Ocean
        equatorial_loc_c = [90,0] # Near Malaysia
        equatorial_loc_d = [-90,0] # Near Galapagos Islands

        geo_locs = [north_pole, south_pole, equatorial_loc_a, equatorial_loc_b, equatorial_loc_c, equatorial_loc_d]
        cart_points = geographic_utils.geographic_to_cartesian(geo_locs)

        coord_pairs = list()
        coord_pairs.append([cart_points[0], [0,0,1]])
        coord_pairs.append([cart_points[0], [0,0,1]])
        coord_pairs.append([cart_points[1], [0,0,-1]])
        coord_pairs.append([cart_points[2], [1,0,0]])
        coord_pairs.append([cart_points[3], [-1,0,0]])
        coord_pairs.append([cart_points[4], [0,1,0]])
        coord_pairs.append([cart_points[5], [0,-1,0]])
        for pair in coord_pairs:
            for i in range(3):
                self.assertAlmostEqual(pair[0][i], pair[1][i])