赞
踩
西储大学轴承各类型故障数据准备
导入python处理包看下
- import scipy.io # To use the '.mat' files
- import seaborn as sns
- import numpy as np
- import pandas as pd
- import os
- import matplotlib.pyplot as plt
看下文件下文件
- for root, dirs, files in os.walk("0hp_load_48_KHz", topdown=False):
- for file_name in files:
- path = os.path.join(root, file_name)
- print(path)
看下数据mat内部概况
- path = r'0hp_load_48_KHz\7_OR3.mat'
- mat = scipy.io.loadmat(path)
- mat.items()
list(mat.keys())
获取风扇端数据
- key_name = list(mat.keys())[3]
- DE_data = mat.get(key_name)
- fault = np.full((len(DE_data), 1), file_name[:-4])
- df_temp = pd.DataFrame({'DE_data':np.ravel(DE_data) , 'fault':np.ravel(fault)})
- df_temp
- plt.figure(figsize=(15,5))
- plt.plot(df_temp.iloc[:,0])
- plt.show()
画下这个数据的波形
处理数据集
- df=pd.DataFrame(columns=['DE_data','fault'])
-
- for root, dirs, files in os.walk("0hp_load_48_KHz", topdown=False):
- for file_name in files:
- path = os.path.join(root, file_name)
- print(path)
-
- mat = scipy.io.loadmat(path)
-
- key_name = list(mat.keys())[3]
- DE_data = mat.get(key_name)
- fault = np.full((len(DE_data), 1), file_name[:-4])
-
- df_temp = pd.DataFrame({'DE_data':np.ravel(DE_data) , 'fault':np.ravel(fault)})
-
- df = pd.concat([df,df_temp],axis=0)
- print(df['fault'].unique())
-
- df.to_csv('0hp_all_faults.csv',index=False)
看下数据集情况
df = pd.read_csv('0hp_all_faults.csv')
- faults = df['fault'].unique()
- for f in faults:
- plt.figure(figsize=(10,3))
- plt.plot(df[df['fault']==f].iloc[:,0])
- plt.title(f)
- plt.show()
等等。。。。
拼接看下
- plt.figure(figsize=(15,5))
- sns.scatterplot(data=df.iloc[::100,:],y='DE_data',x=np.arange(0,len(df),100),hue='fault')
- plt.show()
生成数据集文件
- load=3
-
- df=pd.DataFrame(columns=['DE_data','fault'])
-
- for root, dirs, files in os.walk("{}hp_load_48_KHz".format(load), topdown=False):
- for file_name in files:
- path = os.path.join(root, file_name)
- print(path)
-
- mat = scipy.io.loadmat(path)
-
- for k in list(mat.keys()):
- if k[5:]== 'DE_time':
- key_name=k
- DE_data = mat.get(key_name)
- fault = np.full((len(DE_data), 1), file_name[:-4])
-
- df_temp = pd.DataFrame({'DE_data':np.ravel(DE_data) , 'fault':np.ravel(fault)})
-
- df = pd.concat([df,df_temp],axis=0)
- print(df['fault'].unique())
-
- df.to_csv('{}hp_all_faults.csv'.format(load),index=False)
欢迎加微信公众号:轴承故障诊断和寿命预测
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。