使用scipy的SmoothSphereBivariateSpline进行插值

7
我想使用scipy.interpolate.SmoothSphereBivariateSpline在地图上插值温度(我不熟悉数据插值,所以这可能不是一个好选择,但我想试一试)。
我做了以下几步:
- 从tsv文件中加载数据,它看起来像这样: latitude longitude temperature city 30.22 120.14 39 2caves 30.26 120.13 39 3caves 30.23 120.13 39 Anlong 33.48 108.5 30 Anda 37.2 100.74 15 Anan ...
  • into pandas

    data = pandas.read_table('temp.tsv')
    
  • Get radians from lat, lon:

    theta = numpy.array(data.latitude) / 180 * numpy.pi # the lat, lon domain is safe here so
    phi = numpy.array(data.longitude) / 180 * numpy.pi  # I won't adjust for the output range
    temp = numpy.array(data.temperature)
    
  • Feed them into scipy:

    lut = SmoothSphereBivariateSpline(theta, phi, temps)
    

然后该函数会引发ValueError错误:

ValueError: 所需存储空间超过可用存储空间:nxest或nyest太小,或s太小。 加权最小二乘样条对应于当前的节点集。

我尝试使用不同的值调整 s 参数,从 1、2、3 到 7000、8000,但它仍然太小。我应该怎么做才能使插值工作?


我遇到了球面插值的同样问题,但始终无法使这个类起作用...完全相同的问题。 - Binxu Wang 王彬旭
2个回答

1

仅供记录: 根据文档, 有一个平滑参数s需要选择; 默认值为s=0, 但有时根据文档的建议,手动选择是至关重要的。


0

实际上,我尝试了一种可行的替代方法。使用同一库中的RectSphereBivariateSpline函数。它接受 u,v 或者 theta,phi网格 作为输入并在网格上进行插值。

看起来你的数据样本也是在网格上,这个方法应该也适用于你的情况!

请注意,在此函数中极地需要一些特殊处理。

https://scipy.github.io/devdocs/reference/generated/scipy.interpolate.RectSphereBivariateSpline.html

我尝试了几个例子,似乎问题在于SmoothSphereBivariateSpline的内存缩放。因此,如果我们在网格上有太多点,它将会内存溢出。这似乎是一种更灵活的方法,适用于不规则地落在球体上的点,而不是像我们的正常网格。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接