def test_kepler_read_only(self): orb = Orbit(M0=self.M, G=self.G, kepler_read_only=True, **self.cart_orb) a = orb.a with self.assertRaises(AttributeError): orb.a = 1 orb.x += 0.1 with self.assertRaises(AssertionError): nt.assert_array_equal(a, orb.a)
def test_delete(self): orb = Orbit(M0=self.M, G=self.G, m=0.1, **self.kep_orb) a0 = self.kep_orb['a'] inds = [2,4,6] orb.add(num=9, **self.kep_orb) a = orb.a a[inds] = a0 + 2 orb.a = a orb.delete(inds) assert orb.num == 10-3 assert np.all(orb.a < a0 + 1)
def test_disable_update(self): orb = Orbit(M0=self.M, G=self.G, direct_update=False, auto_update=False, **self.cart_orb) assert np.all(np.isnan(orb.kepler)) orb.x += 1 assert np.all(np.isnan(orb.kepler)) orb.calculate_kepler() kep0 = orb.kepler print('Before cart change') print(orb) orb.x += 1 kep = orb.kepler print('After cart change') print(orb) nt.assert_array_equal(kep0, kep) orb = Orbit(M0=self.M, G=self.G, direct_update=False, auto_update=False, **self.kep_orb) assert np.all(np.isnan(orb.cartesian)) orb.a += 1 assert np.all(np.isnan(orb.cartesian)) orb.a = 1 orb.calculate_cartesian() cart0 = orb.cartesian print('Before kep change') print(orb) orb.a += 1 cart = orb.cartesian print('After kep change') print(orb) nt.assert_array_equal(cart0, cart)
def test_direct_update_cart(self): orb = Orbit(M0=self.M, G=self.G, direct_update=True, **self.kep_orb) assert orb.direct_update is True assert np.all(np.logical_not(np.isnan(orb.cartesian))) kep0 = orb.cartesian print('Before cart change') print(orb) orb.a += 1 kep = orb.cartesian print('After cart change') print(orb) with self.assertRaises(AssertionError): nt.assert_array_equal(kep0, kep) orb = Orbit(M0=self.M, G=self.G, direct_update=False, **self.kep_orb) assert orb.direct_update is False assert np.all(np.isnan(orb._cart)), 'internally before access should be nan' assert np.all(np.logical_not(np.isnan(orb.cartesian))), 'With auto_update should be calculated' kep0 = orb.cartesian print('Before cart change') print(orb) orb.a = 2 kep = orb._cart.copy() print('After cart change') print(orb) kep2 = orb.cartesian nt.assert_array_equal(kep0, kep) with self.assertRaises(AssertionError): nt.assert_array_equal(kep0, kep2)