Ejemplo n.º 1
0
 def test_hash(self):
     a = EcefPoint(ECEF_ICOSAHEDRON[1])
     b = EcefPoint(ECEF_ICOSAHEDRON[10])
     self.assertTrue(hash(a) == hash(a))
     self.assertTrue(hash(b) == hash(b))
     self.assertFalse(hash(a) == hash(b))
     self.assertFalse(hash(b) == hash(a))
Ejemplo n.º 2
0
    def test_perp_position(self):
        ecef_equator_1 = EcefPoint([1.0, 0.0, 0.0])
        ecef_equator_2 = EcefPoint([0.0, 1.0, 0.0])
        arc = EcefArc(ecef_equator_1, ecef_equator_2)

        assert_array_almost_equal(arc.perp_position(ecef_equator_1, 0.0),
                                  ecef_equator_1)
        assert_array_almost_equal(arc.perp_position(ecef_equator_2, 0.0),
                                  ecef_equator_2)

        distance = np.deg2rad(1.0)
        perp_pos1 = arc.perp_position(ecef_equator_1, distance)
        assert_almost_equal(arc.along_track_distance(perp_pos1), 0.0)
        assert_almost_equal(arc.cross_track_distance(perp_pos1), distance)

        perp_pos2 = arc.perp_position(ecef_equator_1, -distance)
        assert_almost_equal(arc.along_track_distance(perp_pos2), 0.0)
        assert_almost_equal(arc.cross_track_distance(perp_pos2), -distance)

        perp_pos3 = arc.perp_position(ecef_equator_2, distance)
        assert_almost_equal(arc.along_track_distance(perp_pos3), arc.length)
        assert_almost_equal(arc.cross_track_distance(perp_pos3), distance)

        perp_pos4 = arc.perp_position(ecef_equator_2, -distance)
        assert_almost_equal(arc.along_track_distance(perp_pos4), arc.length)
        assert_almost_equal(arc.cross_track_distance(perp_pos4), -distance)
Ejemplo n.º 3
0
 def test_str(self):
     ecef_point_0 = EcefPoint(ECEF_ICOSAHEDRON[0])
     ecef_point_1 = EcefPoint(ECEF_ICOSAHEDRON[1])
     arc = EcefArc(ecef_point_0, ecef_point_1)
     self.assertEqual(
         'EcefArc([[ 0.  0.  1.]\n [ 0. -1.  0.]],1.1071487172337777)',
         str(arc))
Ejemplo n.º 4
0
    def test_calculate_ground_track(self):

        a = EcefPoint(ECEF_ICOSAHEDRON[1])
        b = EcefPoint(ECEF_ICOSAHEDRON[2])
        arc_1 = EcefArc(a, b)

        track_1a = arc_1.calculate_ground_track(arc_1.a)
        assert_almost_equal(np.rad2deg(track_1a), 72.0)
        track_1b = arc_1.calculate_ground_track(arc_1.b)
        assert_almost_equal(np.rad2deg(track_1b), 108.0)

        arc_2 = EcefArc(b, a)

        track_2a = arc_2.calculate_ground_track(arc_2.a)
        assert_almost_equal(np.rad2deg(track_2a), -72.0)
        track_2b = arc_2.calculate_ground_track(arc_2.b)
        assert_almost_equal(np.rad2deg(track_2b), -108.0)

        # North pole
        c = EcefPoint(ECEF_ICOSAHEDRON[0])
        arc_np = EcefArc(c, a)

        track_np_a = arc_np.calculate_ground_track(arc_np.a)
        self.assertEqual(track_np_a, np.pi)
        track_np_b = arc_np.calculate_ground_track(arc_np.b)
        self.assertEqual(track_np_b, np.pi)

        # South pole
        d = EcefPoint(ECEF_ICOSAHEDRON[-1])
        arc_sp = EcefArc(d, a)

        track_sp_a = arc_sp.calculate_ground_track(arc_sp.a)
        self.assertEqual(track_sp_a, 0.0)
        track_sp_b = arc_sp.calculate_ground_track(arc_sp.b)
        self.assertEqual(track_sp_b, 0.0)
