JohannesBuchner / regulargrid

Regular Grid Multivariate linear interpolation
BSD 2-Clause "Simplified" License
21 stars 1 forks source link

test_interpnd.py doesn't work #1

Open andreas-h opened 10 years ago

andreas-h commented 10 years ago

On my 64bit Ubuntu 13.10 system, test_interpnd.py fails:

In [6]: numpy.__version__, scipy.__version__
Out[6]: ('1.7.1', '0.12.0')

In [7]: %run test/test_interpnd.py
(8, 10, 9) (8, 10, 9) (8, 10, 9)
(8, 10, 9) 3.96624731711e-05 1.85481966135
evaluating
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
/usr/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
    176             else:
    177                 filename = fname
--> 178             __builtin__.execfile(filename, *where)

/home2/hilboll/Code/regulargrid/test/test_interpnd.py in <module>()
     27                 zvalues = []
     28                 for zi in zv:
---> 29                         v = interpn(x, y, z, a, xi, zi, yi)
     30                         #z = numpy.exp(-0.5 * (((xi-0.3)/0.2)**2 + ((yi-0.6)/0.3)**2))
     31                         zvalues.append(v)

/home2/hilboll/Code/regulargrid/regulargrid/interpn.py in interpn(*args, **kw)
     21         for j in range(nd):
     22                 #print q[j].shape, a.shape
---> 23                 a = interp1d(q[j], a, axis=j, kind=method)(qi[j])
     24         return a
     25 

/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.pyc in __init__(self, x, y, kind, axis, copy, bounds_error, fill_value)
    328                  copy=True, bounds_error=True, fill_value=np.nan):
    329         """ Initialize a 1D linear interpolation class."""
--> 330         _Interpolator1D.__init__(self, x, y, axis=axis)
    331 
    332         self.copy = copy

/usr/lib/python2.7/dist-packages/scipy/interpolate/polyint.pyc in __init__(self, xi, yi, axis)
     31         self.dtype = None
     32         if yi is not None:
---> 33             self._set_yi(yi, xi=xi, axis=axis)
     34 
     35     def __call__(self, x):

/usr/lib/python2.7/dist-packages/scipy/interpolate/polyint.pyc in _set_yi(self, yi, xi, axis)
     89         if shape == ():
     90             shape = (1,)
---> 91         if xi is not None and shape[axis] != len(xi):
     92             raise ValueError("x and y arrays must be equal in length along "
     93                              "interpolation axis.")

IndexError: tuple index out of range

In [6]: numpy.__version__, scipy.__version__
Out[6]: ('1.7.1', '0.12.0')

In [7]: %run test/test_interpnd.py
(8, 10, 9) (8, 10, 9) (8, 10, 9)
(8, 10, 9) 3.96624731711e-05 1.85481966135
evaluating
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
/usr/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
    176             else:
    177                 filename = fname
--> 178             __builtin__.execfile(filename, *where)

/home2/hilboll/Code/regulargrid/test/test_interpnd.py in <module>()
     27                 zvalues = []
     28                 for zi in zv:
---> 29                         v = interpn(x, y, z, a, xi, zi, yi)
     30                         #z = numpy.exp(-0.5 * (((xi-0.3)/0.2)**2 + ((yi-0.6)/0.3)**2))
     31                         zvalues.append(v)

/home2/hilboll/Code/regulargrid/regulargrid/interpn.py in interpn(*args, **kw)
     21         for j in range(nd):
     22                 #print q[j].shape, a.shape
---> 23                 a = interp1d(q[j], a, axis=j, kind=method)(qi[j])
     24         return a
     25 

/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.pyc in __init__(self, x, y, kind, axis, copy, bounds_error, fill_value)
    328                  copy=True, bounds_error=True, fill_value=np.nan):
    329         """ Initialize a 1D linear interpolation class."""
--> 330         _Interpolator1D.__init__(self, x, y, axis=axis)
    331 
    332         self.copy = copy

/usr/lib/python2.7/dist-packages/scipy/interpolate/polyint.pyc in __init__(self, xi, yi, axis)
     31         self.dtype = None
     32         if yi is not None:
---> 33             self._set_yi(yi, xi=xi, axis=axis)
     34 
     35     def __call__(self, x):

/usr/lib/python2.7/dist-packages/scipy/interpolate/polyint.pyc in _set_yi(self, yi, xi, axis)
     89         if shape == ():
     90             shape = (1,)
---> 91         if xi is not None and shape[axis] != len(xi):
     92             raise ValueError("x and y arrays must be equal in length along "
     93                              "interpolation axis.")

IndexError: tuple index out of range
JohannesBuchner commented 10 years ago

True. I think that never has worked. Sorry.

Use the classes in regulargrid.py (CartesianGrid and RegularGrid). test/test_cartesiangrid.py shows how (and that one actually does work ;) .