code: def XYZ_to_galcenrect(X,Y,Z,Xsun=1.,Zsun=0.,_extra_rot=True):
      
      if _extra_rot:
          X,Y,Z= nu.dot(galcen_extra_rot,nu.array([X,Y,Z]))
      dgc= nu.sqrt(Xsun**2.+Zsun**2.)
      costheta, sintheta= Xsun/dgc, Zsun/dgc
      return nu.dot(nu.array([[costheta,0.,-sintheta],
                              [0.,1.,0.],
                              [sintheta,0.,costheta]]),
                    nu.array([-X+dgc,Y,nu.sign(Xsun)*Z])).T
docs: NAME:
  
         XYZ_to_galcenrect
  
      PURPOSE:
  
         transform XYZ coordinates (wrt Sun) to rectangular Galactocentric coordinates
  
      INPUT:
  
         X - X
  
         Y - Y
  
         Z - Z
  
         Xsun - cylindrical distance to the GC
         
         Zsun - Sun's height above the midplane
  
         _extra_rot= (True) if True, perform an extra tiny rotation to align the Galactocentric coordinate frame with astropy's definition
  
      OUTPUT:
  
         (Xg, Yg, Zg)
  
      HISTORY:
  
         2010-09-24 - Written - Bovy (NYU)
  
         2016-05-12 - Edited to properly take into account the Sun's vertical position; dropped Ysun keyword - Bovy (UofT)
  
         2018-04-18 - Tweaked to be consistent with astropy's Galactocentric frame - Bovy (UofT)