Ejemplo n.º 5
0
 def test_repr(self):
     a = EcefPoint(ECEF_ICOSAHEDRON[1])
     self.assertEqual('EcefPoint([-0.89442719  0.          0.4472136 ])',
                      repr(a))
     b = EcefPoint(ECEF_ICOSAHEDRON[10])
     self.assertEqual('EcefPoint([ 0.2763932   0.85065081 -0.4472136 ])',
                      repr(b))
Ejemplo n.º 6
0
    def test_neg_and_pos(self):
        ecef_point = EcefPoint(ECEF_ICOSAHEDRON[0])
        ecef_point_anti = EcefPoint(ECEF_ICOSAHEDRON[11])
        assert_array_almost_equal(+ecef_point, ecef_point)
        assert_array_almost_equal(-ecef_point, ecef_point_anti)

        assert_array_almost_equal(+ecef_point_anti, ecef_point_anti)
        assert_array_almost_equal(-ecef_point_anti, ecef_point)
Ejemplo n.º 7
0
    def test_eq(self):
        a = EcefPoint(ECEF_ICOSAHEDRON[1])
        b = EcefPoint(ECEF_ICOSAHEDRON[10])

        self.assertTrue(a == a)
        self.assertTrue(b == b)
        self.assertFalse(a == b)
        self.assertFalse(b == a)
Ejemplo n.º 8
0
    def test_bool(self):
        ecef_point_0 = EcefPoint(ECEF_ICOSAHEDRON[0])
        ecef_point_1 = EcefPoint(ECEF_ICOSAHEDRON[1])
        a = EcefArc(ecef_point_0, ecef_point_1)
        b = EcefArc(ecef_point_1, ecef_point_1)  # a null arc

        self.assertTrue(a)
        self.assertFalse(b)
Ejemplo n.º 9
0
    def test_EcefPoint_to_lat_long(self):
        """Test conversion to Lat Longs using Icosahedron verticies."""
        for i in range(12):
            ecef_point = EcefPoint(ECEF_ICOSAHEDRON[i])
            lat_long = ecef_point.to_lat_long()

            expected_result = LAT_LONG_ICOSAHEDRON[i]
            assert_array_almost_equal(lat_long, expected_result)
Ejemplo n.º 10
0
    def test_eq(self):
        ecef_point_0 = EcefPoint(ECEF_ICOSAHEDRON[0])
        ecef_point_1 = EcefPoint(ECEF_ICOSAHEDRON[1])
        a = EcefArc(ecef_point_0, ecef_point_1)
        b = EcefArc(ecef_point_1, ecef_point_0)

        self.assertTrue(a == a)
        self.assertTrue(b == b)
        self.assertFalse(a == b)
        self.assertFalse(b == a)
Ejemplo n.º 11
0
    def test_add_and_sub(self):
        ecef_point1 = EcefPoint(ECEF_ICOSAHEDRON[1])
        ecef_point2 = EcefPoint(ECEF_ICOSAHEDRON[2])

        ecef_point_3 = ecef_point1 + ecef_point2
        assert_almost_equal(abs(ecef_point_3), 1.7013016170169837)

        ecef_point_4 = ecef_point_3 - ecef_point2
        assert_almost_equal(abs(ecef_point_4), 1.0)
        assert_array_almost_equal(ecef_point_4, ecef_point1)

        ecef_point_5 = ecef_point_3 - ecef_point1
        assert_almost_equal(abs(ecef_point_5), 1.0)
        assert_array_almost_equal(ecef_point_5, ecef_point2)
Ejemplo n.º 12
0
    def test_ecefArc_init(self):
        """Test initialisation of EcefArc class."""

        result_1 = np.arctan(2.0)
        for i in range(11):
            a = EcefPoint(ECEF_ICOSAHEDRON[i])
            b = EcefPoint(ECEF_ICOSAHEDRON[i + 1])
            arc = EcefArc(a, b)
            assert_array_almost_equal(arc.coords[0], a)
            assert_array_almost_equal(arc.a, a)
            assert_almost_equal(abs(EcefPoint(arc.pole)), 1.0)
            assert_almost_equal(result_1, arc.length)

        # Test zero length arc
        a = EcefPoint(ECEF_ICOSAHEDRON[5])
        arc = EcefArc(a, a)
        assert_array_almost_equal(arc.coords[0], a)
        assert_array_almost_equal(arc.a, a)
        self.assertFalse(EcefPoint(arc.pole))
        self.assertEqual(arc.length, 0.0)

        # Test antipodal points
        a = EcefPoint(ECEF_ICOSAHEDRON[0])
        b = EcefPoint(ECEF_ICOSAHEDRON[11])
        arc = EcefArc(a, b)
        assert_array_almost_equal(arc.coords[0], a)
        assert_array_almost_equal(arc.a, a)
        self.assertFalse(EcefPoint(arc.pole))
        assert_almost_equal(arc.length, np.pi)
