コード例 #1
0
ファイル: solar_system_app.py プロジェクト: pchalas1/libWall
    def __init__(self, name):
        super(SolarSystemApp, self).__init__(name)

        self.solar_system_widget = SolarSystem(self.default_width,
                                               self.default_height)
        self.use_default_layout(self.solar_system_widget)
        pass
コード例 #2
0
def solar_system():
    # distance : in millions of km
    # radius : in thousands of km, all get divided by 2 and the sun by 10 on top for size on screen
    # velocity : in km/s
    # mass : in kg
    sun = Planet([center_w, center_h], 696.340 / 20, [0, 0], 1.989 * 10**30,
                 (255, 255, 0), "Sun")
    mercury = Planet([center_w - 69.8, center_h], 2.439, [0, 38.86],
                     3.301 * 10**23, (128, 128, 128), "Mercury")
    venus = Planet([center_w - 108, center_h], 6.051, [0, 35], 4.8675 * 10**24,
                   (255, 128, 0), "Venus")
    earth = Planet([center_w - 152.1, center_h], 6.371, [0, 29.3],
                   5.972 * 10**24, BLUE, "Earth")
    mars = Planet([center_w - 228, center_h], 3.390, [0, 21.972],
                  6.4185 * 10**23, RED, "Mars")

    m = 1.5 * 10**29
    x = 97.000436
    y = 24.308753
    vx = 9.3240737
    vy = 8.6473146
    p1 = Planet([center_w + x, center_h + y], 10, [vx / 2, -vy / 2], m, BLUE)
    p2 = Planet([center_w - x, center_h - y], 10, [vx / 2, -vy / 2], m, RED)
    p3 = Planet([center_w, center_h], 10, [-vx, vy], m, WHITE)

    # planets = [p1, p2, p3] # 8 figure
    planets = [sun, mercury, venus, mars, earth]  # solar system

    return planets, SolarSystem(planets)
コード例 #3
0
ファイル: test_animate.py プロジェクト: pmorande27/Solar.py
    def test_period_graph_update(self, beeman, plot, show):
        try:
            system = SolarSystem(3600, 10.175 * 10**3, Options.NORMAL_RUN,
                                 "CelestialObjects")

            Animation.periods_graph(100, system)
        except ZeroDivisionError as err:
            self.assertEqual(100, beeman.call_count)
コード例 #4
0
def main():
    """
    Main function
    """
    system = SolarSystem(3600, 11.5517 * 10**3, Options.PROBE_RUN,
                         "CelestialObjects")
    animate = Animation(system)
    animate.plot()
コード例 #5
0
 def __init__(self, sys: SolarSystem):
     self.solar_system = sys
     self.planets = sys.get_planets()
     self.mission = {
         'earth': self.planets['earth'],
         'mars': self.planets['mars']
     }
     self.velocity = 0
コード例 #6
0
ファイル: test_animate.py プロジェクト: pmorande27/Solar.py
 def test_plot_show(self, mock):
     """Test to prove that plt.show is called in plot() method.
     Uses mocking
     """
     self.system_probe = SolarSystem(3600, 10000, Options.PROBE_RUN,
                                     "CelestialObjects")
     animate = Animation(self.system_probe)
     animate.plot()
     mock.assert_called()
コード例 #7
0
ファイル: test_animate.py プロジェクト: pmorande27/Solar.py
 def test_scatterplot_show(self, mock):
     """Test used to prove that plt.show() is called once in scatter_plot method
     uses mocking
     """
     self.system_probe = SolarSystem(3600, 10000, Options.PROBE_RUN,
                                     "CelestialObjects")
     animate = Animation(self.system_probe)
     animate.scatter_plot(100)
     mock.assert_called_once()
