Example #1
0
 def test_angle_between_radian_positions(self):
     """ Test spherepoints.radians_between_locations(x) returns correct result (within 7dp) """
     samples = 6
     first_loc = [0,0]
     for i in range(0, samples+1):
         r = (math.pi / samples) * i
         # Test x
         second_loc = [math.degrees(r), 0]
         radians_between_locations = geographic_utils.radians_between_locations(first_loc, second_loc)
         self.assertAlmostEqual(r, radians_between_locations)
         # Test y
         second_loc = [0, math.degrees(r)]
         radians_between_locations = geographic_utils.radians_between_locations(first_loc, second_loc)
         self.assertAlmostEqual(r, radians_between_locations)
Example #2
0
 def test_distance_between_location_methods(self):
     """
     Test if two functions for calculating distance between two coordinate locations produces equal results
     """
     pairs = list()
     pairs.append([[0,0], [0,0]])
     pairs.append([[0,90], [0,0]])
     pairs.append([[0,0], [0,90]])
     pairs.append([[0,-90], [0,0]])
     pairs.append([[0,0], [0,-90]])
     pairs.append([[45,0], [0,0]])
     pairs.append([[0,0], [180,0]])
     pairs.append([[180,0], [-180,0]])
     pairs.append([[24,-89], [-100,-5]])
     for pair in pairs:
         d1 = geographic_utils.distance_between_locations(pair[0], pair[1])
         d2 = geographic_utils.radians_between_locations(pair[0], pair[1])
         self.assertAlmostEqual(d1, d2)
Example #3
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)
Example #4
0
 def angular_distance_criteria_function(node):
     dist = degrees(geographic_utils.radians_between_locations(starting_location, node.loc))
     #print("Distance criteria: {0} to {1} is {2} ({3} max allowed)".format(starting_location, node.loc, dist, max_distance))
     return  dist <= max_distance