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))
def simulation(par):
integrator, run, trial = par
sim = rebound.Simulation()
k = 0.01720209895
Gfac = 1./k
sim.dt = dt
if integrator == "whfast-nocor":
integrator = "whfast"
else:
sim.ri_whfast.corrector = 11
sim.integrator = integrator
sim.ri_whfast.safe_mode = 0
massfac = 1.
sim.add(m=1.00000597682, x=-4.06428567034226e-3, y=-6.08813756435987e-3, z=-1.66162304225834e-6, vx=+6.69048890636161e-6*Gfac, vy=-6.33922479583593e-6*Gfac, vz=-3.13202145590767e-9*Gfac) # Sun
sim.add(m=massfac/1407.355, x=+3.40546614227466e+0, y=+3.62978190075864e+0, z=+3.42386261766577e-2, vx=-5.59797969310664e-3*Gfac, vy=+5.51815399480116e-3*Gfac, vz=-2.66711392865591e-6*Gfac) # Jupiter
sim.add(m=massfac/3501.6, x=+6.60801554403466e+0, y=+6.38084674585064e+0, z=-1.36145963724542e-1, vx=-4.17354020307064e-3*Gfac, vy=+3.99723751748116e-3*Gfac, vz=+1.67206320571441e-5*Gfac) # Saturn
sim.add(m=massfac/22869., x=+1.11636331405597e+1, y=+1.60373479057256e+1, z=+3.61783279369958e-1, vx=-3.25884806151064e-3*Gfac, vy=+2.06438412905916e-3*Gfac, vz=-2.17699042180559e-5*Gfac) # Uranus
sim.add(m=massfac/19314., x=-3.01777243405203e+1, y=+1.91155314998064e+0, z=-1.53887595621042e-1, vx=-2.17471785045538e-4*Gfac, vy=-3.11361111025884e-3*Gfac, vz=+3.58344705491441e-5*Gfac) # Neptune