Reputation: 441
I am trying to use the class shown here to interpolate some data.
I am having trouble getting this class to work. A minimal example is:
#!/usr/bin/env python
import sys
from mayavi.mlab import *
from mayavi import mlab
from numpy import *
import numpy as np
from mayavi.scripts import mayavi2
from mayavi.sources.vtk_file_reader import VTKFileReader
from mayavi.modules.outline import Outline
from mayavi.modules.grid_plane import GridPlane
from mayavi.modules.contour_grid_plane import ContourGridPlane
from mayavi.modules.iso_surface import IsoSurface
from mayavi.modules.scalar_cut_plane import ScalarCutPlane
import scipy
from scipy import interpolate
from scipy.interpolate import griddata
#from scipy.interpolate import RegularGridInterpolator
print 'Argument List:', str(sys.argv)
if (len(sys.argv)==5):
NX = int(sys.argv[1])
NY = int(sys.argv[2])
NZ = int(sys.argv[3])
fname = sys.argv[4]
else:
print "Error in parsing the command line arguments"
print "Command line arguments are: N_X N_Y N_Z filename "
sys.exit()
clf()
figure(bgcolor=(1, 1, 1))
len(sys.argv)
data = genfromtxt(fname)
x,y,z = mgrid[ 0:NX:1, 0:NY:1, 0:NZ:1 ]
#print(x)
index = 0
V=0*x
for k in range(NZ):
for j in range(NY):
for i in range(NX):
V[i][j][k] = 1000*data[index,5]
scipy.interpolate.RegularGridInterpolator(V, V, method='linear', bounds_error=True, fill_value=nan) #ERROR
The only bits really of interest to my current problem are the last line and all the import commands at the beginning
My error is:
Traceback (most recent call last):
File "contour-3d.py", line 70, in <module>
scipy.interpolate.RegularGridInterpolator(W, W, method='linear', bounds_error=True, fill_value=nan)
AttributeError: 'module' object has no attribute 'RegularGridInterpolator'
I'm not too familiar with python, so this may be a very basic error.
Upvotes: 0
Views: 3507
Reputation: 54330
scipy.interpolate.RegularGridInterpolator
is a new function in scipy
0.14.x
. You are likely to be using a older version. Updating scipy
should solve the problem.
Upvotes: 1
Reputation: 6700
From the docs:
New in version 0.14.
It's likely you have a previous version of SciPy. If you are using Ubuntu, try running pip
:
pip install --user --upgrade scipy
You might need some additional dependencies:
sudo apt-get install gcc gfortran python-dev libblas-dev liblapack-dev cython
For more information see http://www.scipy.org/install.html and http://www.scipy.org/scipylib/building/
Upvotes: 2