def test_three(): '''Three observations, the middle one an arc second off in both RA and Dec.''' mjd = [56123, 56123.01, 56123.02] pos = [ gcm.Sphr(dmsToRad(' ', 0, 0, -15), 0), gcm.Sphr(dmsToRad(' ', 0, 0, 1), dmsToRad(' ', 0, 0, 1)), gcm.Sphr(dmsToRad(' ', 0, 0, 15), 0)] eps = 1e-6 # gcm fit g = gcm.GCM(mjd, pos) # test the method that returns just residuals res = g.res() assert near(res[0][0], -1. / 3, eps) assert near(res[0][1], -1. / 3, eps) assert near(res[1][0], 2. / 3, eps) assert near(res[1][1], 2. / 3, eps) assert near(res[2][0], -1. / 3, eps) assert near(res[2][1], -1. / 3, eps) # assert( np.allclose( res , expectedRes ) ) # test the method that returns just rms assert near(g.rms(), 2 / 3, eps) # test the method that returns just both rms, res = g.rmsRes() assert near(res[0][0], -1. / 3, eps) assert near(res[0][1], -1. / 3, eps) assert near(res[1][0], 2. / 3, eps) assert near(res[1][1], 2. / 3, eps) assert near(res[2][0], -1. / 3, eps) assert near(res[2][1], -1. / 3, eps) assert near(rms, 2 / 3, eps)
def test_cartToSphr(): s = [gcm.Sphr(0, 0), gcm.Sphr(np.pi / 2, 0), gcm.Sphr(0, np.pi / 2), gcm.Sphr(np.pi / 4, 0), gcm.Sphr(np.pi / 6, -np.pi / 4)] c = [gcm.Cart(1, 0, 0), gcm.Cart(0, 1, 0), gcm.Cart(0, 0, 1), gcm.Cart(np.sqrt(2) / 2, np.sqrt(2) / 2, 0), gcm.Cart(np.sqrt(6) / 4, np.sqrt(2) / 4, -np.sqrt(2) / 2)] eps = 1e-14 for got, want in zip(gcm.cartToSphr(c), s): assert sphrNear(got, want, eps)
def test_sphrToCart(): s = [gcm.Sphr(0, 0), gcm.Sphr(np.pi / 2, 0), gcm.Sphr(0, np.pi / 2), gcm.Sphr(np.pi / 4, 0), gcm.Sphr(np.pi / 6, -np.pi / 4)] c = [gcm.Cart(1, 0, 0), gcm.Cart(0, 1, 0), gcm.Cart(0, 0, 1), gcm.Cart(np.sqrt(2) / 2, np.sqrt(2) / 2, 0), gcm.Cart(np.sqrt(6) / 4, np.sqrt(2) / 4, -np.sqrt(2) / 2)] eps = 1e-14 for got, want in zip(gcm.sphrToCart(s), c): assert cartNear(got, want, eps)
def test_two(): # two position test data mjd = [56123, 56123.01] pos = [ gcm.Sphr(0, dmsToRad(' ', 89, 59, 40)), gcm.Sphr(0, dmsToRad(' ', 90, 0, 0))] # gcm fit g = gcm.GCM(mjd, pos) # test the method that returns just residuals assert g.res() == [[0.0, 0.0], [0.0, 0.0]] # test the method that returns just rms assert g.rms() == 0 # test the method that returns both assert g.rmsRes() == (0, [[0.0, 0.0], [0.0, 0.0]])
def test_exceptions(): mjd = [56123, 56123.01, 56123.02] pos = [ gcm.Sphr(dmsToRad(' ', 0, 0, -15), 0), gcm.Sphr(dmsToRad(' ', 0, 0, 1), dmsToRad(' ', 0, 0, 1)), gcm.Sphr(dmsToRad(' ', 0, 0, 15), 0)] with pytest.raises(ValueError) as e: gcm.GCM(mjd[:-1], pos) assert str(e.value) == 'date and pos different lengths' with pytest.raises(ValueError) as e: gcm.GCM(mjd[:1], pos[:1]) assert str(e.value) == 'at least two positions needed' with pytest.raises(ValueError) as e: gcm.GCM([mjd[0], mjd[0]], pos[:2]) assert str(e.value) == 'positive elapsed time needed' with pytest.raises(ValueError) as e: gcm.GCM(mjd[:2], [pos[0], pos[0]]) assert str(e.value) == 'motion across sky needed'
def test_sphrStr(): assert str(gcm.Sphr( dmsToRad(' ', 1, 20, 0), dmsToRad('-', 14, 17, 8.5))) == '( 1 20 0.0, -14 17 8.5)'