Пример #1
0
    def test_fit_arc_to_points(self):
        LATS_0 = np.zeros(4, dtype=np.float)
        LONS_0 = np.array([0.0, 1.0, 2.0, 3.0])

        # Test points along arc
        ecef_points_0 = calculate_EcefPoints(LATS_0, LONS_0)
        ecef_arc_0 = EcefArc(ecef_points_0[0], ecef_points_0[-1])
        new_arc_0 = fit_arc_to_points(ecef_points_0, ecef_arc_0)
        assert_array_almost_equal(new_arc_0.a, ecef_arc_0.a)
        assert_array_almost_equal(new_arc_0.b, ecef_arc_0.b)

        # Test slope away from start of arc
        ecef_points_1 = calculate_EcefPoints(LONS_0, LONS_0)
        ecef_arc_1 = EcefArc(ecef_points_1[0], ecef_points_1[-1])

        new_arc_1 = fit_arc_to_points(ecef_points_1, ecef_arc_0)
        assert_array_almost_equal(new_arc_1.a, ecef_arc_0.a)
        assert_array_almost_equal(new_arc_1.pole, ecef_arc_1.pole)

        # Test slope towards end of arc
        LATS_2 = np.array([3.0, 2.0, 1.0, 0.0])
        ecef_points_2 = calculate_EcefPoints(LATS_2, LONS_0)
        ecef_arc_2 = EcefArc(ecef_points_2[0], ecef_points_2[-1])

        new_arc_2 = fit_arc_to_points(ecef_points_2, ecef_arc_0)
        assert_array_almost_equal(new_arc_2.pole, ecef_arc_2.pole)
        assert_array_almost_equal(new_arc_2.b, ecef_arc_0.b)
Пример #2
0
    def test_find_extreme_point_index_3(self):
        # A line of Lat Longs around the Equator
        LATITUDES = np.zeros(10, dtype=float)
        LONGITUDES = np.array(range(-5, 5), dtype=float)
        ecef_points_0 = calculate_EcefPoints(LATITUDES, LONGITUDES)

        # same point
        max_index = len(ecef_points_0) - 1
        result_0 = find_extreme_point_index(ecef_points_0,
                                            0,
                                            max_index,
                                            threshold=ACROSS_TRACK_TOLERANCE,
                                            xtd_ratio=0.1,
                                            calc_along_track=True)
        self.assertEqual(result_0, max_index)

        # route "doubles back" on itself
        LONGITUDES[-1] = LONGITUDES[-3]
        ecef_points_1 = calculate_EcefPoints(LATITUDES, LONGITUDES)
        result_1 = find_extreme_point_index(ecef_points_1,
                                            0,
                                            max_index,
                                            threshold=ACROSS_TRACK_TOLERANCE,
                                            xtd_ratio=0.1,
                                            calc_along_track=True)
        self.assertEqual(result_1, max_index - 1)
Пример #3
0
    def test_find_extreme_point_indicies(self):
        # A line of Lat Longs around the Equator
        LATITUDES = np.zeros(10, dtype=float)
        LONGITUDES = np.array([-5 + i for i in range(10)], dtype=float)
        ecef_points_0 = calculate_EcefPoints(LATITUDES, LONGITUDES)

        indicies_0 = find_extreme_point_indicies(
            ecef_points_0, threshold=ACROSS_TRACK_TOLERANCE, xtd_ratio=0.1)

        self.assertEqual(len(indicies_0), 2)
        assert_array_almost_equal(indicies_0, [0, 9])

        LATITUDES[4] = 1
        LATITUDES[8] = -1
        ecef_points_1 = calculate_EcefPoints(LATITUDES, LONGITUDES)

        indicies_1 = find_extreme_point_indicies(
            ecef_points_1, threshold=ACROSS_TRACK_TOLERANCE, xtd_ratio=0.1)
        self.assertEqual(len(indicies_1), 7)
        assert_array_almost_equal(indicies_1, [0, 3, 4, 5, 7, 8, 9])

        indicies_3 = find_extreme_point_indicies(ecef_points_1,
                                                 threshold=np.deg2rad(1.0),
                                                 xtd_ratio=0.1)
        self.assertEqual(len(indicies_3), 7)
Пример #4
0
    def test_find_extreme_point_along_track_index(self):
        # A line of Lat Longs around the Equator
        LATITUDES = np.zeros(10, dtype=float)
        LONGITUDES = np.array(range(-5, 5), dtype=float)
        ecef_points_0 = calculate_EcefPoints(LATITUDES, LONGITUDES)

        # All points within arc
        arc = EcefArc(ecef_points_0[0], ecef_points_0[-1])
        index_0 = find_extreme_point_along_track_index(arc, ecef_points_0,
                                                       1.0 * NM)
        self.assertEqual(index_0, 0)

        # Point 2 before start of arc
        LONGITUDES[2] = -6
        ecef_points_1 = calculate_EcefPoints(LATITUDES, LONGITUDES)
        index_1 = find_extreme_point_along_track_index(arc, ecef_points_1,
                                                       1.0 * NM)
        self.assertEqual(index_1, 2)

        # Point 8 past end of arc
        LONGITUDES[8] = 8
        ecef_points_2 = calculate_EcefPoints(LATITUDES, LONGITUDES)
        index_2 = find_extreme_point_along_track_index(arc, ecef_points_2,
                                                       1.0 * NM)
        self.assertEqual(index_2, 8)
