Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scipy.interpolate.interpnd complaining about 'Delaunay' object has no attribute 'simplices'

I'm dusting off some code I wrote a few months ago, and for some reason it doesn't work anymore... In a nutshell, I'm using scipy.interpolate.LinearNDInterpolator objects to interpolate models and compare to data. Now, when I attempt to call the interpolator object with the coordinates at which I would like the interpolation, I get the following error:

In [9]: a([[3500, 3.5, 1.5]])
AttributeError                            Traceback (most recent call last)
<ipython-input-9-91f2103e7a0c> in <module>()
----> 1 a([[3500, 3.5, 1.5]])

/usr/lib64/python2.7/site-packages/scipy/interpolate/interpnd.so in     scipy.interpolate.interpnd.NDInterpolatorBase.__call__ (scipy/interpolate/interpnd.c:3133)()

/usr/lib64/python2.7/site-packages/scipy/interpolate/interpnd.so in     scipy.interpolate.interpnd.LinearNDInterpolator._evaluate_double (scipy/interpolate/interpnd.c:3954)()

/usr/lib64/python2.7/site-packages/scipy/interpolate/interpnd.so in scipy.interpolate.interpnd.LinearNDInterpolator._do_evaluate (scipy/interpolate/interpnd.c:4684)()

AttributeError: 'Delaunay' object has no attribute 'simplices'

I have never seen this error before, and the code has worked previously. Did something just change in scipy that I'm not aware of?

Thanks for looking!

like image 709
soylentdeen Avatar asked Oct 22 '22 02:10

soylentdeen


1 Answers

I guess you use an older version of the library:

The Delaunay library has two different accessors for simplices: "Delaunay.simplices" and "Delaunay.vertices" shown here (newest docs): http://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.Delaunay.html

Of the two Delaunay.vertices is marked "deprecated".

On Ubuntu 13.04 the simplices call does not exist however, because it still uses scipy 0.11.0: http://docs.scipy.org/doc/scipy-0.11.0/reference/generated/scipy.spatial.Delaunay.html#scipy.spatial.Delaunay

Try with this minimal example or just rewrite your simplices call to vertices:

from __future__ import print_function

import numpy as np
from scipy.spatial import Delaunay
import sys

my_molecule = np.random.rand(400,3) #points for query
points = np.random.rand(1000, 3)   #points used for Triangulation

diag = Delaunay(points)
simplices = diag.find_simplex(my_molecule)

for point,simplex in zip(my_molecule,simplices):
    if simplex == -1:
        print ("Point not included in diag.")
        continue
    print ("Doing vertices call: ")
    spoints = diag.vertices[simplex]
    print ("Doing simplices call: ")
    spoints = diag.simplices[simplex]
like image 133
tstrunk Avatar answered Nov 03 '22 20:11

tstrunk