【问题标题】:How can I extract (x,y,z) values from an interpolated grid in Python如何从 Python 中的插值网格中提取 (x,y,z) 值
【发布时间】:2020-09-04 12:41:52
【问题描述】:

我正在使用 scipy.interpolate() 并使用与示例类似的方法创建地图。所以,我需要在另一个软件中使用插值表面的 X、Y、Z 值。如何将存储在网格格式中的数据导出为 X、Y、Z 值? 非常感谢您的建议...

示例

''' 将 numpy 导入为 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()

'''

【问题讨论】:

    标签: python scipy grid spatial-interpolation xyz


    【解决方案1】:

    您可以使用嵌套循环将 X Y 和 Z 值作为列表获取,然后使用 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=',')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-02
      • 2019-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多