Пример #5
0
    def test_EcefPath_turn_points(self):
        ecef_points = calculate_EcefPoints(ROUTE_LATS, ROUTE_LONS)

        ecef_path = EcefPath(ecef_points, TURN_DISTANCES)
        turn_points_0 = ecef_path.turn_points(number_of_points=0)
        self.assertEqual(len(turn_points_0), len(ecef_path) + 8)

        # Ensure that start and end points are along inbound and outboud arcs
        arc_1 = EcefArc(ecef_points[1], ecef_points[2])
        assert_almost_equal(arc_1.cross_track_distance(turn_points_0[2]), 0.0)

        arc_2 = EcefArc(ecef_points[2], ecef_points[3])
        assert_almost_equal(arc_2.cross_track_distance(turn_points_0[3]), 0.0)
        assert_almost_equal(arc_2.cross_track_distance(turn_points_0[4]), 0.0)

        arc_last = EcefArc(ecef_points[-2], ecef_points[-1])
        assert_almost_equal(arc_last.cross_track_distance(turn_points_0[-2]),
                            0.0)

        turn_points_1 = ecef_path.turn_points(number_of_points=1)
        self.assertEqual(len(turn_points_1), len(ecef_path) + 16)

        turn_points_3 = ecef_path.turn_points()
        self.assertEqual(len(turn_points_3), len(ecef_path) + 32)

        turn_points_5 = ecef_path.turn_points(number_of_points=5)
        self.assertEqual(len(turn_points_5), len(ecef_path) + 48)
Пример #6
0
    def test_find_extreme_point_index_2(self):
        # A line of Lat Longs by the Equator
        LATITUDES = np.array([0.0, -0.001, 0.01, -0.001, 0.0])
        LONGITUDES = np.array([0.0, 0.0005, 0.001, 0.0014, 0.0015])
        ecef_points_0 = calculate_EcefPoints(LATITUDES, LONGITUDES)

        # mid point
        max_index = len(ecef_points_0) - 1
        result_0 = find_extreme_point_index(ecef_points_0,
                                            0,
                                            max_index,
                                            threshold=ACROSS_TRACK_TOLERANCE,
                                            xtd_ratio=0.1,
                                            calc_along_track=False)
        self.assertEqual(result_0, 2)

        # first half
        max_index = 2
        result_1 = find_extreme_point_index(ecef_points_0,
                                            0,
                                            max_index,
                                            threshold=ACROSS_TRACK_TOLERANCE,
                                            xtd_ratio=0.1,
                                            calc_along_track=False)
        self.assertEqual(result_1, 2)

        # second half
        max_index = len(ecef_points_0) - 1
        result_2 = find_extreme_point_index(ecef_points_0,
                                            2,
                                            max_index,
                                            threshold=ACROSS_TRACK_TOLERANCE,
                                            xtd_ratio=0.1,
                                            calc_along_track=False)
        self.assertEqual(result_2, max_index)
Пример #7
0
    def test_EcefPath_section_distances_and_types(self):
        ecef_points = calculate_EcefPoints(ROUTE_LATS, ROUTE_LONS)

        ecef_path = EcefPath(ecef_points, TURN_DISTANCES)

        path_distances = rad2nm(ecef_path.path_distances())

        distances, types = ecef_path.section_distances_and_types()
        self.assertEqual(len(distances), len(ecef_path) + 8)
        self.assertEqual(len(types), len(ecef_path) + 8)

        self.assertEqual(distances[0], 0.0)
        self.assertEqual(types[0], PointType.Waypoint)

        self.assertEqual(distances[1], path_distances[1])
        self.assertEqual(types[1], PointType.Waypoint)

        self.assertTrue(distances[2] < path_distances[2])
        self.assertEqual(types[2], PointType.TurnStart)

        self.assertTrue(distances[3] > path_distances[2])
        self.assertEqual(types[3], PointType.TurnFinish)

        self.assertEqual(distances[-2], path_distances[-2])
        self.assertEqual(types[-2], PointType.Waypoint)

        self.assertEqual(distances[-1], path_distances[-1])
        self.assertEqual(types[-1], PointType.Waypoint)
