code: def rectgal_to_sphergal(X,Y,Z,vx,vy,vz,degree=False):
      
      lbd= XYZ_to_lbd(X,Y,Z,degree=degree)
      vrpmllpmbb= vxvyvz_to_vrpmllpmbb(vx,vy,vz,X,Y,Z,XYZ=True)
      if sc.array(X).shape == ():
          return sc.array([lbd[0],lbd[1],lbd[2],vrpmllpmbb[0],vrpmllpmbb[1],vrpmllpmbb[2]])
      else:
          out=sc.zeros((len(X),6))
          out[:,0:3]= lbd
          out[:,3:6]= vrpmllpmbb
          return out
docs: NAME:
  
         rectgal_to_sphergal
  
      PURPOSE:
  
         transform phase-space coordinates in rectangular Galactic coordinates to spherical Galactic coordinates (can take vector inputs)
  
      INPUT:
  
         X - component towards the Galactic Center (kpc)
  
         Y - component in the direction of Galactic rotation (kpc)
  
         Z - component towards the North Galactic Pole (kpc)
  
         vx - velocity towards the Galactic Center (km/s)
  
         vy - velocity in the direction of Galactic rotation (km/s)
  
         vz - velocity towards the North Galactic Pole (km/s)
  
         degree - (Bool) if True, return l and b in degrees
  
      OUTPUT:
  
         (l,b,d,vr,pmll x cos(b),pmbb) in (rad,rad,kpc,km/s,mas/yr,mas/yr)
  
      HISTORY:
  
         2009-10-25 - Written - Bovy (NYU)