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_cartesian_to_spherical():
expected = np.array([[1, 45, 45], [1, -45, 135]], dtype=np.float32)
data = np.array([[0.5, 0.5, 0.7071], [0.5, -0.5, -0.7071]])
result = np.zeros_like(expected)
radial, azimuthal, polar = cartesian_to_spherical(data)
result[:, 0] = radial
result[:, 1] = azimuthal
result[:, 2] = polar
assert np.all(np.isclose(result, expected))
expected[:, 1:] = np.deg2rad(expected[:, 1:])
radial, azimuthal, polar = cartesian_to_spherical(data, degrees=False)
result[:, 0] = radial
result[:, 1] = azimuthal
result[:, 2] = polar
assert np.all(np.isclose(result, expected))
def test_cartesian_to_spherical():
expected = np.array([[1, 45, 45], [1, -45, 135]], dtype=np.float32)
data = np.array([[0.5, 0.5, 0.7071], [0.5, -0.5, -0.7071]])
result = np.zeros_like(expected)
radial, azimuthal, polar = cartesian_to_spherical(data)
result[:, 0] = radial
result[:, 1] = azimuthal
result[:, 2] = polar
assert np.all(np.isclose(result, expected))
expected[:, 1:] = np.deg2rad(expected[:, 1:])
radial, azimuthal, polar = cartesian_to_spherical(data, degrees=False)
result[:, 0] = radial
result[:, 1] = azimuthal
result[:, 2] = polar
assert np.all(np.isclose(result, expected))
def compute(self):
radial, theta, phi = cartesian_to_spherical(
self.points, degrees=self.degrees)
self.to_be_added["radial"] = radial
self.to_be_added["polar"] = theta
self.to_be_added["azimuthal"] = phi