工业设备的状态监测和预测性维护(Python)

360影视 2025-01-24 06:21 3

摘要:# Common importsimport pandas as pdimport numpy as npfrom sklearn import preprocessingimport seaborn as snssns.set(color_codes=Tru

# Common importsimport pandas as pdimport numpy as npfrom sklearn import preprocessingimport seaborn as snssns.set(color_codes=True)import matplotlib.pyplot as plt%matplotlib inlineimport osfrom google.colab import drivedrive.mount('/content/drive')data_dir = '/content/drive/MyDrive/Machine life detection/2nd_test'merged_data = pd.DataFrame# Looping over all files from 12th Feb to 19th Febfor filename in os.listdir(data_dir):dataset=pd.read_csv(os.path.join(data_dir, filename), sep='\t')dataset_mean_abs = np.array(dataset.abs.mean)dataset_mean_abs = pd.DataFrame(dataset_mean_abs.reshape(1,4))dataset_mean_abs.index = [filename]merged_data = pd.concat([merged_data, dataset_mean_abs], ignore_index=False)# Renaming columnsmerged_data.columns = ['Bearing 1','Bearing 2','Bearing 3','Bearing 4']# Identifying index as dateTime formatmerged_data.index = pd.to_datetime(merged_data.index, format='%Y.%m.%d.%H.%M.%S')merged_data = merged_data.sort_indexmerged_data.to_csv('merged_dataset_BearingTest_2.csv')# Check - Begining of Datamerged_data.head# Check - End of Datamerged_data.tail#Check Total Pointsprint(f'Total Data Points {merged_data.shape[0] + 1}')Total Data Points 985# Visualising Dataax = merged_data.plot(figsize = (12,6), title="Vibration Data" , legend = True)ax.set(xlabel="Year-Month-Date", ylabel="Vibration/Acceleration(g)")plt.axvline(x='2004-02-19 06:12:39', linewidth=4, color='b', label ="Breakdown of Bearing 1")plt.text('2004-02-19 06:12:39',0.3,'Breakdown of Bearing 1',rotation=90, fontsize=14, color='b')

Zooming in Data for Bearing 1

fig = plt.figure# Divide the figure into a 1x2 grid, and give me the first sectionax1 = fig.add_subplot(121)# Divide the figure into a 1x2 grid, and give me the second sectionax2 = fig.add_subplot(122)healthy =merged_data['2004-02-12 11:02:39':'2004-02-12 23:52:39']healthy['Bearing 1'].plot(figsize = (12,6), title="Healthy State" , legend = True, ax=ax1)ax1.set(xlabel="Month-Date Time", ylabel="Vibration/Acceleration(g)")faulty =merged_data['2004-02-18 11:02:39':'2004-02-18 23:52:39']ax2 = faulty['Bearing 1'].plot(figsize = (12,6), title="Faulty State" , legend = True, ax= ax2)ax2.set(xlabel="Month-Date Time", ylabel="Vibration/Acceleration(g)")

Anamoly Detection using Prophet Package

pip install prophetfrom prophet import Prophethealthy_bearing1 = merged_data['2004-02-12 10:32:39':'2004-02-15 23:42:39']['Bearing 1']# Creating training dataframeprophet_healthy_train = pd.DataFrameprophet_healthy_train['ds'] = healthy_bearing1.indexprophet_healthy_train['y'] = healthy_bearing1.valuesprophet_healthy_train.headm = Prophet(interval_width = 1)# Using the training data from "healthy part"m.fit(prophet_healthy_train)forecast = m.predict(prophet_healthy_train)forecast['fact'] = prophet_healthy_train['y'].reset_index(drop = True)print('Displaying Prophet plot')fig1 = m.plot(forecast)fig1 = healthy_bearing1.plot(figsize = (12,6), title="Fit of Training Data")fig1.set(xlabel="Month (MM)-Date(DD) Time", ylabel="Vibration/Acceleration(g)")# Reduce data points (assuming prophet_faultydata is your full data)prophet_faultydata_subset = prophet_faultydata.resample('H').mean # Resample to hourly data# Prepare data for Prophet modelprophet_faulty_test = pd.DataFrameprophet_faulty_test['ds'] = prophet_faultydata_subset.indexprophet_faulty_test['y'] = prophet_faultydata_subset.values# Forecast and plot with reduced figure sizeforecast = m.predict(prophet_faulty_test)forecast['fact'] = prophet_faultydata_subset.reset_index(drop=True)print('Displaying Prophet plot')fig1 = m.plot(forecast, figsize=(4, 3)) # Reduce figure size# Plot actual faulty data on a separate figure (optional)fig2 = prophet_faultydata_subset.plot(figsize=(8, 4), title="Actual Faulty Data")fig2.set(xlabel="Month (MM)-Date(DD) Time", ylabel="Vibration/Acceleration(g)")fig2.text(12464.0, 0.06, 'Predicted',fontsize=10, color='r')fig2.text(12464.0,0.075,'Faulty Data', fontsize=10, color='r')fig2.text(12462.0,0.063,'Healthy', fontsize=10, color='r')

知乎学术咨询:

https://www.zhihu.com/consult/people/792359672131756032?isMe=1

担任《Mechanical System and Signal Processing》《中国电机工程学报》等期刊审稿专家,擅长领域:信号滤波/降噪,机器学习/深度学习,时间序列预分析/预测,设备故障诊断/缺陷检测/异常检测。

分割线分割线分割线分割线分割线分割线分割线分割线分割线分割线基于迭代小波阈值方法的非平稳信号降噪-以心电信号为例(Python)完整代码可通过知乎付费咨询获得:https://www.zhihu.com/consult/people/79235967213175603

基于脉冲小波的旋转机械故障诊断(MATLAB R2018a)

基于优化Morlet小波的一维信号瞬态特征提取方法(MATLAB)

来源:小羊看科技

相关推荐