我正在尝试使用scipy.interpolate.interp1d
将经度和纬度值绘制为地图图像的x坐标和y坐标像素。我有样本值:
y = [0, 256, 512, 768, 1024, 1280, 1536]
lat = [615436414755, 615226949459, 615017342897, 614807595000, 614597705702, 614387674936, 614177502635]
x = [0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304]
lon = [235986328125, 236425781250, 236865234375, 237304687500, 237744140625, 238183593750, 238623046875, 239062500000, 239501953125, 239941406250]
当我传递给这样的函数时:
xInterpolation = interp1d(xDegree, xPixel)
yInterpolation = interp1d(yDegree, yPixel)
return (int(xInterpolation(lon)),int(yInterpolation(lat)))
我得到了价值错误:
ValueError(“x_new中的值高于插值”ValueError:x_new中的值高于插值范围。
无论我尝试什么值,它都会抛出值错误,我甚至尝试给出输入列表中相同的lat或lon值,但这些值也不起作用。有谁知道这里发生了什么?或者如果我使用错误的插值。
答案 0 :(得分:1)
来自interp1d
docs:
bounds_error:bool,optional如果为True,则会随时引发ValueError 尝试对x范围之外的值进行插值(其中 外推是必要的)。如果为False,则超出边界值 分配了fill_value。默认情况下,会引发错误。
因此,你的一些插值数据高于插值限制。你试图推断,而不是插值。
使用
等插值时 xInterpolation = interp1d(xDegree, xPixel)
xInterpolation(lon)
来自lon
的所有值都必须属于[xDegree.min, xDegree.max]
区间。
因此,您需要更正数据以进行插值或使用extrapolation。