Beispiel #1
0
    def preprocess(self):
        #        self.data = pd.DataFrame(columns=['rpm', 'amp_ratio', 'rms', 'std', 'mean', 'mode', 'range', 'label'])

        self.data_dict = {
            'rpm': [],
            'amp_ratio': [],
            'rms': [],
            'std': [],
            'mean': [],
            'mode': [],
            'range': [],
            'label': [],
        }
        for label in [0, 1]:
            self.__db.query_dict = {'label': {'$eq': label}}
            file_list = self.__db.query()
            for f in file_list:
                file_uri = os.path.join(f['a_uri'], f['filename'])
                print(file_uri)
                dp = preprocess.DataPreprocess(filename=file_uri)
                data_pre = dp.origin_data().data_split()
                for i, df in enumerate(data_pre):
                    df = dp.data_drop(df)
                    df = dp.data_drop(df, drop_type='tail', pct=0.2)
                    self.data_dict['rpm'].append(i)
                    signal0 = signalProcess.SignalProcess(df=df)

                    self.data_dict['amp_ratio'].append(signal0.f_amp_ratio())
                    self.data_dict['rms'].append(signal0.t_v_rms())
                    self.data_dict['std'].append(signal0.t_a_std())
                    self.data_dict['mean'].append(signal0.t_a_mean())
                    self.data_dict['mode'].append(signal0.t_a_mode())
                    self.data_dict['range'].append(signal0.t_a_range())
                    self.data_dict['label'].append(label)
        self.data = pd.DataFrame().from_dict(self.data_dict)
Beispiel #2
0
def abnormal_zero_anasys():
    figure_no = 0
    db = mongodb_op.MongodbOp()
    db._query_dict = {'label': {'$eq': 1}}
    file_dict = db.query()
    temp = []
    for f_dict in file_dict:
        figure_no += 1
        plt.figure(figure_no)
        file = os.path.join(f_dict.get('a_uri'), f_dict.get('filename'))
        print(file)
        dp = preprocess.DataPreprocess(filename=file)
        dp.origin_data(filter_zero=False)
        dp.df.loc[dp.df.all(axis=1), 'z'] = 1
        f, p = signal.welch(dp.df.z, 4000, scaling='spectrum')
        plt.plot(f, p)
    return f, p
Beispiel #3
0
def origin_distribute():
    db = mongodb_op.MongodbOp()
    db._query_dict = {'label': {'$eq': 0}}
    file_dict = db.query()
    temp = []
    for f_dict in file_dict:

        file = os.path.join(f_dict.get('a_uri'), f_dict.get('filename'))
        print(file)
        dp = preprocess.DataPreprocess(filename=file)
        dp.origin_data()
        dp.df = dp.df.drop(['x', 'y'], axis=1)
        df_rpm_1, _, _ = dp.data_split()
        df_rpm_1 = dp.data_drop(df_rpm_1, )
        df_rpm_1 = dp.data_drop(df_rpm_1, drop_type='tail')
        df_rpm_1.columns = [file]
        temp.append(df_rpm_1)
    return pd.concat(temp, sort=False, axis=1)
Beispiel #4
0
def helper(file_dict, out_dir, label=1):
    gc.collect()
    file_uri = os.path.join(file_dict['a_uri'], file_dict['filename'])
    print(file_uri)
    dp = preprocess.DataPreprocess(filename=file_uri)
    data_pre = dp.origin_data().data_split()
    temp_lst = []
    for i, df in enumerate(data_pre):
        df = dp.data_drop(df)
        df = dp.data_drop(df, drop_type='tail', pct=0.2)
        dp.df = df
        df_sub = dp.data_split(n=20)
        for df_temp in df_sub:
            #            df_temp = df.sample(frac=0.4)
            signal0 = signalProcess.SignalProcess(df=df_temp)
            print('{} signal process'.format(file_uri))
            data_dict = dict()
            data_dict['rpm'] = [i]
            data_dict['amp_ratio'] = [signal0.f_amp_ratio()]
            data_dict['rms'] = [signal0.t_v_rms()]
            data_dict['std'] = [signal0.t_a_std()]
            data_dict['mean'] = [signal0.t_a_mean()]
            data_dict['mode'] = [signal0.t_a_mode()]
            data_dict['range'] = [signal0.t_a_range()]
            data_dict['label'] = label
            temp_lst.append(pd.DataFrame().from_dict(data_dict))
            del df_temp


#        all_df.concat(temp, sort=False, ignore_index=True, copy=False)
#        all_df.to_pickle('{}.pkl'.format(os.path.basename(file_uri)))
#        del temp
        del df_sub
        del df
    del data_pre
    pd.concat(temp_lst, ignore_index=True).to_pickle(
        os.path.join(out_dir, '{}.pkl'.format(file_dict['filename'])))
    del temp_lst
    print('--process finished')
    return 1
Beispiel #5
0
def f_envelope_spectrum():
    db = mongodb_op.MongodbOp()
    fig_num = 0
    for label in [0, 1]:
        db.query_dict = {'label': {'$eq': label}}
        file_dict = list(db.query())[:2]
        for f_dict in file_dict:
            file_uri = os.path.join(f_dict['a_uri'], f_dict['filename'])
            print(file_uri)
            dp = preprocess.DataPreprocess(filename=file_uri)
            data_pre = dp.origin_data().data_split()
            for i, df in enumerate(data_pre):
                df = dp.data_drop(df)
                df = dp.data_drop(df, drop_type='tail', pct=0.2)
                dp.df = df
                df_sub = dp.data_split(n=20)
                for df_temp in df_sub:
                    fig_num += 1
                    plt.figure(fig_num)
                    signal0 = signalProcess.SignalProcess(df=df_temp)
                    f, p = signal0.f_envelope_spectrum()
                    plt.plot(f, p)
                    plt.savefig('fig/{}_{}.jpg'.format(label, fig_num))
                del df_sub
Beispiel #6
0
 def init_param(self, args):
     self.sig = signalProcess.SignalProcess(df=pd.DataFrame())
     self.dp = preprocess.DataPreprocess()
     self.mdb = mongodb_op.MongodbOp()
     self.segment = 'train'