Пример #8
0
    def test_calculate_path_cross_track_distance(self):
        ecef_points = calculate_EcefPoints(ROUTE_LATS, ROUTE_LONS)

        ecef_path = EcefPath(ecef_points, TURN_DISTANCES)

        assert_almost_equal(
            ecef_path.calculate_path_cross_track_distance(ecef_points[0], 0),
            0.0)
        assert_almost_equal(
            ecef_path.calculate_path_cross_track_distance(ecef_points[1], 1),
            0.0)

        xtd_2_1 = ecef_path.calculate_path_cross_track_distance(
            ecef_points[2], 1)
        assert_almost_equal(rad2nm(xtd_2_1), 4.1416795658323213)

        xtd_2_2 = ecef_path.calculate_path_cross_track_distance(
            ecef_points[2], 2)
        assert_almost_equal(rad2nm(xtd_2_2), 4.1416795658323213)

        xtd_3_2 = ecef_path.calculate_path_cross_track_distance(
            ecef_points[3], 2)
        assert_almost_equal(rad2nm(xtd_3_2), 8.2824069920496726)

        xtd_3_3 = ecef_path.calculate_path_cross_track_distance(
            ecef_points[3], 3)
        assert_almost_equal(rad2nm(xtd_3_3), 8.2824069920496726)
Пример #9
0
    def test_calculate_turn_initiation_distance_20(self):
        # A shallow turn at the Equator
        LATS = np.array([0.0, 0.0, 0.2])
        LONS = np.array([-1.0, 0.0, 1.0])
        ecef_points = calculate_EcefPoints(LATS, LONS)

        prev_arc = EcefArc(ecef_points[0], ecef_points[1])
        arc = EcefArc(ecef_points[1], ecef_points[2])
        TEN_NM = TWENTY_NM / 2
        turn_0 = TurnArc(prev_arc, arc, TEN_NM)
        turn_angle_0 = turn_0.angle

        distance_start = calculate_turn_initiation_distance(
            prev_arc, arc, turn_0.start, TWENTY_NM, ACROSS_TRACK_TOLERANCE)
        assert_almost_equal(distance_start, TEN_NM)

        distance_finish = calculate_turn_initiation_distance(
            prev_arc, arc, turn_0.finish, TWENTY_NM, ACROSS_TRACK_TOLERANCE)
        assert_almost_equal(distance_finish, TEN_NM)

        point_1 = turn_0.position(turn_angle_0 / 2)
        distance_1 = calculate_turn_initiation_distance(
            prev_arc, arc, point_1, TWENTY_NM, ACROSS_TRACK_TOLERANCE)
        assert_almost_equal(distance_1, TEN_NM, decimal=6)

        point_2 = turn_0.position(turn_angle_0 / 4)
        distance_2 = calculate_turn_initiation_distance(
            prev_arc, arc, point_2, TWENTY_NM, ACROSS_TRACK_TOLERANCE / 4)
        assert_almost_equal(distance_2, TEN_NM, decimal=6)

        point_3 = turn_0.position(3 * turn_angle_0 / 4)
        distance_3 = calculate_turn_initiation_distance(
            prev_arc, arc, point_3, TWENTY_NM, ACROSS_TRACK_TOLERANCE / 4)
        assert_almost_equal(distance_3, TEN_NM, decimal=5)
Пример #10
0
    def test_EcefPath_init(self):
        ecef_points = calculate_EcefPoints(ROUTE_LATS, ROUTE_LONS)

        ecef_path = EcefPath(ecef_points, TURN_DISTANCES)

        self.assertEqual(len(ecef_path.points), 12)
        assert_array_almost_equal(ecef_path.points, ecef_points)
        self.assertEqual(len(ecef_path.turn_initiation_distances), 12)
        assert_array_almost_equal(ecef_path.turn_initiation_distances,
                                  TURN_DISTANCES)
        self.assertEqual(len(ecef_path.leg_lengths), 12)
        assert_array_almost_equal(rad2nm(ecef_path.leg_lengths),
                                  EXPECTED_LEG_LENGTHS)
        self.assertEqual(len(ecef_path.turn_angles), 12)
        assert_array_almost_equal(np.rad2deg(ecef_path.turn_angles),
                                  EXPECTED_TURN_ANGLES)
        self.assertEqual(len(ecef_path.path_lengths), 12)
        assert_array_almost_equal(rad2nm(ecef_path.path_lengths),
                                  EXPECTED_PATH_LENGTHS)

        lats, lons = ecef_path.point_lat_longs()
        assert_array_almost_equal(lats, ROUTE_LATS)
        assert_array_almost_equal(lons, ROUTE_LONS)

        assert_array_almost_equal(ecef_path.turn_initiation_distances_nm(),
                                  rad2nm(TURN_DISTANCES))
