Ejemplo n.º 1
0
def orbit():
    planets = [
        Planet(1817514095, 1905216634, -1485460920),
        Planet(1817514095, 1905216634, -1722015868),
        Planet(1817514095, 1905216634, -455609026),
        Planet(1817514095, 1905216634, 272811578)
    ]

    t0 = epoch_from_string(str(datetime.now()))
    x_val = list()
    y_val = list()
    z_val = list()
    planet_positions = list()
    planet_names = list()
    planet_colors = list()

    for orbiter in planets:
        orbit_period = orbiter.planet.compute_period(epoch(0)) * SEC2DAY
        orbit_when = np.linspace(0, orbit_period, 60)

        x = np.zeros(60)
        y = np.zeros(60)
        z = np.zeros(60)

        for i, day in enumerate(orbit_when):
            r, _ = orbiter.planet.eph(epoch(t0.mjd2000 + day))
            x[i] = r[0] / AU
            y[i] = r[1] / AU
            z[i] = r[2] / AU

        x_val.append(x.tolist())
        y_val.append(y.tolist())
        z_val.append(z.tolist())

        planet_positions.append(list((x[0], y[0], z[0])))
        if orbiter.id == -455609026:
            planet_colors.append("green")
        else:
            planet_colors.append("gray")
        planet_names.append(orbiter.name)

    return jsonify(success=True,
                   x=x_val,
                   y=y_val,
                   z=z_val,
                   p=planet_positions,
                   c=planet_colors,
                   n=planet_names) if has_app_context() else x_val
Ejemplo n.º 2
0
    def test_property_planet_pykep(self, mock_get, mock_constant, mock_star):
        """Test planet pykep property of Planet."""
        mock_get.side_effect = self.api_traversal \
                + [mocked_requests_get(
                    semimajor_axis=1,
                    mass=0.75)]

        mock_grav = MagicMock()
        type(mock_grav).value = PropertyMock(return_value=6.67408e-11)

        mock_planet_mass = MagicMock()
        type(mock_planet_mass).value = PropertyMock(return_value=5.9722e24)

        mock_planet_radius = MagicMock()
        type(mock_planet_radius).value = PropertyMock(return_value=6378136.6)

        mock_constant.side_effect = [
            mock_planet_radius, mock_planet_mass, mock_grav
        ]

        mock_star_gm = MagicMock()
        type(mock_star_gm).gm = PropertyMock(return_value=0.75 * 1.9884e30 *
                                             6.67408e-11)

        mock_star.return_value = mock_star_gm

        instance = Planet(1, 1, 1)
        expected_result = keplerian
        self.assertIsInstance(instance.planet, expected_result)
Ejemplo n.º 3
0
 def test_init_planets_HTTPError(self, mock_get):
     """Test Planet init with HTTPError on API planets."""
     mock_get.side_effect = self.api_traversal[0:5] + [
         HTTPError("Error", None)
     ]
     with self.assertRaises(HTTPError):
         _ = Planet(1, 1, 1)
Ejemplo n.º 4
0
    def test_property_true_anomaly_at_epoch(self, mock_get, _):
        """Test true anomaly at epoch property of Planet."""
        mock_get.side_effect = self.api_traversal \
                + [mocked_requests_get(true_anomaly_at_epoch=id(sentinel.true))]

        instance = Planet(1, 1, 1)
        expected_result = id(sentinel.true)
        self.assertEqual(instance.true_anomaly_at_epoch, expected_result)
Ejemplo n.º 5
0
    def test_init(self, mock_get, _):
        """Test Planet init."""
        mock_get.side_effect = self.api_traversal \
                + [mocked_requests_get()]

        instance = Planet(1, 1, 1)
        expected_result = Planet
        self.assertIsInstance(instance, expected_result)
Ejemplo n.º 6
0
    def test_property_inclination(self, mock_get, _):
        """Test inclination property of Planet."""
        mock_get.side_effect = self.api_traversal \
                + [mocked_requests_get(inclination=id(sentinel.inclination))]

        instance = Planet(1, 1, 1)
        expected_result = id(sentinel.inclination)
        self.assertEqual(instance.inclination, expected_result)
Ejemplo n.º 7
0
    def test_property_longitude_of_ascending_node(self, mock_get, _):
        """Test longitude of ascending node property of Planet."""
        mock_get.side_effect = self.api_traversal \
                + [mocked_requests_get(longitude_of_ascending_node=id(sentinel.longitude))]

        instance = Planet(1, 1, 1)
        expected_result = id(sentinel.longitude)
        self.assertEqual(instance.longitude_of_ascending_node, expected_result)
Ejemplo n.º 8
0
    def test_property_semimajor_axis(self, mock_get, _):
        """Test semimajor axis property of Planet."""
        mock_get.side_effect = self.api_traversal \
                + [mocked_requests_get(semimajor_axis=id(sentinel.semimajor_axis))]

        instance = Planet(1, 1, 1)
        expected_result = id(sentinel.semimajor_axis)
        self.assertEqual(instance.semimajor_axis, expected_result)
Ejemplo n.º 9
0
    def test_property_eccentricity(self, mock_get, _):
        """Test eccentricity property of Planet."""
        mock_get.side_effect = self.api_traversal \
                + [mocked_requests_get(eccentricity=id(sentinel.eccentricity))]

        instance = Planet(1, 1, 1)
        expected_result = id(sentinel.eccentricity)
        self.assertEqual(instance.eccentricity, expected_result)
Ejemplo n.º 10
0
    def test_property_radius(self, mock_get, _):
        """Test radius property of Planet."""
        mock_get.side_effect = self.api_traversal \
                + [mocked_requests_get(radius=id(sentinel.radius))]

        instance = Planet(1, 1, 1)
        expected_result = id(sentinel.radius)
        self.assertEqual(instance.radius, expected_result)
Ejemplo n.º 11
0
    def test_property_name(self, mock_get, _):
        """Test name property of Planet."""
        mock_get.side_effect = self.api_traversal \
                + [mocked_requests_get(name=id(sentinel.name))]

        instance = Planet(1, 1, 1)
        expected_result = str(id(sentinel.name))
        self.assertEqual(instance.name, expected_result)
Ejemplo n.º 12
0
    def test_property_id(self, mock_get, _):
        """Test id property of Planet."""
        mock_get.side_effect = self.api_traversal \
                + [mocked_requests_get(idnum=1)]

        instance = Planet(1, 1, 1)
        expected_result = 1
        self.assertEqual(instance.id, expected_result)
Ejemplo n.º 13
0
    def test_property_argument_of_periapsis(self, mock_get, _):
        """Test argument of periapsis property of Planet."""
        mock_get.side_effect = self.api_traversal \
                + [mocked_requests_get(argument_of_periapsis=id(sentinel.argument))]

        instance = Planet(1, 1, 1)
        expected_result = id(sentinel.argument)
        self.assertEqual(instance.argument_of_periapsis, expected_result)
Ejemplo n.º 14
0
    def test_property_gm(self, mock_get, mock_constant, _):
        """Test gm property of Planet."""
        mock_get.side_effect = self.api_traversal \
                + [mocked_requests_get(mass=0.75)]

        mock_grav = MagicMock()
        type(mock_grav).value = PropertyMock(return_value=6.67408e-11)

        mock_planet_mass = MagicMock()
        type(mock_planet_mass).value = PropertyMock(return_value=5.9722e24)

        mock_constant.side_effect = [mock_planet_mass, mock_grav]

        instance = Planet(1, 1, 1)
        expected_result = 0.75 * 5.9722e24 * 6.67408e-11
        self.assertEqual(instance.gm, expected_result)
Ejemplo n.º 15
0
def epoch_offset():
    planet = Planet(1817514095, 1905216634, -455609026)

    winter = np.arctan2(-1, 0)

    a = -75.0
    b = 75.0

    for _ in range(1000):
        c = (a + b) / 2
        r_c, _ = planet.planet.eph(epoch(c))

        angle = np.arctan2(r_c[1], r_c[0])

        if angle - winter < 0:
            a = c
        else:
            b = c

    return jsonify(c) if has_app_context() else c
Ejemplo n.º 16
0
 def test_property_longitude_of_ascending_node(self):
     """Test 1 Eta Veneris 3 longitude of ascending node."""
     instance = Planet(1817514095, 1905216634, -455609026)
     expected_result = 0
     self.assertEqual(instance.longitude_of_ascending_node, expected_result)
Ejemplo n.º 17
0
 def test_property_argument_of_periapsis(self):
     """Test 1 Eta Veneris 3 argument of periapsis."""
     instance = Planet(1817514095, 1905216634, -455609026)
     expected_result = 3.7920682
     self.assertEqual(instance.argument_of_periapsis, expected_result)
Ejemplo n.º 18
0
 def test_property_eccentricity(self):
     """Test 1 Eta Veneris 3 eccentricity."""
     instance = Planet(1817514095, 1905216634, -455609026)
     expected_result = 0.05
     self.assertEqual(instance.eccentricity, expected_result)
Ejemplo n.º 19
0
 def test_property_inclination(self):
     """Test 1 Eta Veneris 3 inclination."""
     instance = Planet(1817514095, 1905216634, -455609026)
     expected_result = 0
     self.assertEqual(instance.inclination, expected_result)
Ejemplo n.º 20
0
 def test_property_radius(self):
     """Test 1 Eta Veneris 3 radius."""
     instance = Planet(1817514095, 1905216634, -455609026)
     expected_result = 0.8665139
     self.assertEqual(instance.radius, expected_result)
Ejemplo n.º 21
0
 def test_property_semimajor_axis(self):
     """Test 1 Eta Veneris 3 semimajor axis."""
     instance = Planet(1817514095, 1905216634, -455609026)
     expected_result = 0.50302297
     self.assertEqual(instance.semimajor_axis, expected_result)
Ejemplo n.º 22
0
 def test_property_name(self):
     """Test 1 Eta Veneris 3 name."""
     instance = Planet(1817514095, 1905216634, -455609026)
     expected_result = "1 Eta Veneris 3"
     self.assertEqual(instance.name, expected_result)
