Exemple #1
0
 def test_specified_r_to_orb(self):
     """test conversion from orbital elements to cartesian and back with specified cases"""
     cases = (
         {"m": 0.0, "primary": self.sun, "a": 1.0, "anom": 0.0, "e": 0.01, "omega": 0.0, "inc": 0.0, "Omega": 0.0},
         {"m": 0.0, "primary": self.sun, "a": 1.0, "anom": 3.0, "e": 0.999, "omega": 3.0, "inc": 2.0, "Omega": 3.0},
         {
             "m": 0.0,
             "primary": self.sun,
             "a": 1.0,
             "anom": 1.728,
             "e": 0.851,
             "omega": 1.287,
             "inc": 1.287,
             "Omega": 5.445,
         },
         # {'m':0.,'primary':self.sun,'a':42.,'anom':0.,'e':1.e-8,'omega':0.,'inc':1.e-8,'Omega':0.}
     )
     places = 12
     for kwargs in cases:
         p = rebound.kepler_particle(**kwargs)
         o = rebound.p2orbit(p, self.sun)
         self.assertAlmostEqual(kwargs["a"], o.a, places=places, msg="{}".format(kwargs))
         self.assertAlmostEqual(kwargs["e"], o.e, places=places, msg="{}".format(kwargs))
         self.assertAlmostEqual(kwargs["inc"], o.inc, places=places, msg="{}".format(kwargs))
         self.assertIs(
             almost_equal_wrap_2pi(kwargs["Omega"], rebound.mod2pi(o.Omega), places), True, "{}".format(kwargs)
         )
         self.assertIs(
             almost_equal_wrap_2pi(kwargs["omega"], rebound.mod2pi(o.omega), places), True, "{}".format(kwargs)
         )
         self.assertIs(almost_equal_wrap_2pi(kwargs["anom"], o.f, places), True, "{}".format(kwargs))
Exemple #2
0
    def test_rand_r_to_orb_f(self):
        places = 12
        for q in range(self.N_random_tests):
            kwargs = {
                "a": random.uniform(1.0, 2.0),
                "anom": random.uniform(0, 2 * math.pi),
                "e": random.uniform(0.0, 1.0),
                "omega": random.uniform(0, 2 * math.pi),
                "inc": random.uniform(0, math.pi),
                "Omega": random.uniform(0, 2 * math.pi),
                "MEAN": True,
            }

            p = rebound.kepler_particle(m=0.0, primary=self.sun, **kwargs)
            o = rebound.p2orbit(p, self.sun)
            self.assertAlmostEqual(kwargs["a"], o.a, places=12, msg="{}".format(kwargs))
            self.assertAlmostEqual(kwargs["e"], o.e, places=12, msg="{}".format(kwargs))
            self.assertAlmostEqual(kwargs["inc"], o.inc, places=12, msg="{}".format(kwargs))
            self.assertIs(
                almost_equal_wrap_2pi(kwargs["Omega"], rebound.mod2pi(o.Omega), places), True, "{}".format(kwargs)
            )
            self.assertIs(
                almost_equal_wrap_2pi(kwargs["omega"], rebound.mod2pi(o.omega), places), True, "{}".format(kwargs)
            )
            self.assertIs(
                almost_equal_wrap_2pi(kwargs["anom"], rebound.mod2pi(o.l - o.Omega - o.omega), places),
                True,
                "{}".format(kwargs),
            )
Exemple #3
0
    def test_r_to_orb_defaults(self):
        cases = ({"m": 0.0, "primary": self.sun, "a": 1}, {"m": 0.0, "primary": self.sun, "a": 1, "e": 0.01})

        results = (
            {"a": 1.0, "anom": 0.0, "e": 0.0, "omega": 0.0, "inc": 0.0, "Omega": 0.0},
            {"a": 1.0, "anom": 0.0, "e": 0.01, "omega": 0.0, "inc": 0.0, "Omega": 0.0},
        )
        places = 12
        for ctr, kwargs in enumerate(cases):
            p = rebound.kepler_particle(**kwargs)
            o = rebound.p2orbit(p, self.sun)
            self.assertAlmostEqual(results[ctr]["a"], o.a, places=places, msg="{}".format(kwargs))
            self.assertAlmostEqual(results[ctr]["e"], o.e, places=places, msg="{}".format(kwargs))
            self.assertAlmostEqual(results[ctr]["inc"], o.inc, places=places, msg="{}".format(kwargs))
            self.assertIs(
                almost_equal_wrap_2pi(results[ctr]["Omega"], rebound.mod2pi(o.Omega), places), True, "{}".format(kwargs)
            )
            self.assertIs(
                almost_equal_wrap_2pi(results[ctr]["omega"], rebound.mod2pi(o.omega), places), True, "{}".format(kwargs)
            )