Пример #11
0
    def test_EcefPath_calculate_position(self):
        ecef_points = calculate_EcefPoints(ROUTE_LATS, ROUTE_LONS)

        ecef_path = EcefPath(ecef_points, TURN_DISTANCES)

        pos_0 = ecef_path.calculate_position(0, 0.0)
        assert_array_almost_equal(pos_0, ecef_points[0])

        pos_1 = ecef_path.calculate_position(1, 0.0)
        assert_array_almost_equal(pos_1, ecef_points[1])

        arc2 = EcefArc(ecef_points[1], ecef_points[2])
        arc3 = EcefArc(ecef_points[2], ecef_points[3])

        turn_arc2 = TurnArc(arc2, arc3, TURN_DISTANCES[2])
        turn2_midpoint = EcefPoint(
            turn_arc2.position(0.5 * abs(turn_arc2.angle)))

        pos_2 = ecef_path.calculate_position(2, 0.000001)
        assert_array_almost_equal(pos_2, turn2_midpoint)

        pos_1_99999 = ecef_path.calculate_position(1, 0.99999)
        assert_array_almost_equal(pos_1_99999, pos_2)

        pos_13 = ecef_path.calculate_position(13, 0.0)
        assert_array_almost_equal(pos_13, ecef_points[-1])
Пример #12
0
 def test_EcefPath_invalid_init(self):
     'The route has a duplicate point in the middle, so closer than MIN_LENGTH'
     INVALID_ROUTE_LATS = np.array([1.0, 1.0, 1.0, 1.0, -1.0, 1.0])
     INVALID_ROUTE_LONS = np.array([-3.0, -2.0, -1.0, -1.0, 1.0, 0.0])
     invalid_points = calculate_EcefPoints(INVALID_ROUTE_LATS,
                                           INVALID_ROUTE_LONS)
     zero_distances = np.zeros(len(invalid_points), dtype=float)
     self.assertRaises(ValueError, EcefPath, invalid_points, zero_distances)
Пример #13
0
    def test_derive_horizontal_path(self):
        test_data_home = env.get('TEST_DATA_HOME')
        self.assertTrue(test_data_home)

        ecef_points = calculate_EcefPoints(ROUTE_LATS, ROUTE_LONS)
        ecef_path = derive_horizontal_path(ecef_points, ACROSS_TRACK_TOLERANCE)
        self.assertEqual(len(ecef_path), 12)
        assert_array_almost_equal(ecef_path.points[0], ecef_points[0])
        assert_array_almost_equal(ecef_path.points[-1], ecef_points[-1])
Пример #14
0
    def test_EcefPath_path_distances(self):
        ecef_points = calculate_EcefPoints(ROUTE_LATS, ROUTE_LONS)

        ecef_path = EcefPath(ecef_points, TURN_DISTANCES)

        path_distances = ecef_path.path_distances()
        self.assertEqual(len(path_distances), 12)

        assert_array_almost_equal(rad2nm(path_distances),
                                  EXPECTED_PATH_DISTANCES)
Пример #15
0
    def test_EcefPath_calculate_ground_tracks(self):
        ecef_points = calculate_EcefPoints(ROUTE_LATS, ROUTE_LONS)

        ecef_path = EcefPath(ecef_points, TURN_DISTANCES)

        distances, types = ecef_path.section_distances_and_types()

        ground_tracks = ecef_path.calculate_ground_tracks(distances)
        self.assertEqual(len(ground_tracks), len(ecef_path) + 8)
        assert_almost_equal(ground_tracks[0], np.pi / 2, decimal=3)
Пример #16
0
    def test_EcefPath_calculate_path_leg_distance(self):
        ecef_points = calculate_EcefPoints(ROUTE_LATS, ROUTE_LONS)

        ecef_path = EcefPath(ecef_points, TURN_DISTANCES)

        # Start point
        distance_0 = ecef_path.calculate_path_leg_distance(ecef_points[0], 0)
        self.assertEqual(distance_0, 0.0)

        # Point at end of a straight leg
        distance_1_0 = ecef_path.calculate_path_leg_distance(ecef_points[1], 0)
        assert_almost_equal(rad2nm(distance_1_0), EXPECTED_PATH_LENGTHS[1])

        # Point at start of a straight leg
        distance_1_1 = ecef_path.calculate_path_leg_distance(ecef_points[1], 1)
        self.assertEqual(distance_0, 0.0)

        # Point in middle of a straight leg
        pos_1_5 = ecef_path.calculate_position(1, 0.5)
        distance_1_5 = ecef_path.calculate_path_leg_distance(pos_1_5, 1)
        assert_almost_equal(rad2nm(distance_1_5),
                            0.5 * EXPECTED_PATH_LENGTHS[2])

        # Point toward end of a turning leg
        pos_1_9 = ecef_path.calculate_position(1, 0.99)
        distance_1_9 = ecef_path.calculate_path_leg_distance(pos_1_9, 1)
        assert_almost_equal(rad2nm(distance_1_9),
                            0.99 * EXPECTED_PATH_LENGTHS[2])

        # Before start of a turning leg
        distance_2_9 = ecef_path.calculate_path_leg_distance(pos_1_9, 2)
        assert_almost_equal(rad2nm(distance_2_9), -0.57845277761762326)

        # Point toward start of a turning leg
        pos_2_1 = ecef_path.calculate_position(2, 0.01)
        distance_2_1 = ecef_path.calculate_path_leg_distance(pos_2_1, 2)
        assert_almost_equal(rad2nm(distance_2_1),
                            0.01 * EXPECTED_PATH_LENGTHS[3])

        # Past the ned of a turning leg
        distance_1_2 = ecef_path.calculate_path_leg_distance(pos_2_1, 1)
        self.assertTrue(rad2nm(distance_1_2) > EXPECTED_PATH_LENGTHS[2])
        assert_almost_equal(rad2nm(distance_1_2), 58.980918943627351)

        # Point along a turning leg
        pos_2_75 = ecef_path.calculate_position(2, 0.75)
        distance_2_75 = ecef_path.calculate_path_leg_distance(pos_2_75, 2)
        assert_almost_equal(rad2nm(distance_2_75),
                            0.75 * EXPECTED_PATH_LENGTHS[3])

        # Last point
        distance_last = ecef_path.calculate_path_leg_distance(
            ecef_points[-1], 10)
        assert_almost_equal(rad2nm(distance_last), EXPECTED_PATH_LENGTHS[11])
