Reputation: 1
I am working with scipy.interpolate() and create a map using a methodology similar to the example. So, I need to use the X, Y, Z values from the interpolated surface in another software. How can I export the data that is stored in a grid format as X, Y, Z values? Thanks a lot for your suggestions...
Example
import numpy as np
import scipy.interpolate
import matplotlib.pyplot as plt
np.random.seed(1234)
x, y, z = np.random.random((3, 10))
interp = scipy.interpolate.Rbf(x, y, z, function='thin_plate')
yi, xi = np.mgrid[0:1:100j, 0:1:100j]
zi = interp(xi, yi)
plt.plot(x, y, 'ko')
plt.imshow(zi.T, extent=[0, 1, 1, 0], cmap='gist_earth')
plt.colorbar()
plt.show()
Upvotes: 0
Views: 672
Reputation: 1
You can get the X Y and Z values as a list with a nested loop then export with numpy.savetxt:
coordinateList = np.zeros([100*100,3])
for x in range(100):
for y in range(100):
coordinateList[x*100+y,0]=xi[x,y]
coordinateList[x*100+y,1]=yi[x,y]
coordinateList[x*100+y,2]=zi[x,y]
np.savetxt('data.csv', coordinateList, delimiter=',')
Upvotes: 0