Scipy LSQSphereBivariateSpline:悬挂,以及如何选择结?

2024-07-05 10:46:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一些python代码,将不规则数据插值到180°lat x 360°lon球面网格上。当我调用以下命令时,代码当前处于挂起状态:

def geo_interp(lats,lons,data,grid_size_deg):

        deg2rad = pi/180.
        new_lats = np.linspace(grid_size_deg, 180, 180) * deg2rad
        new_lons = np.linspace(grid_size_deg, 360, 360) * deg2rad

        knotst, knotsp = new_lats.copy(), new_lons.copy()
        knotst[0] += .0001
        knotst[-1] -= .0001
        knotsp[0] += .0001
        knotsp[-1] -= .0001

        lut = LSQSphereBivariateSpline(lats.ravel(),lons.ravel(),data.T.ravel(),knotst,knotsp)

        data_interp = lut(new_lats, new_lons)
        return data_interp

当我调用上述子例程时,用作参数的数组都符合文档中列出的LSQSphereBivariateSpline的要求。当我运行它时,它所花费的时间比我认为处理180x360数据集所需的时间要长得多。在

当我使用python-mtrace--trace运行脚本时,在很长一段时间内什么都不发生之前的最后一行输出是 fitpack2.py(1025): w=w, eps=eps)

据我所知,fitpack2.py的第1025行在注释中,这更令人困惑。在

所以我的问题是: 1有没有办法分辨它是挂着的还是很慢的? 2如果挂着,我该怎么修理?在

我唯一能想到的是,我不知道我在做什么,因为我选择了结。有没有好的方法来选择这些?我只是使用稍后将要插值的网格,因为doc中的示例似乎是一个任意网格。在

更新:大约3个小时后它终于完成了,但是“插值数据”看起来像随机噪声。另外,如果这是相关的,据我所知LSQSphereBivariateSpline是我唯一可以使用的函数,因为我的lat和lon不是严格递增的。在

另外,我还应该添加,当它完成时,它输出以下警告:Warning (from warnings module): File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy/interpolate/fitpack2.py", line 1029 warnings.warn(message) UserWarning: WARNING. The coefficients of the spline returned have been computed as the minimal norm least-squares solution of a (numerically) rank deficient system (deficiency=16336, rank=48650). Especially if the rank deficiency, which is computed by 6+(nt-8)*(np-7)+ier, is large, the results may be inaccurate. They could also seriously depend on the value of eps.


解决方法:我的结太多了,导致了冰天雪地的速度和无用的结果。在


Tags: the数据网格newdatasizegrid插值