NF: Find the closest vertex on a sphere for an input vector.

This is useful for both https://github.com/nipy/dipy/pull/460 and https://github.com/nipy/dipy/pull/419 so needs to take precedence. It's not quite done yet, though. Will hopefully have a chance to finish this later today. 
Looks good to me! +1

In dipy/core/sphere.py:

> +    def find_closest(self, xyz):
> +        """
> +        Find the index of the vertex in the Sphere closest to the input vector
> +
> +        Parameters
> +        ----------
> +        xyz : array-like, 3 elements
> +            A unit vector
> +
> +        Return
> +        ------
> +        idx : int
> +            The index into the Sphere.vertices array that gives the closest
> +            vertex (in angle).
> +        """
> +        ang = np.arccos(np.dot(self.vertices, xyz))

Thanks for the comments and suggestions. How about the following solution?
Have each of these classes have it's own (just very slightly different)
implementation of this function, taking or not taking the absolute value,
as needed. I have also added a test to demonstrate that scaling by l2norm
is not necessary, as long as you are not interested in the angle, but
rather just in finding the index of the minimal.
… <#149ee0c9a5adaa44_>
On Wed, Nov 26, 2014 at 12:22 PM, Samuel St-Jean <notifications@github.com>
wrote: In dipy/core/sphere.py: > + def find_closest(self, xyz): > + """ > +
Find the index of the vertex in the Sphere closest to the input vector > +
> + Parameters > + ---------- > + xyz : array-like, 3 elements > + A unit
vector > + > + Return > + ------ > + idx : int > + The index into the
Sphere.vertices array that gives the closest > + vertex (in angle). > + """
> + ang = np.arccos(np.dot(self.vertices, xyz)) I also have a similar
function like that, and by experience not using real unit vectors (like
bvecs for example, which are almost unit vector by default) let to
instability in the result. Why not make it trulty general by dividing by
the l2 norm and be able to pass any vector as an added bonus? I also clip
the result between -1 and 1 because of imprecision in the division step. —
Reply to this email directly or view it on GitHub <
https://github.com/nipy/dipy/pull/483/files#r20961761>.

—
Reply to this email directly or view it on GitHub
<https://github.com/nipy/dipy/pull/483/files#r20965750>.