コード例 #8
0
 def test_Adding_Planet(self):
     """Test used to check that the method add_planet can add a planet correctly into a system.
     """
     self.write.add_planet("test",1,1,1,"blue","test")
     system = SolarSystem(1,1,Options.PROBE_RUN,"test")
     self.assertEqual(len(system.celestial_bodies),7)
     self.assertEqual(system.celestial_bodies[len(system.celestial_bodies)-1].name,"test")
     self.assertEqual(system.celestial_bodies[len(system.celestial_bodies)-1].mass,1)
     self.assertEqual(system.celestial_bodies[len(system.celestial_bodies)-1].orbital_radius,1)
     self.assertEqual(system.celestial_bodies[len(system.celestial_bodies)-1].type_of_object,"Planet")
コード例 #9
0
ファイル: test_animate.py プロジェクト: pmorande27/Solar.py
 def test_animate_update(self, mock, mock2):
     """Test used to prove that update beeman is calld in the animate method
     Uses mocking.
     """
     self.system_probe = SolarSystem(3600, 10000, Options.PROBE_RUN,
                                     "CelestialObjects")
     animate = Animation(self.system_probe)
     animate.plot()
     animate.init()
     animate.animate(0)
     mock.assert_called()
コード例 #10
0
ファイル: test_animate.py プロジェクト: pmorande27/Solar.py
 def test_scatterplot_update(self, mock, mock2):
     """Test used to prove that update_beeman() is called 100 times in scatter_plot method
     if the parameter passed to scatter_plot is 100.
     uses mocking
     """
     self.system_probe = SolarSystem(3600, 10000, Options.PROBE_RUN,
                                     "CelestialObjects")
     animate = Animation(self.system_probe)
     animate.scatter_plot(100)
     mock.assert_called()
     self.assertEqual(mock.call_count, 100)
コード例 #11
0
ファイル: test_animate.py プロジェクト: pmorande27/Solar.py
    def test_plot_animate(self, mock, mock2):
        """Test used to check that a FunCAnimator is used in plot()
        Uses mocking

        """
        mock.return_value = None
        self.system_probe = SolarSystem(3600, 10000, Options.PROBE_RUN,
                                        "CelestialObjects")
        animate = Animation(self.system_probe)
        animate.plot()
        mock.assert_called()
コード例 #12
0
 def setUp(self):
     """Method that is executed begore each test and that loads all the systems used
     """
     self.system_probe = SolarSystem(3600,10000,Options.PROBE_RUN,"CelestialObjects")
     self.system = SolarSystem(3600,10000,Options.NORMAL_RUN,"CelestialObjects")
     self.system_simple = SolarSystem(3600,10000,Options.NORMAL_RUN,"CelestialObjects")
     planetA = CelestialBody("B",1,1,1,"Planet",1,10000,"blue")
     star = CelestialBody("A",1,1,1,"Star",0,10000,"blue")
     planets = [star,planetA]
     self.system_simple.celestial_bodies = planets
     self.system_simple.update_initial_acceleration()
コード例 #13
0
 def test_beeman(self):
     """Test used to check that Beeman's method works appropiatley.
     """
     planetA = CelestialBody("B",1,1,1,"Planet",1,10000,"blue")
     star = CelestialBody("A",1,1,1,"Star",0,10000,"blue")
     planetB = CelestialBody("B",1,2,1,"Planet",1,10000,"blue")
     planetB.position = np.array([-1.0,0.0])
     planetB.velocity = np.array([0.0,-planetA.velocity[1]])
     system = SolarSystem(3600,1000,Options.NORMAL_RUN,"CelestialObjects")
     system.celestial_bodies = [star,planetA,planetB]
     system.update_initial_acceleration()
     for i in range(100):
         system.update_beeman()
     self.assertEqual(0.0,star.acceleration[0])
     self.assertEqual(0.0,star.acceleration[1])
