微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决在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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?