繁体   English   中英

我认为 scipy.interpolate 可能坏了还是我用错了?

[英]I think scipy.interpolate might be broken or am I using it wrong?

我正在处理一些缺少值的地理数据,并且我正在尝试沿它们的路径估算缺失值。 我已经使用其他值进行插值,包括我在这里包含的一组纬度 (working_x) 和经度 (working_y)。 但是,由broken_x 和broken_y 组成的以下数据会导致错误。

from scipy import interpolate

working_x = [50.2577, 50.0482, 50.0486, 51.7697, 54.5125, 56.6626, 59.1144, 61.2571, 65.0806, 66.541, 68.8, 70.672, 72.5613, 74.7929, 75.7798, 78.119, 79.4935, 82.3863, 85.0249, 88.0613, 91.878, 94.1954, 96.7093, 98.3678, 100.5983, 102.5626]
working_y = [27.1174, 26.9498, 26.9501, 27.0585, 26.1905, 26.3719, 24.5836, 23.4857, 21.4881, 20.4295, 18.0235, 16.0258, 13.9794, 11.0714, 9.0558, 6.7257, 6.0434, 5.6889, 5.7001, 5.6913, 5.7709, 6.167, 5.7973, 4.9382, 3.1171, 1.7426]
broke_x = [50.3603, 50.2219, 50.2246, 50.182, 50.182, 50.182, 52.0052, 54.3371, 56.7533, 58.8949, 65.2883, 67.1264, 68.3829, 70.0129, 72.003, 73.8859, 75.1131, 75.6843, 77.3321, 78.6119, 81.6834, 83.8053, 87.7575, 89.1056, 92.7804, 95.1509, 100.2694, 101.2058]
broke_y = [27.0834, 26.678, 26.6786, 26.6716, 26.6716, 26.6716, 27.0163, 26.2115, 26.2435, 25.1276, 24.7504, 23.3715, 21.7267, 19.6113, 17.2461, 13.7936, 10.9089, 9.8805, 7.5112, 6.6072, 5.8491, 6.1449, 6.5355, 6.5364, 6.316, 6.1539, 3.4317, 2.6727]
tck1, u1 = interpolate.splprep([working_x, working_y], s=1)
tck, u = interpolate.splprep([broke_x, broke_y], s=1)

每当我运行上面的代码时,我都会收到此错误。

ValueError                                Traceback (most recent call last)
<ipython-input-232-cad98765c4aa> in <module>
      6 broke_y = [27.0834, 26.678, 26.6786, 26.6716, 26.6716, 26.6716, 27.0163, 26.2115, 26.2435, 25.1276, 24.7504, 23.3715, 21.7267, 19.6113, 17.2461, 13.7936, 10.9089, 9.8805, 7.5112, 6.6072, 5.8491, 6.1449, 6.5355, 6.5364, 6.316, 6.1539, 3.4317, 2.6727][:10]
      7 tck1, u1 = interpolate.splprep([working_x, working_y], s=1)
----> 8 tck, u = interpolate.splprep([broke_x, broke_y], s=1)

C:\ProgramData\Anaconda3\envs\geo\lib\site-packages\scipy\interpolate\fitpack.py in splprep(x, w, u, ub, ue, k, task, s, t, full_output, nest, per, quiet)
    155     """
    156     res = _impl.splprep(x, w, u, ub, ue, k, task, s, t, full_output, nest, per,
--> 157                         quiet)
    158     return res
    159 

C:\ProgramData\Anaconda3\envs\geo\lib\site-packages\scipy\interpolate\_fitpack_impl.py in splprep(x, w, u, ub, ue, k, task, s, t, full_output, nest, per, quiet)
    278     iwrk = _parcur_cache['iwrk']
    279     t, c, o = _fitpack._parcur(ravel(transpose(x)), w, u, ub, ue, k,
--> 280                                task, ipar, s, t, nest, wrk, iwrk, per)
    281     _parcur_cache['u'] = o['u']
    282     _parcur_cache['ub'] = o['ub']

ValueError: Invalid inputs. ```

您的broke列表包含连续的相同点,显然interpolate.splprep()无法处理。 这是一个突出问题的最小示例:

from scipy import interpolate

working_x = [1, 2, 3, 4]
working_y = [1, 2, 3, 4]

tck1, u1 = interpolate.splprep([working_x, working_y], s=1)

有效,而

broke_x = [1, 2, 3, 3] 
broke_y = [1, 2, 3, 3]

tck, u = interpolate.splprep([broke_x, broke_y], s=1)

抛出错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM