import math


def to_spherical(r):
    """ Convert xyz vector a single row of three elements to spherical """
    x,y,z = r
    r = math.sqrt(x**2 + y**2 + z**2)              
    theta = math.atan2(y,x)                          
    phi = math.atan2(z,math.sqrt(x**2 + y**2))     
    return r, theta, phi