我有以下数据,可以使用interp2
函数在MATLAB中轻松对其进行插值。但是,在使用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')
答案 0 :(得分:2)
我最终改为使用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的任意范围。