コード例 #14
0
ファイル: animate.py プロジェクト: pmorande27/Solar.py
 def energy_graph_comparisson(updates):
     """Function used to generate a comparison graph between Euler's method and Beeman's
     to show conservation (or not conservation) of energy in both methods
     """
     system = SolarSystem(3600, 10.175 * 10**3, Options.NORMAL_RUN,
                          "CelestialObjects")
     energy_1 = [system.get_energy()]
     system2 = SolarSystem(3600, 10.175 * 10**3, Options.NORMAL_RUN,
                           "CelestialObjects")
     energy_2 = [system2.get_energy()]
     iterate = updates
     iterations = [i * 3600 for i in range(iterate + 1)]
     for i in range(iterate):
         energy_1.append(system.update_beeman())
         energy_2.append(system2.update_euler())
     plt.xlabel('time(s)')
     plt.ylabel('Energy [J]')
     plt.plot(iterations, energy_1, iterations, energy_2)
     plt.show()
コード例 #15
0
def search_velocity_to_mars(updates, tries, velocity):
    """Function used to searc for the optimal velocity for the probe to approach mars
    it will do it by try and error over different values.

    Returns:
        (float,float): tuple of distance the minimum distance found and the speed needed to
        accomplish it.
    """
    start_velocity = velocity
    system = SolarSystem(3600, start_velocity, Options.PROBE_RUN,
                         "CelestialObjects")
    min_v = 0
    increment = 0.001
    minimum = system.distance_to_mars()
    for i in range(tries):
        system = SolarSystem(3600, start_velocity + i * increment,
                             Options.PROBE_RUN, "CelestialObjects")
        for j in range(updates):
            system.update_beeman()
            if minimum >= system.distance_to_mars():
                minimum = system.distance_to_mars()
                min_v = start_velocity + i * increment
    return (minimum, min_v)
コード例 #16
0
    vx0 = vars.vx0
    vy0 = vars.vy0
    a = vars.a
    e = vars.e
    theta0 = vars.theta0
    psi0 = vars.psi0
    radius = vars.radius
    m_star = vars.m_star
    m = vars.m

    G = vars.G

    names = ['Matsat','sunsun', 'Dum','og', 'Deilig', 'Juba', 'juba', 'Pizzatryne', 'Verdens ende']
    sun_name = 'pleb'

    fullmugg = SolarSystem()
    sunsun = Sun(m_star, 0.001, np.array([0,0]), np.array([0,0]), 100000, 'sunsun')
    fullmugg.addSun(sunsun)

    masses = np.concatenate((np.array([m_star]), m))

    radius = np.concatenate((np.array([vars.radius_star]), radius))
    x0 = np.concatenate((np.array([0]), x0))
    y0 = np.concatenate((np.array([0]), y0))
    vx0 = np.concatenate((np.array([0]), vx0))
    vy0 = np.concatenate((np.array([0]), vy0))

    initial_rocket_mass = 1.456e+05/1.989e30
    m_sat = 1100/1.989e30

    m_rock = np.array([m_sat])
コード例 #17
0
ファイル: test_animate.py プロジェクト: pmorande27/Solar.py
 def test_period_graph_plot(self, plot, show):
     system = SolarSystem(1000000, 10.175 * 10**3, Options.NORMAL_RUN,
                          "CelestialObjects")
     system.celestial_bodies = system.celestial_bodies[0:2]
     Animation.periods_graph(10, system)
     show.assert_called_once()
コード例 #18
0
from solar_system import SolarSystem
from solar_time import UniversalTime

ss = SolarSystem()

ut = UniversalTime(year=2020, month=3, day=14, hour=0, minute=0, second=0)

