code: def impulse_deltav_general(v,y,b,w,pot):
      
      pot= flatten_potential(pot)
      if len(v.shape) == 1: v= numpy.reshape(v,(1,3))
      nv= v.shape[0]
      # Build the rotation matrices and their inverse
      rot= _rotation_vy(v)
      rotinv= _rotation_vy(v,inv=True)
      # Rotate the subhalo's velocity to the stream frames
      tilew= numpy.sum(rot*numpy.tile(w,(nv,3,1)),axis=-1)
      tilew[:,1]-=numpy.sqrt(numpy.sum(v**2.,axis=1))
      wmag = numpy.sqrt(tilew[:,0]**2+tilew[:,2]**2)
      b0 = b*numpy.array([-tilew[:,2]/wmag,numpy.zeros(nv),tilew[:,0]/wmag]).T
      return numpy.array(list(map(lambda i:numpy.sum(i[3]
                         *_deltav_integrate(i[0],i[1],i[2],pot).T,axis=-1)
                          ,zip(y,b0,tilew,rotinv))))
docs: NAME:
  
         impulse_deltav_general
  
  
      PURPOSE:
  
         calculate the delta velocity to due an encounter with a general spherical potential in the impulse approximation; allows for arbitrary velocity vectors, but y is input as the position along the stream
  
      INPUT:
  
         v - velocity of the stream (nstar,3)
  
         y - position along the stream (nstar)
  
         b - impact parameter
  
         w - velocity of the subhalo (3)
  
         pot - Potential object or list thereof (should be spherical)
  
      OUTPUT:
  
         deltav (nstar,3)
  
      HISTORY:
  
         2015-05-04 - SANDERS
  
         2015-06-15 - Tweak to use galpy' potential objects - Bovy (IAS)