Пример #17
0
    def test_EcefPath_calculate_path_distances(self):
        ecef_points = calculate_EcefPoints(ROUTE_LATS, ROUTE_LONS)

        ecef_path = EcefPath(ecef_points, TURN_DISTANCES)

        distances = rad2nm(
            ecef_path.calculate_path_distances(ecef_points,
                                               ACROSS_TRACK_TOLERANCE))
        self.assertEqual(len(distances), len(ecef_points))
        self.assertEqual(distances[0], 0.0)
        assert_almost_equal(distances[11],
                            EXPECTED_PATH_DISTANCES[11],
                            decimal=6)
        assert_array_almost_equal(distances, EXPECTED_PATH_DISTANCES)
Пример #18
0
    def test_EcefPath_calculate_positions(self):
        ecef_points = calculate_EcefPoints(ROUTE_LATS, ROUTE_LONS)

        ecef_path = EcefPath(ecef_points, TURN_DISTANCES)

        distances, types = ecef_path.section_distances_and_types()

        positions = ecef_path.calculate_positions(distances)
        self.assertEqual(len(positions), len(ecef_path) + 8)

        assert_array_almost_equal(positions[0], ecef_points[0])
        assert_array_almost_equal(positions[1], ecef_points[1])
        assert_array_almost_equal(positions[-2], ecef_points[-2])
        assert_array_almost_equal(positions[-1], ecef_points[-1])
Пример #19
0
    def test_EcefPath_calculate_ground_track(self):
        ecef_points = calculate_EcefPoints(ROUTE_LATS, ROUTE_LONS)

        ecef_path = EcefPath(ecef_points, TURN_DISTANCES)

        track_0 = ecef_path.calculate_ground_track(0, 0.0)
        assert_almost_equal(track_0, np.pi / 2, decimal=3)  # close to due East

        track_2_5 = ecef_path.calculate_ground_track(2, 0.5)
        assert_almost_equal(track_2_5, np.pi)  # due south

        track_2_0 = ecef_path.calculate_ground_track(2, 0.0)
        assert_almost_equal(track_2_0, 0.75 * np.pi, decimal=3)  # South East

        track_12_0 = ecef_path.calculate_ground_track(12, 0.0)
        assert_almost_equal(track_12_0, 0.0)  # North
Пример #20
0
    def test_calculate_turn_initiation_distance_90(self):
        # A 90 degree turn at the Equator
        LATS = np.array([0.0, 0.0, 1.0])
        LONS = np.array([1.0, 0.0, 0.0])
        ecef_points = calculate_EcefPoints(LATS, LONS)

        prev_arc = EcefArc(ecef_points[0], ecef_points[1])
        arc = EcefArc(ecef_points[1], ecef_points[2])
        TEN_NM = TWENTY_NM / 2
        turn_0 = TurnArc(prev_arc, arc, TEN_NM)
        turn_angle_0 = turn_0.angle

        distance_start = calculate_turn_initiation_distance(
            prev_arc, arc, turn_0.start, TWENTY_NM, ACROSS_TRACK_TOLERANCE)
        assert_almost_equal(distance_start, TEN_NM)

        distance_finish = calculate_turn_initiation_distance(
            prev_arc, arc, turn_0.finish, TWENTY_NM, ACROSS_TRACK_TOLERANCE)
        assert_almost_equal(distance_finish, TEN_NM)

        point_1 = turn_0.position(turn_angle_0 / 2)
        distance_1 = calculate_turn_initiation_distance(
            prev_arc, arc, point_1, TWENTY_NM, ACROSS_TRACK_TOLERANCE)
        assert_almost_equal(distance_1, TEN_NM)

        point_2 = turn_0.position(turn_angle_0 / 4)
        distance_2 = calculate_turn_initiation_distance(
            prev_arc, arc, point_2, TWENTY_NM, ACROSS_TRACK_TOLERANCE)
        assert_almost_equal(distance_2, TEN_NM)

        point_3 = turn_0.position(3 * turn_angle_0 / 4)
        distance_3 = calculate_turn_initiation_distance(
            prev_arc, arc, point_3, TWENTY_NM, ACROSS_TRACK_TOLERANCE)
        assert_almost_equal(distance_3, TEN_NM)

        # Test with a point further than TWENTY_NM from the intersection
        turn_30 = TurnArc(prev_arc, arc, TWENTY_NM + TEN_NM)
        distance_4 = calculate_turn_initiation_distance(
            prev_arc, arc, turn_30.start, TWENTY_NM, ACROSS_TRACK_TOLERANCE)
        self.assertEqual(distance_4, TWENTY_NM)

        point_30 = turn_30.position(3 * turn_angle_0 / 4)
        distance_30 = calculate_turn_initiation_distance(
            prev_arc, arc, point_30, TWENTY_NM, ACROSS_TRACK_TOLERANCE)
        self.assertEqual(distance_30, TWENTY_NM)
