python运行时错误中的Interp2D函数



i具有以下数据,在MATLAB中,使用interp2函数可以轻松地插值。但是,在使用Interp2d的Python中,以下错误遇到:

RuntimeWarning: No more knots can be added because the number of B-spline
coefficients already exceeds the number of data points m.
Probable causes: either s or m too small. (fp>s)
    kx,ky=3,3 nx,ny=17,11 m=90 fp=0.000013 s=0.000000
  warnings.warn(RuntimeWarning(_iermess2[ierm][0] + _mess))

我试图使用griddata,但也没有运气。对这些问题的任何解决方案都将不胜感激。

代码:

OF_S = np.array([[5, 5, 5, 5, 5, 5, 5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5],
                 [6, 6, 6,     6,     6,     6,     6,     6,     6,     6,     6,     6,     6,     6,     6, 6,     6,     6,     6,     6,     6,     6,     6,     6,     6,     6,     6,     6,     6,     6],
                 [7, 7, 7,     7,     7,     7,     7,     7,     7,     7,     7,     7,     7,     7,     7,     7,     7,     7,     7,     7,     7,     7,     7,     7,     7,     7,     7,     7,     7,     7]])
FT_FTAVAIL_S = np.array([[0.198,     0.205,     0.214,     0.227,     0.237,     0.249,     0.26,     0.271,     0.285,     0.304,     0.332,     0.371,     0.405,     0.436,     0.464,     0.507,     0.548,     0.598,     0.649,     0.694,     0.746,     0.787,     0.822,     0.851,     0.879,     0.914,     0.951,     0.985,     0.999,     1],
                         [0.198,     0.205,     0.214,     0.227,     0.237,     0.249,     0.26,     0.271,     0.285,     0.304,     0.332,     0.371,     0.405,     0.436,     0.464, 0.507,     0.548,     0.598,     0.649,     0.694,     0.746,     0.787,     0.822,     0.851,     0.879,     0.914,     0.951,     0.985,     0.999,     1],
                         [0.198,     0.205,     0.214,     0.227,     0.237,     0.249,     0.26,     0.271,     0.285,     0.304,     0.332,     0.371,     0.405,     0.436,     0.464,     0.507,     0.548,     0.598,     0.649,     0.694,     0.746,     0.787,     0.822,     0.851,     0.879,     0.914,     0.951,     0.985,     0.999,     1.000]])
ISP_ISPAVAIL_S = np.array([[0.9845,     0.9867,     0.9867,     0.9867,     0.9867,     0.9889,     0.9889,     0.9889,     0.9889,     0.9911,     0.9911,     0.9933,     0.9933,     0.9956,     0.9956,     0.9956,     0.9978,     0.9978,     0.9978,     0.9978,     0.9978,     0.9978,     0.9978,     0.9978,     0.9978,     0.9978,     1,     1,     1,     1],
                           [0.9756,     0.9756,     0.9761,     0.9778,     0.9778,     0.9778,     0.9787,     0.9798,     0.98,     0.9804,     0.9827,     0.9844,     0.9855,     0.9867, 0.9889,     0.9892,     0.9911,     0.9927,     0.9933,     0.9942,     0.9956,     0.9956,     0.9978,     0.9978,     0.9978,     0.9978,     0.9988,     1,     1,     1],
                           [0.9662,     0.9662,     0.9662,     0.9679,     0.9685,     0.9697,     0.9707,     0.9709,     0.972,     0.9738,     0.9755,     0.9797,     0.9805,     0.982,     0.9842,     0.9863,     0.9873,     0.9887,     0.991,     0.992,     0.9932,     0.9943,     0.9955,     0.9955,     0.9966,     0.9977,     0.9978,     0.9986,     0.9999,     1]])
ISP_ISPAVAIL_interpGrid = interp2d(FT_FTAVAIL_S, OF_S, ISP_ISPAVAIL_S, kind='cubic')

我最终使用griddata。这里的关键是要在任何插值之前扁平的数据。因此,我用.ravel((做到了。

ISP_ISPAVAIL= griddata(
        (FT_FTAVAIL_S.ravel(), OF_S.ravel()), ISP_ISPAVAIL_S.ravel(), (XX, YY), method="nearest")

其中xx和yy分别是ft_ftavail_s和of_s的任意界限。

最新更新