ss.plot_planets(ut, [0, 1, 2, 3])
コード例 #19
0
class TestSolarSystem(unittest.TestCase):
    def setUp(self):
        """Method that is executed begore each test and that loads all the systems used
        """
        self.system_probe = SolarSystem(3600,10000,Options.PROBE_RUN,"CelestialObjects")
        self.system = SolarSystem(3600,10000,Options.NORMAL_RUN,"CelestialObjects")
        self.system_simple = SolarSystem(3600,10000,Options.NORMAL_RUN,"CelestialObjects")
        planetA = CelestialBody("B",1,1,1,"Planet",1,10000,"blue")
        star = CelestialBody("A",1,1,1,"Star",0,10000,"blue")
        planets = [star,planetA]
        self.system_simple.celestial_bodies = planets
        self.system_simple.update_initial_acceleration()
    def test_initial_accelerations(self):
        """Test used to check that the initial accelerations of the bodies of the systems are
        not zero.
        """
        for planet in self.system.celestial_bodies:
            self.assertNotEqual(0.0,planet.acceleration[0])
            self.assertEqual(0.0,planet.acceleration[1],planet.name)
        for planet in self.system.celestial_bodies:
            self.assertNotEqual(0.0,planet.acceleration[0])
            if (planet.name!="Mars" and planet.name != "Probe"):
                self.assertEqual(0.0,planet.acceleration[1],planet.name)
    def test_potential_energy_simple(self):
        """Test used to check that the value of the potential energy for a siple system is calculated
        correctly.
        """
        expected_value = -CelestialBody.G
        self.assertEqual(expected_value,self.system_simple.get_potential_energy())
    def test_kinetic_energy_simple(self):
        """Test used to check that the value of the kinetic energy for a siple system is calculated
        correctly.
        """
        expected_value = 1/2 * 1 * CelestialBody.G
        self.assertEqual(expected_value,self.system_simple.get_kinetic_energy())
    def test_kinetic_energy(self):
        """Test used to check that the value of the kinetic energy of a system is calculated
        correctly.
        """
        expected_value = 0
        for body in self.system.celestial_bodies:
            expected_value+= 1/2 *body.mass * np.linalg.norm(body.velocity)**2
        self.assertEqual(expected_value,self.system.get_kinetic_energy())
    def test_potential_energy(self):
        """Test used to check that the value of the potential energy of a system is calculated
        correctly.
        """
        expected_value = 0
        for bodyA in self.system.celestial_bodies:
            for bodyB in self.system.celestial_bodies:
                if bodyA.name != bodyB.name:
                    expected_value += -CelestialBody.G * bodyB.mass*0.5 *bodyA.mass/(np.linalg.norm(bodyB.position-bodyA.position))
        self.assertEqual(expected_value,self.system.get_potential_energy())
    def test_total_energy(self):
        """Test used to check that the value of the total energy of a system is calculated
        correctly.
        """
        potential = 0
        for bodyA in self.system.celestial_bodies:
            for bodyB in self.system.celestial_bodies:
                if bodyA.name != bodyB.name:
                    potential += -CelestialBody.G * bodyB.mass*0.5 *bodyA.mass/(np.linalg.norm(bodyB.position-bodyA.position))
        kinetic_energy = 0
        for body in self.system.celestial_bodies:
            kinetic_energy+= 1/2 *body.mass * np.linalg.norm(body.velocity)**2
        self.assertEqual(potential+kinetic_energy,self.system.get_energy())
    def test_distance_to_earth(self):
        """Test used to check that the initial distance between the probe and the Earth is correctly set
        """
        expected_value = 6.371*10**6
        self.assertEqual(expected_value,self.system_probe.distance_to_earth())
    def test_euler(self):
        """Test used to check that Euler's method works appropiatley.
        """
        planetA = CelestialBody("B",1,1,1,"Planet",1,10000,"blue")
        star = CelestialBody("A",1,1,1,"Star",0,10000,"blue")
        planetB = CelestialBody("B",1,2,1,"Planet",1,10000,"blue")
        planetB.position = np.array([-1.0,0.0])
        planetB.velocity = np.array([0.0,-planetA.velocity[1]])
        system = SolarSystem(3600,1000,Options.NORMAL_RUN,"CelestialObjects")
        system.celestial_bodies = [star,planetA,planetB]
        system.update_initial_acceleration()
        for i in range(100):
            system.update_euler()
        self.assertEqual(0.0,star.acceleration[0])
        self.assertEqual(0.0,star.acceleration[1])
    def test_beeman(self):
        """Test used to check that Beeman's method works appropiatley.
        """
        planetA = CelestialBody("B",1,1,1,"Planet",1,10000,"blue")
        star = CelestialBody("A",1,1,1,"Star",0,10000,"blue")
        planetB = CelestialBody("B",1,2,1,"Planet",1,10000,"blue")
        planetB.position = np.array([-1.0,0.0])
        planetB.velocity = np.array([0.0,-planetA.velocity[1]])
        system = SolarSystem(3600,1000,Options.NORMAL_RUN,"CelestialObjects")
        system.celestial_bodies = [star,planetA,planetB]
        system.update_initial_acceleration()
        for i in range(100):
            system.update_beeman()
        self.assertEqual(0.0,star.acceleration[0])
        self.assertEqual(0.0,star.acceleration[1])
    def test_timeStep(self):
        """Test used to check that the variable time step is implemented.
        """
        self.system_probe.update_beeman()
        self.assertEqual(self.system_probe.time_step,20)
        for i in range(1000):
            self.system_probe.update_beeman()
        self.assertEqual(self.system_probe.time_step,3600)
    def test_search(self):
        for body in self.system.celestial_bodies:
            self.assertEqual(self.system.search_body(body.name).name,body.name)
    def test_exception_search(self):
        with self.assertRaises(ValueError) as context:
            self.system.search_body("Probe")   
        self.assertTrue("The given name is not in the actual list of bodies" in str(context.exception))
    def test_variable_time_step(self):
        self.assertEqual(self.system_probe.time_step, 20)
        self.system_probe.initial = False
        self.system_probe.search_body("Probe").position = np.array([1000.0,0.0])
        self.system_probe.update_beeman()
        self.assertEqual(self.system_probe.time_step, 3600)
