code: def cartesian_to_spherical(cartesian):
      
      xyz = cartesian
      xy = xyz[:,0]**2 + xyz[:,1]**2
      r = np.sqrt(xy + xyz[:,2]**2)
      phi = np.arctan2(np.sqrt(xy), xyz[:,2]) # for elevation angle defined from Z-axis down
      #ptsnew[:,4] = np.arctan2(xyz[:,2], np.sqrt(xy)) # for elevation angle defined from XY-plane up
      theta = np.arctan2(xyz[:,1], xyz[:,0])
      return np.array([r, theta, phi]).T
docs: Convert cartesian to spherical coordinates passed as (N,3) shaped arrays.