Ejemplo n.º 13
0
    def test_normalize(self):
        for i in range(12):
            ecef_point = 2.0 * EcefPoint(ECEF_ICOSAHEDRON[i])
            assert_almost_equal(abs(ecef_point), 2.0)
            self.assertTrue(ecef_point)

            ecef_point.normalize()
            assert_almost_equal(abs(ecef_point), 1.0)
            self.assertTrue(ecef_point)

        ecef_point = EcefPoint([EPSILON, -EPSILON, EPSILON])
        assert_almost_equal(abs(ecef_point), 0.0)

        ecef_point.normalize()
        assert_almost_equal(abs(ecef_point), 0.0)
Ejemplo n.º 14
0
    def test_position(self):
        ecef_equator_1 = EcefPoint([1.0, 0.0, 0.0])
        ecef_equator_2 = EcefPoint([0.0, 1.0, 0.0])
        arc = EcefArc(ecef_equator_1, ecef_equator_2)

        assert_array_almost_equal(arc.position(0.0), ecef_equator_1)
        assert_array_almost_equal(arc.position(arc.length), ecef_equator_2)

        recp_sqrt_2 = 1.0 / np.sqrt(2.0)
        ecef_equator_half = EcefPoint([recp_sqrt_2, recp_sqrt_2, 0.0])
        assert_array_almost_equal(arc.position(arc.length / 2),
                                  ecef_equator_half)

        ecef_equator_3 = EcefPoint([0.0, -1.0, 0.0])
        assert_array_almost_equal(arc.position(-arc.length), ecef_equator_3)

        ecef_equator_4 = EcefPoint([-1.0, 0.0, 0.0])
        assert_array_almost_equal(arc.position(2 * arc.length), ecef_equator_4)
Ejemplo n.º 15
0
    def test_mul(self):
        ecef_point1 = EcefPoint(ECEF_ICOSAHEDRON[1])
        non_scalar = 'hello'

        try:
            ecef_point1 * non_scalar
        except TypeError:
            self.assertTrue(1)
        else:
            self.assertTrue(0)
Ejemplo n.º 16
0
    def test_distance_radians(self):
        ecef_point_0 = EcefPoint(ECEF_ICOSAHEDRON[0])
        self.assertEqual(distance_radians(ecef_point_0, ecef_point_0), 0.0)

        result_1 = np.arctan(2.0)
        for i in range(1, 6):
            ecef_point_i = EcefPoint(ECEF_ICOSAHEDRON[i])
            assert_almost_equal(distance_radians(ecef_point_0, ecef_point_i),
                                result_1)

        result_2 = np.pi - result_1  # 2.0344439363560154
        for i in range(6, 11):
            ecef_point_i = EcefPoint(ECEF_ICOSAHEDRON[i])
            assert_almost_equal(distance_radians(ecef_point_0, ecef_point_i),
                                result_2)

        ecef_point_11 = EcefPoint(ECEF_ICOSAHEDRON[11])
        assert_almost_equal(distance_radians(ecef_point_0, ecef_point_11),
                            np.pi)
Ejemplo n.º 17
0
    def test_getitem(self):
        a = EcefPoint(ECEF_ICOSAHEDRON[10])
        assert_almost_equal(a[0], 0.276393202421474)
        assert_almost_equal(a[1], 0.8506508080328565)
        assert_almost_equal(a[2], -0.4472135960011169)

        try:
            a[1.0]
        except TypeError:
            self.assertTrue(1)
        else:
            self.assertTrue(0)
