scipy ndimage to fill array for matplotlib interpolated data
<p>I have an array of data representing what might look like a topographic map when plotted using a contour map.  I am looking to expand the array to 'interpolate' data between points at a user-selected interval and then fill the missing elements with mean values between the existing data points.  For example:</p>

<pre><code>Original Array:
[[1 2 3]
[4 5 6]
[7 8 9]]

with 1X expansion becomes:
[[1 . 2 . 3]
[. . . . .]
[4 . 5 . 6]
[. . . . .]
[7 . 8 . 9]]
</code></pre>

<p>and the filled in '.' values would be the mean of those values in the data point region.  I understand that there are a number of ways to do something like this with scipy.ndimage filters, but it seems they all alter the original data values, i.e. gaussian_filter and ndimage.zoom.</p>

<p>I wonder if there is a filter that I'm missing that would expand this data array and retain the original values in their expanded positions and fill in the missing points with the 'interpolated' mean values?  If someone could point me in the right direction, I'll check it out, but all my searching and testing haven't yielded the results I'm looking for yet.</p>

<p>Here's a sample of the applicable code this is coming from.  The original x, y, and z values come from arrays created from a sql result on a mysql database,  I've tried 'order' variations from 0 to 5, all the listed modes I could find, and prefilter on and off.  I've also tried a number of options using the gaussian_filter as well.  The interpolation value is a number between 1 and 10 passed from user input:</p>

<pre><code>x=np.array(self.lon)
y=np.array(self.lat)
z=np.array(self.plotdata)
if (int(interpolation)&gt;0):
    x=scipy.ndimage.zoom(x, int(interpolation), order=0, mode='nearest', prefilter=True)
    y=scipy.ndimage.zoom(y, int(interpolation), order=0, mode='nearest', prefilter=True)
    z=scipy.ndimage.zoom(z, int(interpolation), order=0, mode='nearest', prefilter=True)
</code></pre>

<p>TIA</p>

<p>I was doing something similar and had issues with ndimage.zoom. It was skewing the images and I was never happy with the results. I found skimage.transform.resize. This worked much better and might be useful for you. </p>

<p><a href="http://scikit-image.org/docs/dev/api/skimage.transform.html#skimage.transform.resize" rel="nofollow">http://scikit-image.org/docs/dev/api/skimage.transform.html#skimage.transform.resize</a></p>

python numpy matplotlib scipy