2D插值函数问题

时间:2018-02-26 19:05:25

标签: python scipy interpolation

我正在尝试编写插值函数,以从Ts和Seff值获取任何CO2值。我和Ts和Seff的网格不是正方形。 问题是对于某些Ts值(例如275),Seff仅从0.4变为0.8,而对于其他Ts值(例如320),Seff从0.5变为1.2。 但是当插值时,如果我要求CO2值(Ts = 275,S = 1.1),我得到CO2的值,即使我应该得到NaN(Ts = 275,Seff为1.1不存在) )。

我尝试使用下面的bounds_error和fill_value参数解决此问题,但这只能确保在“绝对”最大值和最小值S之外插值时得到Nan值。

import numpy as np
from scipy import interpolate

Seff =[0.88383316136305645,1.0298932275648676,1.1097533821426062,1.1234656716815736,0.80369957429646033,0.93326566449886517,1.0134725598796075,1.0452557986414284,0.71380176528610517,0.81469788653203512,0.89382224429581447,0.94761085313180471,0.40459228983422418,0.43388658896464499,0.46430015708333283,0.50080988488067069]

CO2 = [63.632000000000005,63.632000000000005,63.632000000000005,63.632000000000005,3171.6999999999998,3171.6999999999998,3171.6999999999998,3171.6999999999998,59829.0,59829.0,59829.0,59829.0,760870.0,760870.0,760870.0,760870.0]

Tslist = [275,290,305,320,275,290,305,320,275,290,305,320,275,290,305,320]


Tsnew = np.arange(280, 315, 0.001)
Seffnew = np.arange(0.5, 1.1, 0.001)
f=interpolate.interp2d(Tslist,Seff,CO2,bounds_error=False, fill_value='NaN')

print f(275,1.1)
>> array([ 70446.45005256])

但它似乎仍然在每个Ts的范围之外插值。有办法解决这个问题吗?

0 个答案:

没有答案