Ejemplo n.º 18
0
    def test_turn_angle(self):

        result_1 = 0.6 * np.pi
        result_2 = 0.2 * np.pi

        a = EcefPoint(ECEF_ICOSAHEDRON[0])
        b = EcefPoint(ECEF_ICOSAHEDRON[1])
        arc = EcefArc(a, b)

        # test zero distance to b
        angle = arc.turn_angle(b)
        self.assertEqual(angle, 0.0)

        # test zero angle, along IDL from North Pole to South Pole
        c = EcefPoint(ECEF_ICOSAHEDRON[11])
        angle = arc.turn_angle(c)
        self.assertEqual(angle, 0.0)

        for i in range(10):
            a = EcefPoint(ECEF_ICOSAHEDRON[i])
            b = EcefPoint(ECEF_ICOSAHEDRON[i + 1])
            arc = EcefArc(a, b)

            c = EcefPoint(ECEF_ICOSAHEDRON[i + 2])

            angle = arc.turn_angle(c)

            if i == 0:
                assert_almost_equal(angle, -result_1)
            elif i == 9:
                assert_almost_equal(angle, result_1)
            elif i == 4 or i >= 6:
                assert_almost_equal(angle, result_2)
            else:  # elif i == 1:
                assert_almost_equal(angle, -result_2)
Ejemplo n.º 19
0
    def test_closest_distance(self):
        ecef_equator_1 = EcefPoint([1.0, 0.0, 0.0])
        ecef_equator_2 = EcefPoint([0.0, 1.0, 0.0])
        arc = EcefArc(ecef_equator_1, ecef_equator_2)

        assert_almost_equal(arc.closest_distance(ecef_equator_1), 0.0)
        assert_almost_equal(arc.closest_distance(ecef_equator_2), 0.0)

        ecef_vector_4 = EcefPoint(ECEF_ICOSAHEDRON[4])
        assert_almost_equal(arc.closest_distance(ecef_vector_4),
                            0.463647609561)
        ecef_vector_7 = EcefPoint(ECEF_ICOSAHEDRON[7])
        assert_almost_equal(arc.closest_distance(ecef_vector_7),
                            2.1243706866836156)

        north_pole = EcefPoint(ECEF_ICOSAHEDRON[0])
        assert_almost_equal(arc.closest_distance(north_pole), np.pi / 2)

        south_pole = EcefPoint(ECEF_ICOSAHEDRON[11])
        assert_almost_equal(arc.closest_distance(south_pole), np.pi / 2)
Ejemplo n.º 20
0
 def test_str(self):
     a = EcefPoint(ECEF_ICOSAHEDRON[1])
     self.assertEqual('EcefPoint(26.565051209181547, 180.0)', str(a))
     b = EcefPoint(ECEF_ICOSAHEDRON[10])
Ejemplo n.º 21
0
 def test_abs(self):
     for i in range(12):
         ecef_point = EcefPoint(ECEF_ICOSAHEDRON[i])
         assert_almost_equal(abs(ecef_point), 1.0)
Ejemplo n.º 22
0
    def test_cross_track_distance(self):
        ecef_point_0 = EcefPoint(ECEF_ICOSAHEDRON[0])
        ecef_point_1 = EcefPoint(ECEF_ICOSAHEDRON[1])
        arc = EcefArc(ecef_point_0, ecef_point_1)

        self.assertEqual(arc.cross_track_distance(ecef_point_0), 0.0)
        self.assertEqual(arc.cross_track_distance(ecef_point_1), 0.0)

        result2 = 0.5 * (np.pi - np.arctan(2.0))
        ecef_point_2 = EcefPoint(ECEF_ICOSAHEDRON[2])
        assert_almost_equal(arc.cross_track_distance(ecef_point_2), result2)

        result3 = 0.5 * np.arctan(2.0)
        ecef_point_3 = EcefPoint(ECEF_ICOSAHEDRON[3])
        assert_almost_equal(arc.cross_track_distance(ecef_point_3), result3)
        ecef_point_4 = EcefPoint(ECEF_ICOSAHEDRON[4])
        assert_almost_equal(arc.cross_track_distance(ecef_point_4), -result3)

        ecef_point_5 = EcefPoint(ECEF_ICOSAHEDRON[5])
        assert_almost_equal(arc.cross_track_distance(ecef_point_5), -result2)

        ecef_point_6 = EcefPoint(ECEF_ICOSAHEDRON[6])
        assert_almost_equal(arc.cross_track_distance(ecef_point_6), -result3)
        ecef_point_7 = EcefPoint(ECEF_ICOSAHEDRON[7])
        assert_almost_equal(arc.cross_track_distance(ecef_point_7), result3)

        ecef_point_8 = EcefPoint(ECEF_ICOSAHEDRON[8])
        assert_almost_equal(arc.cross_track_distance(ecef_point_8), result2)

        ecef_point_9 = EcefPoint(ECEF_ICOSAHEDRON[9])
        assert_almost_equal(arc.cross_track_distance(ecef_point_9), 0.0)

        ecef_point_10 = EcefPoint(ECEF_ICOSAHEDRON[10])
        assert_almost_equal(arc.cross_track_distance(ecef_point_10), -result2)

        ecef_point_11 = EcefPoint(ECEF_ICOSAHEDRON[11])
        assert_almost_equal(arc.cross_track_distance(ecef_point_11), 0.0)
