【问题标题】:Python scipy.interpolate.interp1d not working with large float valuesPython scipy.interpolate.interp1d 不适用于大浮点值
【发布时间】:2017-02-05 13:28:20
【问题描述】:

我正在尝试使用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("a value in x_new is above the interpolation " ValueError: A value in x_new is above the interpolation range.

无论我尝试什么值,它都会引发值错误,我什至尝试给出与输入列表中相同的 lat 或 lon 值,但这也不起作用。有人知道这里发生了什么吗?或者,如果我使用了错误的插值。

【问题讨论】:

    标签: python scipy interpolation


    【解决方案1】:

    来自interp1ddocs

    bounds_error : bool, optional 如果为真,则随时引发 ValueError 尝试对 x 范围之外的值进行插值(其中 外推是必要的)。如果为 False,则超出范围的值是 分配填充值。默认情况下,会引发错误。

    因此,您的一些插值数据超出了插值范围。您正在尝试推断,而不是插值。

    当你使用像

    这样的插值时

    xInterpolation = interp1d(xDegree, xPixel) xInterpolation(lon)

    来自lon 的所有值都必须属于区间[xDegree.min, xDegree.max]

    因此,您需要更正数据以进行插值或使用extrapolation

    【讨论】:

    • 不,它不在插值范围之上。我已经仔细检查过,并在问题中提到了这条信息。
    • @Omayr 那么,您能否为您的问题中的所有数组提供样本?
    猜你喜欢
    • 2018-03-23
    • 1970-01-01
    • 2020-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多