【发布时间】:2015-08-23 10:59:28
【问题描述】:
我在使用 scipy.interpolate.griddata 时遇到错误。我的目标是使用 matplotlib 为轮廓准备数据。我已经读过,执行此操作的最佳方法是在传递给 griddata 之前使用 linspace 将 x any y 分隔为一维数组。
我的 x 和 y 值的最小值和最大值用于输入到 linspace,以便为 GIS 映射目的保持坐标相同(不确定是否有必要将数据点放入与网格坐标相同的 xy 区域,但无论如何都是这样做的)
Watertable CSV 文件作为具有 x、y 和 z 值的 numpy 数组导入。 z 作为直接数组列索引提供给 griddata。
我遇到了错误“valueError:输入数据点的形状无效”
我确信这是非常简单的事情,希望有人能解释我的错误。
[编辑]
我已按照建议使用 pastebin 链接了 csv 文件:
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')
然后我的脚本退出并出现以下错误:
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
【问题讨论】:
-
有人可能会注意到这个,但对于我们这些不能的人来说,你的 csv 会让调查变得更容易。如果您没有办法托管它,我认为您可以使用pastebin。
-
谢谢,刚刚更新了指向 csv 粘贴的链接
标签: scipy