Ejemplo n.º 23
0
    def test_along_track_distance(self):
        ecef_point_0 = EcefPoint(ECEF_ICOSAHEDRON[0])
        ecef_point_1 = EcefPoint(ECEF_ICOSAHEDRON[1])
        arc = EcefArc(ecef_point_0, ecef_point_1)

        self.assertEqual(arc.along_track_distance(ecef_point_0), 0.0)

        result1 = np.arctan(2.0)
        assert_almost_equal(arc.along_track_distance(ecef_point_1), result1)

        result2 = 0.5 * np.arctan(2.0)
        ecef_point_2 = EcefPoint(ECEF_ICOSAHEDRON[2])
        assert_almost_equal(arc.along_track_distance(ecef_point_2), result2)

        result3 = 0.5 * (np.arctan(2.0) - np.pi)
        ecef_point_3 = EcefPoint(ECEF_ICOSAHEDRON[3])
        assert_almost_equal(arc.along_track_distance(ecef_point_3), result3)
        ecef_point_4 = EcefPoint(ECEF_ICOSAHEDRON[4])
        assert_almost_equal(arc.along_track_distance(ecef_point_4), result3)

        ecef_point_5 = EcefPoint(ECEF_ICOSAHEDRON[5])
        assert_almost_equal(arc.along_track_distance(ecef_point_5), result2)

        result4 = 2.124370686
        ecef_point_6 = EcefPoint(ECEF_ICOSAHEDRON[6])
        assert_almost_equal(arc.along_track_distance(ecef_point_6), result4)
        ecef_point_7 = EcefPoint(ECEF_ICOSAHEDRON[7])
        assert_almost_equal(arc.along_track_distance(ecef_point_7), result4)

        result5 = 0.5 * np.arctan(2.0) - np.pi
        ecef_point_8 = EcefPoint(ECEF_ICOSAHEDRON[8])
        assert_almost_equal(arc.along_track_distance(ecef_point_8), result5)

        result6 = np.arctan(2.0) - np.pi
        ecef_point_9 = EcefPoint(ECEF_ICOSAHEDRON[9])
        assert_almost_equal(arc.along_track_distance(ecef_point_9), result6)

        ecef_point_10 = EcefPoint(ECEF_ICOSAHEDRON[10])
        assert_almost_equal(arc.along_track_distance(ecef_point_10), result5)

        ecef_point_11 = EcefPoint(ECEF_ICOSAHEDRON[11])
        assert_almost_equal(arc.along_track_distance(ecef_point_11), np.pi)

        # Test points at poles.
        ecef_equator_1 = EcefPoint([1.0, 0.0, 0.0])
        ecef_equator_2 = EcefPoint([0.0, 1.0, 0.0])
        arc = EcefArc(ecef_equator_1, ecef_equator_2)

        north_pole = EcefPoint(ECEF_ICOSAHEDRON[0])
        assert_almost_equal(arc.along_track_distance(north_pole), 0.0)

        south_pole = EcefPoint(ECEF_ICOSAHEDRON[11])
        assert_almost_equal(arc.along_track_distance(south_pole), 0.0)