Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_rand_r_to_orb_f(self):
places=12
for q in range(self.N_random_tests):
kwargs = {'a':random.uniform(1.,2.),'anom':random.uniform(0,2*math.pi),
'e':random.uniform(0.,1.),'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.,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))
def test_rand_r_to_orb_f(self):
places=12
for q in range(self.N_random_tests):
kwargs = {'a':random.uniform(1.,2.),'anom':random.uniform(0,2*math.pi),
'e':random.uniform(0.,1.),'omega':random.uniform(0,2*math.pi),
'inc':random.uniform(0,math.pi),'Omega':random.uniform(0,2*math.pi)}
p = rebound.kepler_particle(m=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.f),places), True,'{}'.format(kwargs))
def test_specified_r_to_orb(self):
"""test conversion from orbital elements to cartesian and back with specified cases"""
cases = ({'m':0.,'primary':self.sun,'a':1.,'anom':0.,'e':.01,'omega':0.,'inc':0.,'Omega':0.},
{'m':0.,'primary':self.sun,'a':1.,'anom':3.,'e':.999,'omega':3.,'inc':2.,'Omega':3.},
{'m':0.,'primary':self.sun,'a':1.,'anom':1.728,'e':.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))
cases = ({'m':0., 'primary':self.sun, 'a':1},
{'m':0., 'primary':self.sun, 'a':1, 'e':0.01},
)
results = ({'a':1.,'anom':0.,'e':0.,'omega':0.,'inc':0.,'Omega':0.},
{'a':1.,'anom':0.,'e':0.01,'omega':0.,'inc':0.,'Omega':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))
def test_r_to_orb_defaults(self):
cases = ({'m':0., 'primary':self.sun, 'a':1},
{'m':0., 'primary':self.sun, 'a':1, 'e':0.01},
)
results = ({'a':1.,'anom':0.,'e':0.,'omega':0.,'inc':0.,'Omega':0.},
{'a':1.,'anom':0.,'e':0.01,'omega':0.,'inc':0.,'Omega':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))
def test_rand_r_to_orb_f(self):
places=12
for q in range(self.N_random_tests):
kwargs = {'a':random.uniform(1.,2.),'anom':random.uniform(0,2*math.pi),
'e':random.uniform(0.,1.),'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.,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))
def test_specified_r_to_orb(self):
"""test conversion from orbital elements to cartesian and back with specified cases"""
cases = ({'m':0.,'primary':self.sun,'a':1.,'anom':0.,'e':.01,'omega':0.,'inc':0.,'Omega':0.},
{'m':0.,'primary':self.sun,'a':1.,'anom':3.,'e':.999,'omega':3.,'inc':2.,'Omega':3.},
{'m':0.,'primary':self.sun,'a':1.,'anom':1.728,'e':.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))
def test_rand_r_to_orb_f(self):
places=12
for q in range(self.N_random_tests):
kwargs = {'a':random.uniform(1.,2.),'anom':random.uniform(0,2*math.pi),
'e':random.uniform(0.,1.),'omega':random.uniform(0,2*math.pi),
'inc':random.uniform(0,math.pi),'Omega':random.uniform(0,2*math.pi)}
p = rebound.kepler_particle(m=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.f),places), True,'{}'.format(kwargs))
def test_rand_r_to_orb_f(self):
places=12
for q in range(self.N_random_tests):
kwargs = {'a':random.uniform(1.,2.),'anom':random.uniform(0,2*math.pi),
'e':random.uniform(0.,1.),'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.,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))