Ejemplo n.º 23
0
 def test_property_mass(self):
     """Test 1 Eta Veneris 3 mass."""
     instance = Planet(1817514095, 1905216634, -455609026)
     expected_result = 0.7156807
     self.assertEqual(instance.mass, expected_result)
Ejemplo n.º 24
0
 def test_property_id(self):
     """Test 1 Eta Veneris 3 id."""
     instance = Planet(1817514095, 1905216634, -455609026)
     expected_result = -455609026
     self.assertEqual(instance.id, expected_result)
Ejemplo n.º 25
0
 def test_init_planet(self):
     """Test 1 Eta Veneris 3 init."""
     instance = Planet(1817514095, 1905216634, -455609026)
     expected_result = Planet
     self.assertIsInstance(instance, expected_result)
Ejemplo n.º 26
0
 def test_init_planet_KeyError(self, mock_get):
     """Test Planet init with KeyError on API planet."""
     mock_get.side_effect = self.api_traversal + [KeyError()]
     with self.assertRaises(KeyError):
         _ = Planet(1, 1, 1)
Ejemplo n.º 27
0
 def test_property_true_anomaly_at_epoch(self):
     """Test 1 Eta Veneris 3 true anomaly at epoch."""
     instance = Planet(1817514095, 1905216634, -455609026)
     expected_result = 3.8604798
     self.assertEqual(instance.true_anomaly_at_epoch, expected_result)
Ejemplo n.º 28
0
def transfer():
    star = Star(1817514095, 1905216634)
    origin = Planet(1817514095, 1905216634, -455609026)
    target = Planet(1817514095, 1905216634, 272811578)
    origin_orbit_radius = origin.planet.radius + 200000
    target_orbit_radius = target.planet.radius + 200000

    launch_time_start = int(float(flask_request.values['launch_start']))
    launch_time_end = int(float(flask_request.values['launch_end']))
    launch_time_offset = 0 if launch_time_start >= 0 else -launch_time_start

    flight_time_start = int(float(flask_request.values['flight_start']))
    flight_time_start = max(1, flight_time_start)
    flight_time_end = int(float(flask_request.values['flight_end']))
    flight_time_end = max(1, flight_time_end)

    t0 = epoch_from_string(str(datetime.now()))
    t0_number = int(t0.mjd2000)

    delta_v = np.full((flight_time_end - flight_time_start,
                       launch_time_end + launch_time_offset), None)

    for launch_time in range(launch_time_start, launch_time_end):
        for flight_time in range(flight_time_start, flight_time_end):
            launch_time = int(launch_time)
            launch_time_index = launch_time + launch_time_offset
            flight_time = int(flight_time)
            flight_time_index = flight_time - flight_time_start

            t1 = epoch(launch_time + t0_number)
            t2 = epoch(launch_time + t0_number + flight_time)
            dt = (t2.mjd - t1.mjd) * DAY2SEC
            r1, v1 = origin.planet.eph(t1)
            r2, v2 = target.planet.eph(t2)
            lambert = lambert_problem(list(r1), list(r2), dt, star.gm)

            delta_vs = list()

            for x in range(lambert.get_Nmax() + 1):
                vp_vec = np.array(v1)
                vs_vec = np.array(lambert.get_v1()[x])
                vsp_vec = vs_vec - vp_vec
                vsp = np.linalg.norm(vsp_vec)
                vo = sqrt(vsp * vsp +
                          2 * origin.planet.mu_self / origin_orbit_radius)
                inj_delta_v = vo - sqrt(
                    origin.planet.mu_self / origin_orbit_radius)

                vp_vec = np.array(v2)
                vs_vec = np.array(lambert.get_v2()[x])
                vsp_vec = vs_vec - vp_vec
                vsp = np.linalg.norm(vsp_vec)
                vo = sqrt(vsp * vsp +
                          2 * target.planet.mu_self / target_orbit_radius)
                ins_delta_v = vo - sqrt(
                    target.planet.mu_self / target_orbit_radius)

                delta_vs.append(inj_delta_v + ins_delta_v)

            delta_v[flight_time_index, launch_time_index] = min(delta_vs)

    return jsonify(success=True,
                   delta_v=delta_v.tolist(),
                   launch_start=launch_time_start,
                   launch_end=launch_time_end,
                   flight_start=flight_time_start,
                   flight_end=flight_time_end,
                   launch_offset=-launch_time_offset)
Ejemplo n.º 29
0
 def test_init_index_HTTPError(self, mock_get):
     """Test Planet init with HTTPError on API index."""
     mock_get.side_effect = HTTPError("Error", None)
     with self.assertRaises(HTTPError):
         _ = Planet(1, 1, 1)
Ejemplo n.º 30
0
 def test_init_index_KeyError(self, mock_get):
     """Test Planet init with KeyError on API index."""
     mock_get.side_effect = KeyError()
     with self.assertRaises(KeyError):
         _ = Planet(1, 1, 1)