Пример #21
0
    def test_EcefPath_calculate_cross_track_distances(self):
        ecef_points = calculate_EcefPoints(ROUTE_LATS, ROUTE_LONS)

        ecef_path = EcefPath(ecef_points, TURN_DISTANCES)

        distances = rad2nm(
            ecef_path.calculate_path_distances(ecef_points,
                                               ACROSS_TRACK_TOLERANCE))
        self.assertEqual(len(distances), len(ecef_points))

        xtds = ecef_path.calculate_cross_track_distances(
            ecef_points, distances)
        self.assertEqual(len(xtds), len(ecef_points))
        assert_almost_equal(xtds[0], 0.0)
        assert_almost_equal(xtds[1], 0.0)
        assert_almost_equal(xtds[2], 4.1416795658323213)  # 10NM TID
        assert_almost_equal(xtds[3], 8.2824069920496726)  # 20NM TID
        assert_almost_equal(xtds[-1], 0.0)
Пример #22
0
    def test_EcefPath_subsection_positions(self):
        ecef_points = calculate_EcefPoints(ROUTE_LATS, ROUTE_LONS)

        ecef_path = EcefPath(ecef_points, TURN_DISTANCES)

        positions0 = ecef_path.subsection_positions(0, 1040.0)
        self.assertEqual(len(positions0), len(ecef_path))
        assert_array_almost_equal(positions0[0], ecef_points[0])
        assert_array_almost_equal(positions0[-1], ecef_points[-1])

        positions1 = ecef_path.subsection_positions(0, 1000.0)
        self.assertEqual(len(positions1), len(ecef_path))
        assert_array_almost_equal(positions1[0], ecef_points[0])
        assert_array_almost_equal(positions1[-2], ecef_points[-2])

        positions2 = ecef_path.subsection_positions(100.0, 1040.0)
        self.assertEqual(len(positions2), len(ecef_path) - 1)
        assert_array_almost_equal(positions2[1], ecef_points[2])
        assert_array_almost_equal(positions2[-1], ecef_points[-1])
Пример #23
0
    def test_calculate_intersection(self):
        ecef_points = calculate_EcefPoints(ROUTE_LATS, ROUTE_LONS)

        # intersection point between arcs on different Great Circles
        prev_arc = EcefArc(ecef_points[0], ecef_points[1])
        arc = EcefArc(ecef_points[1], ecef_points[2])
        point_1 = calculate_intersection(prev_arc, arc)
        assert_array_almost_equal(point_1, ecef_points[1])

        # intersection point between arcs on same Great Circles
        next_point = arc.position(2 * arc.length)
        next_arc = EcefArc(ecef_points[2], next_point)
        point_2 = calculate_intersection(arc, next_arc)
        assert_array_almost_equal(point_2, ecef_points[2])

        # intersection point between arcs on different Great Circles,
        # opposite direction turn
        prev_arc = EcefArc(ecef_points[5], ecef_points[6])
        arc = EcefArc(ecef_points[6], ecef_points[7])
        point_3 = calculate_intersection(prev_arc, arc)
        assert_array_almost_equal(point_3, ecef_points[6])
