ValueError: invalid shape for input data points in griddata operation
Question: I am running into an error when using scipy.interpolate.griddata. My goal is
to prepare data for contouring using matplotlib. I have read that the best way
to perform this is to separate the x any y as 1D arrays using linspace before
passing to griddata.

The min and max values of my x and y values are used to input into the
linspace, so as to keep the co-ordinates the same for GIS mapping purposes
(not sure if this is necessary to have the data points in the same xy area as
the grid co-ordinates, but am doing so any way)

The file Watertable CSV is imported as a numpy array with x,y and z values.
The z is supplied to griddata as a straight array column index.

I am running into the error "valueError: invalid shape for input data points"

I am sure it is something very simple and hopefully someone can shed light on
my error.

[EDIT]

I have linked the csv file using pastebin as suggested:

<http://pastebin.com/nj7THgMw>

    
    
    import numpy as np
    from scipy.interpolate import griddata
    from numpy import genfromtxt
    
    
    my_data = genfromtxt('WaterTable.csv', delimiter=',')
    x = my_data[1:,0:1]
    y = my_data[1:,1:2]
    z = my_data[1:,2:3]
    
    xmax = max(x)
    xmin = min(x)
    ymax = max(y)
    ymin = min(y)
    
    xi = np.linspace(xmin, xmax, 2000)
    
    yi = np.linspace(ymin, ymax, 2000)
    
    zi = griddata((x, y), z, (xi, yi), method='cubic')
    

I script then exits with the following error:

    
    
    Traceback (most recent call last):
    File "C:/Users/Hp/PycharmProjects/GISdev/Irregular_Grid03.py", line 60, in <module>
    zi = griddata((x, y), z, (xi, yi), method='cubic')
    File "C:\Python27\lib\site-packages\scipy\interpolate\ndgriddata.py", line 212, in griddata
    rescale=rescale)
    File "scipy/interpolate/interpnd.pyx", line 840, in scipy.interpolate.interpnd.CloughTocher2DInterpolator.__init__ (scipy\interpolate\interpnd.c:9961)
    File "scipy/interpolate/interpnd.pyx", line 78, in scipy.interpolate.interpnd.NDInterpolatorBase.__init__ (scipy\interpolate\interpnd.c:2356)
    File "scipy/interpolate/interpnd.pyx", line 123, in scipy.interpolate.interpnd.NDInterpolatorBase._check_init_shape (scipy\interpolate\interpnd.c:3128)
    ValueError: invalid shape for input data points
    


Answer: Your arrays `x`, `y` and `z` are _two-dimensional_ , with shape `(n, 1)`.
`griddata` expects _one-dimensional_ arrays (i.e. with shape `(n,)`).

To fix this, use a single index instead of a slice in the second index
position when you pull the arrays out of `my_data`:

    
    
    x = my_data[1:, 0]
    y = my_data[1:, 1]
    z = my_data[1:, 2]
    

