def cartesianToSpherical(x, y, z):
  """
  Convert Cartesian to spherical coordinates. The input can be scalars or 1-dimensional numpy arrays.
  Note that the angle coordinates follow the astronomical convention of using elevation (declination,
  latitude) rather than its complement (pi/2-elevation), which is commonly used in the mathematical
  treatment of spherical coordinates.

  Parameters
  ----------
  
  x - Cartesian vector component along the X-axis
  y - Cartesian vector component along the Y-axis
  z - Cartesian vector component along the Z-axis

  Returns
  -------
  
  The spherical coordinates r=sqrt(x*x+y*y+z*z), longitude phi, latitude theta.
  
  NOTE THAT THE LONGITUDE ANGLE IS BETWEEN 0 AND +2PI. FOR r=0 AN EXCEPTION IS RAISED.
  """
  rCylSq=x*x+y*y
  r=sqrt(rCylSq+z*z)
  if any(r==0.0):
    raise Exception("Error: one or more of the points is at distance zero.")
  phi = arctan2(y,x)
  phi = where(phi<0.0, phi+2*pi, phi)
  return r, phi, arctan2(z,sqrt(rCylSq))
def cartesianToSpherical(x, y, z):
  """
  Convert Cartesian to spherical coordinates. The input can be scalars or 1-dimensional numpy arrays.
  Note that the angle coordinates follow the astronomical convention of using elevation (declination,
  latitude) rather than its complement (pi/2-elevation), which is commonly used in the mathematical
  treatment of spherical coordinates.

  Parameters
  ----------
  
  x - Cartesian vector component along the X-axis
  y - Cartesian vector component along the Y-axis
  z - Cartesian vector component along the Z-axis

  Returns
  -------
  
  The spherical coordinates r=sqrt(x*x+y*y+z*z), longitude phi, latitude theta.
  
  NOTE THAT THE LONGITUDE ANGLE IS BETWEEN 0 AND +2PI. FOR r=0 AN EXCEPTION IS RAISED.
  """
  rCylSq=x*x+y*y
  r=sqrt(rCylSq+z*z)
  if any(r==0.0):
    raise Exception("Error: one or more of the points is at distance zero.")
  phi = arctan2(y,x)
  phi = where(phi<0.0, phi+2*pi, phi)
  return r, phi, arctan2(z,sqrt(rCylSq))
def cartesianToSpherical ( x , y , z ) : rCylSq = x * x + y * y r = sqrt ( rCylSq + z * z ) if any ( r == 0.0 ) : raise Exception ( "Error: one or more of the points is at distance zero." ) phi = arctan2 ( y , x ) phi = where ( phi < 0.0 , phi + 2 * pi , phi ) return r , phi , arctan2 ( z , sqrt ( rCylSq ) )
Convert Cartesian to spherical coordinates. The input can be scalars or 1-dimensional numpy arrays.
  Note that the angle coordinates follow the astronomical convention of using elevation (declination,
  latitude) rather than its complement (pi/2-elevation), which is commonly used in the mathematical
  treatment of spherical coordinates.

  Parameters
  ----------
  
  x - Cartesian vector component along the X-axis
  y - Cartesian vector component along the Y-axis
  z - Cartesian vector component along the Z-axis

  Returns
  -------
  
  The spherical coordinates r=sqrt(x*x+y*y+z*z), longitude phi, latitude theta.
  
  NOTE THAT THE LONGITUDE ANGLE IS BETWEEN 0 AND +2PI. FOR r=0 AN EXCEPTION IS RAISED.
Convert Cartesian to spherical coordinates . The input can be scalars or 1 - dimensional numpy arrays . Note that the angle coordinates follow the astronomical convention of using elevation ( declination latitude ) rather than its complement ( pi / 2 - elevation ) which is commonly used in the mathematical treatment of spherical coordinates .