Пример #24
0
    def test_find_extreme_point_index_1(self):
        # A line of Lat Longs around the Equator
        LATITUDES = np.zeros(10, dtype=float)
        LONGITUDES = np.array(range(-5, 5), dtype=float)
        ecef_points_0 = calculate_EcefPoints(LATITUDES, LONGITUDES)

        # same point
        max_index = 0
        result_0 = find_extreme_point_index(ecef_points_0,
                                            0,
                                            max_index,
                                            threshold=ACROSS_TRACK_TOLERANCE,
                                            xtd_ratio=0.1,
                                            calc_along_track=False)
        self.assertEqual(result_0, max_index)

        # adjacent points
        max_index = 1
        result_1 = find_extreme_point_index(ecef_points_0,
                                            0,
                                            max_index,
                                            threshold=ACROSS_TRACK_TOLERANCE,
                                            xtd_ratio=0.1,
                                            calc_along_track=False)
        self.assertEqual(result_1, max_index)

        # a point inbetween points
        max_index = 2
        result_2 = find_extreme_point_index(ecef_points_0,
                                            0,
                                            max_index,
                                            threshold=ACROSS_TRACK_TOLERANCE,
                                            xtd_ratio=0.1,
                                            calc_along_track=False)
        self.assertEqual(result_2, max_index)

        # test toward the end
        max_index = 8
        max_index_0 = find_extreme_point_index(
            ecef_points_0,
            2,
            max_index,
            threshold=ACROSS_TRACK_TOLERANCE,
            xtd_ratio=0.1,
            calc_along_track=False)
        self.assertEqual(max_index_0, max_index)

        # move some points alongside the arc
        LATITUDES[1] = 0.5
        LATITUDES[4] = 1
        ecef_points_1 = calculate_EcefPoints(LATITUDES, LONGITUDES)

        max_index = 2
        result_2 = find_extreme_point_index(ecef_points_1,
                                            0,
                                            max_index,
                                            threshold=ACROSS_TRACK_TOLERANCE,
                                            xtd_ratio=0.1,
                                            calc_along_track=False)
        self.assertEqual(result_2, 1)

        max_index = 8
        max_index_1 = find_extreme_point_index(
            ecef_points_1,
            0,
            max_index,
            threshold=ACROSS_TRACK_TOLERANCE,
            xtd_ratio=0.1,
            calc_along_track=False)
        self.assertEqual(max_index_1, 4)

        LATITUDES[4] = -1
        ecef_points_2 = calculate_EcefPoints(LATITUDES, LONGITUDES)
        max_index_2 = find_extreme_point_index(
            ecef_points_2,
            2,
            max_index,
            threshold=ACROSS_TRACK_TOLERANCE,
            xtd_ratio=0.1,
            calc_along_track=False)
        self.assertEqual(max_index_2, 4)

        max_index_3 = find_extreme_point_index(ecef_points_2,
                                               2,
                                               max_index,
                                               threshold=np.deg2rad(1.0),
                                               xtd_ratio=0.1,
                                               calc_along_track=False)
        self.assertEqual(max_index_3, 4)

        SHORT_LONGITUDES = np.array([-5 + i / 600.0 for i in range(10)],
                                    dtype=float)
        ecef_points_4 = calculate_EcefPoints(LATITUDES, SHORT_LONGITUDES)

        max_index_4 = find_extreme_point_index(
            ecef_points_4,
            2,
            max_index,
            threshold=ACROSS_TRACK_TOLERANCE,
            xtd_ratio=0.1,
            calc_along_track=False)
        self.assertEqual(max_index_2, 4)
Пример #25
0
    def test_EcefPath_calculate_path_distance(self):
        ecef_points = calculate_EcefPoints(ROUTE_LATS, ROUTE_LONS)

        ecef_path = EcefPath(ecef_points, TURN_DISTANCES)

        # Start point
        distance_0 = ecef_path.calculate_path_distance(ecef_points[0], 0,
                                                       ACROSS_TRACK_TOLERANCE)
        self.assertEqual(distance_0, 0.0)

        # from next leg
        distance_0 = ecef_path.calculate_path_distance(ecef_points[0], 1,
                                                       ACROSS_TRACK_TOLERANCE)
        self.assertEqual(distance_0, 0.0)

        # Point at end of first, straight leg
        distance_1_0 = ecef_path.calculate_path_distance(
            ecef_points[1], 0, ACROSS_TRACK_TOLERANCE)
        assert_almost_equal(rad2nm(distance_1_0), EXPECTED_PATH_DISTANCES[1])

        # from next leg
        distance_1_0 = ecef_path.calculate_path_distance(
            ecef_points[1], 1, ACROSS_TRACK_TOLERANCE)
        assert_almost_equal(rad2nm(distance_1_0), EXPECTED_PATH_DISTANCES[1])

        # from leg after next
        distance_1_0 = ecef_path.calculate_path_distance(
            ecef_points[1], 2, ACROSS_TRACK_TOLERANCE)
        assert_almost_equal(rad2nm(distance_1_0), EXPECTED_PATH_DISTANCES[1])

        # Point in middle of first,  straight leg
        pos_1_5 = ecef_path.calculate_position(1, 0.5)
        distance_1_5 = ecef_path.calculate_path_distance(
            pos_1_5, 1, ACROSS_TRACK_TOLERANCE)
        assert_almost_equal(
            rad2nm(distance_1_5),
            EXPECTED_PATH_DISTANCES[1] + 0.5 * EXPECTED_PATH_LENGTHS[2])

        # from previous leg
        distance_1_5 = ecef_path.calculate_path_distance(
            pos_1_5, 0, ACROSS_TRACK_TOLERANCE)
        assert_almost_equal(
            rad2nm(distance_1_5),
            EXPECTED_PATH_DISTANCES[1] + 0.5 * EXPECTED_PATH_LENGTHS[2])

        # from next leg
        distance_1_5 = ecef_path.calculate_path_distance(
            pos_1_5, 2, ACROSS_TRACK_TOLERANCE)
        assert_almost_equal(
            rad2nm(distance_1_5),
            EXPECTED_PATH_DISTANCES[1] + 0.5 * EXPECTED_PATH_LENGTHS[2])

        # Point along a turning leg
        pos_2_75 = ecef_path.calculate_position(2, 0.75)
        distance_2_75 = ecef_path.calculate_path_distance(
            pos_2_75, 2, ACROSS_TRACK_TOLERANCE)
        assert_almost_equal(
            rad2nm(distance_2_75),
            EXPECTED_PATH_DISTANCES[2] + 0.75 * EXPECTED_PATH_LENGTHS[3])

        # Last point
        distance_last = ecef_path.calculate_path_distance(
            ecef_points[-1], 10, ACROSS_TRACK_TOLERANCE)
        assert_almost_equal(rad2nm(distance_last),
                            EXPECTED_PATH_DISTANCES[11],
                            decimal=6)

        # from previous leg
        distance_last = ecef_path.calculate_path_distance(
            ecef_points[-1], 9, ACROSS_TRACK_TOLERANCE)
        assert_almost_equal(rad2nm(distance_last),
                            EXPECTED_PATH_DISTANCES[11],
                            decimal=6)
