self_example/phm_rotate/PHMWarehouse/utils/LTTBUtils.py

39 lines
1021 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#-*- encoding:utf-8 -*-
'''
@Author : dingjiawen
@Date : 2023/5/22 20:33
@Usage :
@Desc : lttb算法的实现保留时序数据波动细节的算法
'''
import numpy as np
import pandas as pd
import lttb
def lttb_try(a):
length, = a.shape
print(length,":",length)
b = np.array([range(length),a]).T
print(b)
print(b.shape)
return lttb.downsample(b,n_out=int(length/10))
if __name__ == '__main__':
cms_data_path = r"E:\data\cmsDemo\华能三塘湖项目一期_D3-29_Shaft2_径向_25600_加速度g_14.41RPM_20180618003450.csv"
cms_data_df = pd.read_csv(cms_data_path, encoding='gbk', header=None)
cms_data_df = cms_data_df.values[0]
data_before = cms_data_df[:1000]
down_sample = lttb_try(data_before)
print(down_sample.shape)
import matplotlib.pyplot as plt
plt.subplot(2, 1, 1)
plt.plot(data_before)
plt.subplot(2, 1, 2)
plt.plot(down_sample[:, 1])
plt.show()
# assert small_data.shape == (20, 2)
# print(cms_send_data.shape)