[英]Python scipy.interpolate.interp1d not working with large float values
我正在嘗試使用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中的值高於插值范圍。
無論我嘗試使用什么值,它都會引發值錯誤,我什至嘗試提供與輸入列表中相同的經度或緯度值,但這也不起作用。 有人知道這里發生了什么嗎? 或者,如果我使用了錯誤的插值。
來自interp1d
docs :
bounds_error:bool,可選如果為True,則任何時候嘗試對x范圍以外的值進行插值(需要外推)時,都會引發ValueError。 如果為False,則為邊界值分配fill_value。 默認情況下,引發錯誤。
因此,您的某些插值數據超出插值范圍。 您正在嘗試外推,而不是內插。
當您使用插值
xInterpolation = interp1d(xDegree, xPixel) xInterpolation(lon)
lon
所有值都必須屬於間隔[xDegree.min, xDegree.max]
。
因此,您需要校正數據以進行插值或使用Extrapolation 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.