def test_spherical_cartesian(): theta, phi = erfa.c2s([0.0, np.sqrt(2.0), np.sqrt(2.0)]) np.testing.assert_allclose(theta, np.pi / 2.0) np.testing.assert_allclose(phi, np.pi / 4.0) theta, phi, r = erfa.p2s([0.0, np.sqrt(2.0), np.sqrt(2.0)]) np.testing.assert_allclose(theta, np.pi / 2.0) np.testing.assert_allclose(phi, np.pi / 4.0) np.testing.assert_allclose(r, 2.0) pv = np.array(([0.0, np.sqrt(2.0), np.sqrt(2.0)], [1.0, 0.0, 0.0]), dtype=erfa.dt_pv) theta, phi, r, td, pd, rd = erfa.pv2s(pv) np.testing.assert_allclose(theta, np.pi / 2.0) np.testing.assert_allclose(phi, np.pi / 4.0) np.testing.assert_allclose(r, 2.0) np.testing.assert_allclose(td, -np.sqrt(2.0) / 2.0) np.testing.assert_allclose(pd, 0.0) np.testing.assert_allclose(rd, 0.0) c = erfa.s2c(np.pi / 2.0, np.pi / 4.0) np.testing.assert_allclose( c, [0.0, np.sqrt(2.0) / 2.0, np.sqrt(2.0) / 2.0], atol=1e-14) c = erfa.s2p(np.pi / 2.0, np.pi / 4.0, 1.0) np.testing.assert_allclose( c, [0.0, np.sqrt(2.0) / 2.0, np.sqrt(2.0) / 2.0], atol=1e-14) pv = erfa.s2pv(np.pi / 2.0, np.pi / 4.0, 2.0, np.sqrt(2.0) / 2.0, 0.0, 0.0) np.testing.assert_allclose( pv['p'], [0.0, np.sqrt(2.0), np.sqrt(2.0)], atol=1e-14) np.testing.assert_allclose(pv['v'], [-1.0, 0.0, 0.0], atol=1e-14)
def test_float32_input(): # Regression test for gh-8615 xyz = np.array([[1, 0, 0], [0.9, 0.1, 0]]) out64 = erfa.p2s(xyz) out32 = erfa.p2s(xyz.astype('f4')) np.testing.assert_allclose(out32, out64, rtol=1.e-5)