簡體   English   中英

scipy.interpolate.interp2d:我真的有太多的數據點嗎?

[英]scipy.interpolate.interp2d: do I really have too many data points?

我有一組位於 X、Y 網格上的高程測量值。 我正在嘗試通過高程創建一個切片(在一個角度下,因此在網格點上不完美)。 我想過使用 scipy 的 2D 插值方法,但我收到錯誤 OverflowError: Too many data points to interpolate。 我沒有龐大的數組,所以我想知道為什么會出錯。

我的數據:

>>> XX.shape, YY.shape, depth_array.shape
((787, 1858), (787, 1858), (787, 1858))

>>> XX
array([[  0,   0,   0, ...,   0,   0,   0],
       [  1,   1,   1, ...,   1,   1,   1],
       [  2,   2,   2, ...,   2,   2,   2],
       ...,
       [784, 784, 784, ..., 784, 784, 784],
       [785, 785, 785, ..., 785, 785, 785],
       [786, 786, 786, ..., 786, 786, 786]])

>>> YY
array([[   0,    1,    2, ..., 1855, 1856, 1857],
    [   0,    1,    2, ..., 1855, 1856, 1857],
    [   0,    1,    2, ..., 1855, 1856, 1857],
    ...,
    [   0,    1,    2, ..., 1855, 1856, 1857],
    [   0,    1,    2, ..., 1855, 1856, 1857],
    [   0,    1,    2, ..., 1855, 1856, 1857]])

>>> depth_array
array([[0., 0., 0., ..., 0., 0., 0.],
    [0., 0., 0., ..., 0., 0., 0.],
    [0., 0., 0., ..., 0., 0., 0.],
    ...,
    [0., 0., 0., ..., 0., 0., 0.],
    [0., 0., 0., ..., 0., 0., 0.],
    [0., 0., 0., ..., 0., 0., 0.]])
# The depth array seems empty, but that's not the case (but that are quite a few zero values)

>>> interpolate.interp2d(YY, XX, depth_array, kind='linear')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/yorian/.pyenv/versions/3.7.5/envs/euromax/lib/python3.7/site-packages/scipy/interpolate/interpolate.py", line 229, in __init__
    self.tck = fitpack.bisplrep(x, y, z, kx=kx, ky=ky, s=0.0)
File "/Users/yorian/.pyenv/versions/3.7.5/envs/euromax/lib/python3.7/site-packages/scipy/interpolate/_fitpack_impl.py", line 956, in bisplrep
    msg=msg)
File "/Users/yorian/.pyenv/versions/3.7.5/envs/euromax/lib/python3.7/site-packages/scipy/interpolate/_fitpack_impl.py", line 48, in _int_overflow
    raise OverflowError(msg)
OverflowError: Too many data points to interpolate

我現在正在使用 RectBivariateSpline,但這似乎適合樣條曲線,我想要一個 2D 線性插值。 (787, 1858) 點數真的太多了嗎? 如果是這樣,我該如何實施?

如果你有一個規則的網格,只提供 x 和 y 坐標的一維數組就足夠了。 這計算成本較低,但我不知道這是否是通用網格情況下出現錯誤消息的原因。


import numpy as np
from scipy import interpolate

nx = 787
ny = 1858
depth_array = np.random.random((ny, nx))
res = interpolate.interp2d(range(nx), range(ny), depth_array, kind='linear')

我嘗試重現您的錯誤並在使用通用網格x, y = np.meshgrid(np.arange(nx), np.arange(ny))時大致發現了這種行為:

  • nx*ny < 200000 :有效
  • nx*ny > 200000 :內存錯誤
  • nx*ny > 250000 :溢出錯誤

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM