在python中

时间:2016-03-14 15:11:12

标签: python interpolation

I have the following .txt file:

elevation   [1] inpol1       [2] inpol2       [3] RL(L1)       [4] RL(L2)       [5] LR(L1)       [6] LR(L2)
90.0,   -6.67107685717,   -2.44901761488,   -23.57314833,   -16.97583667,   -21.77855833,   -19.14620333,   
80.0,   -6.8610001598,   -2.55403460547,   -23.28653167,   -17.77932667,   -21.98888667,   -18.62304333,   
70.0,   -7.26186588862,   -2.9273149233,   -23.36461833,   -18.56328833,   -22.90425333,   -19.83013333,   
60.0,   -8.12320485689,   -3.92112857734,   -26.12222167,   -18.67996333,   -22.35199667,   -21.07369833,   
50.0,   -8.79551120253,   -4.78951507462,   -25.77091833,   -20.15670667,   -22.80505,   -19.24572,   
40.0,   -9.7150274851,   -5.74026771244,   -26.13789833,   -19.492935,   -24.116195,   -18.91178833,   
30.0,   -12.4733143154,   -7.38382695233,   -29.59175167,   -20.10266833,   -26.68595167,   -16.59469,   
20.0,   -15.3636359113,   -8.17039424613,   -28.16000167,   -18.59742333,   -29.06789167,   -16.16085667, 
10.0,   -18.4342503347,   -8.1905188993,   -24.938385,   -18.42761667,   -25.16124333,   -16.52676833,    
0.0,   -18.1632600571,   -9.01468419945,   -26.55651833,   -17.22991,   -24.81285167,   -14.60796,   
-10.0,   -16.7133867094,   -11.2860511308,   -23.03011,   -14.87516333,   -25.25885667,   -12.8514,   
-20.0,   -16.9661747422,   -14.9817503484,   -21.28522167,   -13.41128833,   -22.79150667,   -12.05261,   
-30.0,   -19.0849332428,   -25.0207809175,   -22.19593333,   -11.657085,       -21.78081833,   -11.15619333,   
-40.0,   -23.0413759193,   -27.6812084151,   -21.06287,   -10.79255333,   -21.43039167,   -11.43889667,   
-50.0,   -27.2608901323,   -26.008410352,   -20.72646333,   -10.53535783,   -19.86449333,   -11.257135,   
-60.0,   -32.3277829825,   -26.3760335651,   -19.491665,   -10.0824975,   -18.044145,   -9.58142683,   
-70.0,   -31.9688083301,   -24.6389964298,   -17.26466667,   -8.98763067,   -17.47626,   -8.15476567,   
-80.0,   -31.8190661767,   -22.2776308495,   -16.27771,   -7.96193283,   -16.95944667,   -7.04178467,   
-90.0,   -30.1752513951,   -21.8107054104,   -15.40699222,   -7.50867589,   -15.90784333,   -6.01267233,

我想创建一段代码插入值[1] inpol1,[2] inpol2,[3] RL(L1),[4] RL(L2),[5] LR(L1),[ 6] LR(L2)。我想我必须使用scipy.interpolate中的interp1d函数,但我不知道如何在我的txt文件上执行此操作。

编辑:抱歉,我应该说,对于任何给定的高程,我需要插值。

有谁知道如何执行此任务?注意:值是分贝值,即它们是对数的。

到目前为止我已经

ncal=open('H:/Uni Work/stage 3/Dissertation/Data/newcalibrations.txt')
ncal=ncal.readlines()[1:]
for x in ncal:
    x=x.split(',')
    elevations_for_calibration = x[0]
    calibration_values=x[1:]
    calibration_function = interpolate.interp1d(elevations_for_calibration,calibration_values)

但我知道这不起作用。

感谢。

1 个答案:

答案 0 :(得分:0)

我会做出类似的事情:

import numpy as np

ncal = np.genfromtxt('H:/Uni Work/stage 3/Dissertation/Data/newcalibrations.txt', dtype = float, delimiter = ',' , names=True, skip_header=0 )
ncal = ncal.readlines()

interpolation = np.interp(...)

您可以使用np.interp来实现这一目标。我在我的手机上,所以我无法启动它,但尝试专注于np.interp numpy模块;)