Пример #26
0
    def test_find_furthest_distance(self):
        ecef_points = calculate_EcefPoints(ROUTE_LATS, ROUTE_LONS)

        # Test North pole to South pole
        distance1, index1 = find_furthest_distance(ecef_points)
        self.assertEqual(index1, 11)
Пример #27
0
    def test_EcefPath_find_index_and_ratio(self):
        ecef_points = calculate_EcefPoints(ROUTE_LATS, ROUTE_LONS)

        ecef_path = EcefPath(ecef_points, TURN_DISTANCES)

        # Start point
        index_0, ratio_0 = ecef_path.find_index_and_ratio(ecef_points[0])
        self.assertEqual(index_0, 0)
        self.assertEqual(ratio_0, 0.0)

        # Point at end of a straight leg
        pos_1 = ecef_points[1]
        index_1, ratio_1 = ecef_path.find_index_and_ratio(pos_1)
        self.assertEqual(index_1, 1)
        self.assertEqual(ratio_1, 0.0)

        # Point in middle of a straight leg
        pos_1_5 = ecef_path.calculate_position(1, 0.5)
        index_1_5, ratio_1_5 = ecef_path.find_index_and_ratio(pos_1_5)
        self.assertEqual(index_1_5, 1)
        assert_almost_equal(ratio_1_5, 0.5)

        # Point toward end of a turning leg
        pos_1_9 = ecef_path.calculate_position(1, 0.99)
        index_1_9, ratio_1_9 = ecef_path.find_index_and_ratio(pos_1_9)
        self.assertEqual(index_1_9, 1)
        assert_almost_equal(ratio_1_9, 0.99)

        # Point in middle of a turn
        pos_2 = ecef_path.calculate_position(2, 0.0)
        index_2, ratio_2 = ecef_path.find_index_and_ratio(pos_2)
        self.assertEqual(index_2, 2)
        assert_almost_equal(ratio_2, 0.0)

        # Point toward start of a turning leg
        pos_2_1 = ecef_path.calculate_position(2, 0.01)
        index_2_1, ratio_2_1 = ecef_path.find_index_and_ratio(pos_2_1)
        self.assertEqual(index_2_1, 2)
        assert_almost_equal(ratio_2_1, 0.01)

        # Point along a turning leg
        pos_2_25 = ecef_path.calculate_position(2, 0.25)
        index_2_25, ratio_2_25 = ecef_path.find_index_and_ratio(pos_2_25)
        self.assertEqual(index_2_25, 2)
        assert_almost_equal(ratio_2_25, 0.25)

        # Point in middle of a turning leg
        pos_2_5 = ecef_path.calculate_position(2, 0.5)
        index_2_5, ratio_2_5 = ecef_path.find_index_and_ratio(pos_2_5)
        self.assertEqual(index_2_5, 2)
        assert_almost_equal(ratio_2_5, 0.5)

        # Point along a turning leg
        pos_2_75 = ecef_path.calculate_position(2, 0.75)
        index_2_75, ratio_2_75 = ecef_path.find_index_and_ratio(pos_2_75)
        self.assertEqual(index_2_75, 2)
        assert_almost_equal(ratio_2_75, 0.75)

        # Finish point
        index_last, ratio_last = ecef_path.find_index_and_ratio(
            ecef_points[-1])
        self.assertEqual(index_last, 11)
        self.assertEqual(ratio_last, 0.0)

        # A waypoint not on path
        index_waypoint, ratio_waypoint = ecef_path.find_index_and_ratio(
            ecef_points[2])
        self.assertEqual(index_waypoint, 2)
        assert_almost_equal(ratio_waypoint, 0.0, decimal=6)