code: def cart2dir(self,cart):
          
  #        print "calling cart2dir(), not in anything"
          cart=numpy.array(cart)
          rad=old_div(numpy.pi,180.) # constant to convert degrees to radians
          if len(cart.shape)>1:
              Xs,Ys,Zs=cart[:,0],cart[:,1],cart[:,2]
          else: #single vector
              Xs,Ys,Zs=cart[0],cart[1],cart[2]
          Rs=numpy.sqrt(Xs**2+Ys**2+Zs**2) # calculate resultant vector length
          Decs=(old_div(numpy.arctan2(Ys,Xs),rad))%360. # calculate declination taking care of correct quadrants (arctan2) and making modulo 360.
          try:
              Incs=old_div(numpy.arcsin(old_div(Zs,Rs)),rad) # calculate inclination (converting to degrees) #
          except:
              print('trouble in cart2dir') # most likely division by zero somewhere
              return numpy.zeros(3)
  
          return numpy.array([Decs,Incs,Rs]).transpose()
docs: converts a direction to cartesian coordinates