code: def cart2spher(x, y, z):
      
      hxy = np.hypot(x, y)
      r = np.hypot(hxy, z)
      theta = np.arctan2(z, hxy)
      phi = np.arctan2(y, x)
      return r, theta, phi
docs: Cartesian to Spherical coordinate conversion.