在python中使用线性插值对数据进行下采样

问题描述

您好,我正在尝试使用线性插值对某些数据进行下采样。我尝试使用两种方法来执行此操作。但是我不确定我的结果是否正确。可以在这里找到两个Excel文件(https://www.dropbox.com/sh/ahmd04j78bmz6ti/AABO8h8KUM9R4zxTnyrPfH1la?dl=0),我正在使用的代码是这样的:

### Just to load the data-> Not relevant####

test = pd.read_excel ('test.xlsx')
test2 = pd.read_excel ('test2.xlsx')

testa=np.array(test)
testb=testa.ravel()
testa2=np.array(test2)

######### The two methods###########3


### First method###

df1 = pd.DataFrame({'DateTime': testb,'Br': testa2[:,0],'Bt': testa2[:,1],'Bn': testa2[:,2]}) 
B = df1.set_index('DateTime').resample('1S').mean().interpolate(method='linear')
    #B1 = B.to_numpy()
    
    
    # Find Btotal as B = sqrt(Br^2 + B_n^2 + B_T^2)
Btotal=((np.sqrt((B.Br)**2 + B.Bt**2 + B.Bn**2)))



##Second method###

Btot = []
B_component=test2.values
for i in range(0,len(test),1):
    Btot.append((np.sqrt((B_component[i,0])**2 + B_component[i,1]**2 + B_component[i,2]**2)))
# Create dataframe
#plt.plot(Btot)
df = pd.DataFrame({'DateTime': testb,'Bt': Btot})   

Btotal1 = df.set_index('DateTime')['Bt'].resample('1S').mean().interpolate()


###PLot figures####

plt.plot(test[0:100],np.sqrt((testa2[0:100,0])**2+(testa2[0:100,1])**2+(testa2[0:100,2]**2)),label='original')
plt.plot(Btotal[0:40],label='first method')
plt.plot(Btotal1[0:40],label='second method')
plt.legend(loc=0)
plt.show()

我得到的结果是这个吗?看起来正确吗?分别对每个分量进行插值还是先求出整个值和插值更好?

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)