コード例 #20
0
def main():

    t = 0
    dt = 1
    s = SolarSystem(2.50e+11, "Solar System", dt, 3)

    # Data info
    # initial conditions obtained from date: A.D. 2020 - Jul - 18
    # vector ephemeris data is obtained from: https://ssd.jpl.nasa.gov/horizons.cgi#top
    # km/s converted to m/s

    s.add_body(
        Particle(1.9890e+30, -8.115575219749061E+05, 1.023358542970559E+06,
                 1.030475383803935E+04, -1.367124428632311E+01,
                 -7.255536346983386E0, 3.953653246527174E-01, 7.000E+06,
                 "Sun"))
    # #
    s.add_body(
        Particle(6.4190e+23, 1.700911233235551E+08, -1.154793014669231E+08,
                 -6.623490315706909E+06, 1.455681174959298E+04,
                 2.208572786142721E+04, 1.059053211570298E+03, 4.000E+05,
                 "Mars"))
    #
    #
    # s.add_body(Particle(5.9740e+24, 6.478846194962674E+07, -1.361379609312382E+08, 1.655851550595462E+04,
    #                     2.638665577941761E+04, 1.273331100378729E+04, -1.385515264764159E00, 5.000E+06, "Earth"))

    # s.add_body(Particle(1.8982E+27, 2.925974889403378E+08, -7.120923141565894E+08, -3.592415407148212E+06,
    #                     1.192504812263601E+04, 5.588195368858322E+03, -2.898746577296276E+02, 8.000E+06, "Jupiter"))

    # s.add_body(Particle(7.34767309E+22, 6.484283712254966E+07, -1.357523313359251E+08, 1.235756001138687E+04,
    #                     2.538303859564986E+04, 1.282111106220561E+04, 9.061949758449295E+01, 5.000E+04, "Moon (Earth)"))

    while t < 25000:

        vpy.rate(100)
        s.net_forces()
        s.acceleration()
        s.velocity()
        t += dt

    s.plot()
コード例 #21
0
 def test_WrittingFile(self):
     """Test used to check that the method write_file works correctly.
     """
     system = SolarSystem(1,1,Options.PROBE_RUN,"test")
     self.assertEqual(len(system.celestial_bodies),6)