如何解决在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()
我得到的结果是这个吗?看起来正确吗?分别对每个分量进行插值还是先求出整个值和插值更好?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。