def opeanFile(fileName):
    fileName = fileName

    segFile = SegFile()

    reply = segFile.loadFile(fileName)
    if (reply != 0):
        print('error!')
    else:
        # print(len(segFile.dataList[1].data))
        cwtmatr = []
        for i in range(segFile.tapeNum):
            cwtmatr.append(
                Algorithm_CWT.MyWavelets(segFile.dataList[i].data, 128))
        return cwtmatr
def opeanFile(fileName):
    fileName = fileName

    segFile = SegFile()

    reply = segFile.loadFile(fileName)
    if (reply != 0):
        print('error!')
    else:
        # cwtmatr,freqs = Algorithm.MyPywtCWT( self.segFile.dataList[ self.segFile.TapeNumCurrent ].data )
        # cwtmatr = Algorithm_CWT.MyScipyCwt(self.segFile.dataList[ self.segFile.TapeNumCurrent ].data, 128)
        print('ok')
        print(len(segFile.dataList[1].data))
        print('ok')
        cwtmatr = Algorithm_CWT.MyWavelets(segFile.dataList[1].data, 128)

        return cwtmatr
class Controller(QtWidgets.QMainWindow):
    def __init__(self):
        super(Controller, self).__init__()  # 先调用父类的构造函数
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.initUi()  # 界面初始设置
        self.connect()  # 绑定信号槽
        self.addPainteWidget()  #添加绘图控件

        self.stateDiagram = 0  #程序状态控制 —— 用于切换不同界面控制:0.初始状态、1.已加载文件、2.已完成FFT、3.已完成CWT、4、已完成LSTM

        # 初始化LSTMs模型
        self.model_path = "tf_model_lstm/model_1500.ckpt"
        self.prediction = MyPrediction(self.model_path)

    def initUi(self):  # 界面初始设置
        self.setWindowState(QtCore.Qt.WindowMaximized)
        self.toolButton_Home_clicked()

    '''  ↓ 添加绘图控件 ↓    '''

    def addPainteWidget(self):

        self.paintFFT = MyFigureCanvasFFT(1)
        self.ui.gridLayout_Canvas_FFT.addWidget(self.paintFFT)

        self.paintCWT = MyFigureCanvasCWT(2)
        self.ui.gridLayout_Canvas_CWT_Paint.addWidget(self.paintCWT)

        self.paintLSTM = MyFigureCanvasLSTM(3)
        self.ui.gridLayout_Canvas_LSTM.addWidget(self.paintLSTM)

    def connect(self):  # 绑定信号槽
        # 绑定导航栏按钮
        self.ui.toolButton_Home.clicked.connect(self.toolButton_Home_clicked)
        self.ui.toolButton_FFT.clicked.connect(self.toolButton_FFT_clicked)
        self.ui.toolButton_CWT.clicked.connect(self.toolButton_CWT_clicked)
        self.ui.toolButton_LSTM.clicked.connect(self.toolButton_LSTM_clicked)
        self.ui.toolButton_normalization.clicked.connect(
            self.toolButton_normalization_clicked)
        self.ui.toolButton_Set.clicked.connect(self.toolButton_Set_clicked)

        # 绑定meanBar
        self.ui.opeanFile.triggered.connect(self.menu_opeanFile)

        #绑定 左、右按钮
        self.ui.toolButton_left.clicked.connect(self.toolButton_left)
        self.ui.toolButton_right.clicked.connect(self.toolButton_right)

    '''  -------------------- ↓ 菜单栏事件 ↓ --------------------  '''

    def menu_opeanFile(self):
        fileName, filetype = QtWidgets.QFileDialog.getOpenFileName(
            self, "选取文件", "C:/", "seg Files (*.seg)")  # 设置文件扩展名过滤,注意用双分号间隔

        if fileName == '':
            QtWidgets.QMessageBox.warning(self, "Warning",
                                          Message().dict['Error(1002)'],
                                          QtWidgets.QMessageBox.Yes)
        else:
            self.segFile = SegFile()

            reply = self.segFile.loadFile(fileName)
            if (reply != 0):
                QtWidgets.QMessageBox.warning(self, "Warning",
                                              Message().dict[reply],
                                              QtWidgets.QMessageBox.Yes)
            else:
                self.stateDiagram = 1  # 1-已加载文件

                self.paintFFT.figureClear()
                for i in range(0, self.segFile.tapeNum):
                    self.paintFFT.setAx(i, self.segFile.tapeNum, '2d')
                    self.paintFFT.paint(i, self.segFile.dataList[i].data)
                    # print(len(self.segFile.dataList[i].data))

                # cwtmatr,freqs = Algorithm.MyPywtCWT( self.segFile.dataList[ self.segFile.TapeNumCurrent ].data )
                # cwtmatr = Algorithm_CWT.MyScipyCwt(self.segFile.dataList[ self.segFile.TapeNumCurrent ].data, 128)
                cwtmatr = Algorithm_CWT.MyWavelets(
                    self.segFile.dataList[self.segFile.TapeNumCurrent].data,
                    128)

                self.paintCWT.figureClear()

                # self.paintCWT.setAx(0,2) # 第 1 行, 共 2 行
                # self.paintCWT.MyMatshow(0,cwtmatr)

                self.paintCWT.setAx(0, 1, '3d')  # 第 2 行, 共 2 行
                self.paintCWT.MyPlot_surface(0, cwtmatr, 1,
                                             2)  # 第几行、数据、绘图采样步长:频率、绘图采样步长:时间
                # self.paintCWT.My3DView_init(0,45,180) #设置视角

                # 绘制LSTM曲线
                train_data, train_labels = inputData(4, 5)  # number: 1~5

                self.out = self.prediction.Prediction(train_data[7],
                                                      train_labels[7])
                self.paintLSTM.setAx(0, 5, '2d')
                self.paintLSTM.paint(0, self.out)

                self.out = self.prediction.Prediction(train_data[0],
                                                      train_labels[0])
                self.paintLSTM.setAx(1, 5, '2d')
                self.paintLSTM.paint(1, self.out)

                self.out = self.prediction.Prediction(train_data[1],
                                                      train_labels[1])
                self.paintLSTM.setAx(2, 5, '2d')
                self.paintLSTM.paint(2, self.out)

                self.out = self.prediction.Prediction(train_data[2],
                                                      train_labels[2])
                self.paintLSTM.setAx(3, 5, '2d')
                self.paintLSTM.paint(3, self.out)

                self.out = self.prediction.Prediction(train_data[3],
                                                      train_labels[3])
                self.paintLSTM.setAx(4, 5, '2d')
                self.paintLSTM.paint(4, self.out)

    # 导航栏更新

    def toolButton_NavigationBar_Update(self, i):
        # 设置导航栏颜色
        p = QtGui.QPalette()  # 调色板
        p.setColor(QtGui.QPalette.Button, QtGui.QColor(44, 44, 44))  # 灰黑色

        self.ui.toolButton_Home.setPalette(p)
        self.ui.toolButton_FFT.setPalette(p)
        self.ui.toolButton_CWT.setPalette(p)
        self.ui.toolButton_normalization.setPalette(p)
        self.ui.toolButton_LSTM.setPalette(p)
        self.ui.toolButton_Set.setPalette(p)

        p.setColor(QtGui.QPalette.Button, QtGui.QColor(128, 128, 128))  # 灰色
        if i == 0:
            self.ui.toolButton_Home.setPalette(p)
        if i == 1:
            self.ui.toolButton_FFT.setPalette(p)
        if i == 2:
            self.ui.toolButton_CWT.setPalette(p)
        if i == 3:
            self.ui.toolButton_LSTM.setPalette(p)
        if i == 4:
            self.ui.toolButton_normalization.setPalette(p)
        if i == 5:
            self.ui.toolButton_Set.setPalette(p)

        if i == 4:
            self.ui.stackedWidget_Panel.setCurrentIndex(3)
            self.ui.stackedWidget_Canvs.setCurrentIndex(3)
        elif i == 5:
            self.ui.stackedWidget_Panel.setCurrentIndex(4)
            self.ui.stackedWidget_Canvs.setCurrentIndex(4)
        else:
            self.ui.stackedWidget_Panel.setCurrentIndex(i)
            self.ui.stackedWidget_Canvs.setCurrentIndex(i)

    def toolButton_Home_clicked(self):
        self.toolButton_NavigationBar_Update(0)

    def toolButton_FFT_clicked(self):
        if self.stateDiagram >= 1:  # 1-已加载文件
            self.toolButton_NavigationBar_Update(1)
            self.stateDiagram = 2
        else:
            QtWidgets.QMessageBox.warning(self, "Warning",
                                          Message().dict['Warning(1001)'],
                                          QtWidgets.QMessageBox.Yes)

    def toolButton_CWT_clicked(self):
        if self.stateDiagram >= 2:  # 2-已完成FFT
            self.toolButton_NavigationBar_Update(2)
            self.stateDiagram = 3
        else:
            QtWidgets.QMessageBox.warning(self, "Warning",
                                          Message().dict['Warning(1002)'],
                                          QtWidgets.QMessageBox.Yes)

    def toolButton_normalization_clicked(self):
        if self.stateDiagram >= 3:  # 3-已完成CWT
            self.toolButton_NavigationBar_Update(3)
        else:
            QtWidgets.QMessageBox.warning(self, "Warning",
                                          Message().dict['Warning(1003)'],
                                          QtWidgets.QMessageBox.Yes)

    def toolButton_LSTM_clicked(self):
        if self.stateDiagram >= 4:  # 4-已完成标准化
            self.toolButton_NavigationBar_Update(4)
        else:
            QtWidgets.QMessageBox.warning(self, "Warning",
                                          Message().dict['Warning(1003)'],
                                          QtWidgets.QMessageBox.Yes)

    def toolButton_Set_clicked(self):
        if self.stateDiagram >= 1:  # 1-已加载文件
            self.toolButton_NavigationBar_Update(5)
        else:
            QtWidgets.QMessageBox.warning(self, "Warning",
                                          Message().dict['Warning(1001)'],
                                          QtWidgets.QMessageBox.Yes)

    def toolButton_left(self):
        pass
        if self.segFile.TapeNumCurrent > 1:
            self.segFile.TapeNumCurrent = self.segFile.TapeNumCurrent - 1

            self.ui.label_number.setText(str(self.segFile.TapeNumCurrent + 1))
            cwtmatr = Algorithm_CWT.MyWavelets(
                self.segFile.dataList[self.segFile.TapeNumCurrent].data, 128)

            self.paintCWT.figureClear()

            # self.paintCWT.setAx(0,2) # 第 1 行, 共 2 行
            # self.paintCWT.MyMatshow(0,cwtmatr)

            self.paintCWT.setAx(0, 1, '3d')  # 第 2 行, 共 2 行
            self.paintCWT.MyPlot_surface(0, cwtmatr, 1,
                                         2)  # 第几行、数据、绘图采样步长:频率、绘图采样步长:时间
            # self.paintCWT.My3DView_init(0,45,180) #设置视角

    def toolButton_right(self):
        if self.segFile.TapeNumCurrent < (self.segFile.tapeNum - 1):
            self.segFile.TapeNumCurrent = self.segFile.TapeNumCurrent + 1
            self.ui.label_number.setText(str(self.segFile.TapeNumCurrent + 1))
            cwtmatr = Algorithm_CWT.MyWavelets(
                self.segFile.dataList[self.segFile.TapeNumCurrent].data, 128)

            self.paintCWT.figureClear()

            # self.paintCWT.setAx(0,2) # 第 1 行, 共 2 行
            # self.paintCWT.MyMatshow(0,cwtmatr)

            self.paintCWT.setAx(0, 1, '3d')  # 第 2 行, 共 2 行
            self.paintCWT.MyPlot_surface(0, cwtmatr, 1,
                                         2)  # 第几行、数据、绘图采样步长:频率、绘图采样步长:时间
class Controller(QtWidgets.QMainWindow):
    def __init__(self):
        super(Controller, self).__init__()  # 先调用父类的构造函数
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.initUi()  # 界面初始设置
        self.connect()  # 绑定信号槽
        self.addPainteWidget()  #添加绘图控件

        self.stateDiagram = 0  #程序状态控制 —— 用于切换不同界面控制:0.初始状态、1.已加载文件、2.已完成FFT、3.已完成CWT、4、已完成LSTM

    def initUi(self):  # 界面初始设置
        self.setWindowState(QtCore.Qt.WindowMaximized)
        self.toolButton_Home_clicked()

    '''  ↓ 添加绘图控件 ↓    '''

    def addPainteWidget(self):

        self.paintFFT = MyFigureCanvasFFT(1)
        self.ui.gridLayout_Canvas_FFT.addWidget(self.paintFFT)

        self.paintCWT = MyFigureCanvasCWT(2)
        self.ui.gridLayout_Canvas_CWT_Paint.addWidget(self.paintCWT)

        self.paintLSTM = MyFigureCanvasLSTM(3)
        self.ui.gridLayout_Canvas_LSTM.addWidget(self.paintLSTM)

    def connect(self):  # 绑定信号槽
        # 绑定导航栏按钮
        self.ui.toolButton_Home.clicked.connect(self.toolButton_Home_clicked)
        self.ui.toolButton_FFT.clicked.connect(self.toolButton_FFT_clicked)
        self.ui.toolButton_CWT.clicked.connect(self.toolButton_CWT_clicked)
        self.ui.toolButton_LSTM.clicked.connect(self.toolButton_LSTM_clicked)
        self.ui.toolButton_Set.clicked.connect(self.toolButton_Set_clicked)

        # 绑定meanBar
        self.ui.opeanFile.triggered.connect(self.menu_opeanFile)

    '''  -------------------- ↓ 菜单栏事件 ↓ --------------------  '''

    def menu_opeanFile(self):
        fileName, filetype = QtWidgets.QFileDialog.getOpenFileName(
            self, "选取文件", "C:/", "seg Files (*.seg)")  # 设置文件扩展名过滤,注意用双分号间隔

        if fileName == '':
            QtWidgets.QMessageBox.warning(self, "Warning",
                                          Message().dict['Error(1002)'],
                                          QtWidgets.QMessageBox.Yes)
        else:
            self.segFile = SegFile()

            reply = self.segFile.loadFile(fileName)
            if (reply != 0):
                QtWidgets.QMessageBox.warning(self, "Warning",
                                              Message().dict[reply],
                                              QtWidgets.QMessageBox.Yes)
            else:
                self.stateDiagram = 1  # 1-已加载文件

                self.paintCWT.figureClear()
                for i in range(0, self.segFile.tapeNum):
                    self.paintFFT.setAx(i, self.segFile.tapeNum, '2d')
                    self.paintFFT.paint(i, self.segFile.dataList[i].data)

                # cwtmatr,freqs = Algorithm.MyPywtCWT( self.segFile.dataList[ self.segFile.TapeNumCurrent ].data )
                # cwtmatr = Algorithm_CWT.MyScipyCwt(self.segFile.dataList[ self.segFile.TapeNumCurrent ].data, 128)
                cwtmatr = Algorithm_CWT.MyWavelets(
                    self.segFile.dataList[self.segFile.TapeNumCurrent].data,
                    128)

                self.paintCWT.figureClear()

                # self.paintCWT.setAx(0,2) # 第 1 行, 共 2 行
                # self.paintCWT.MyMatshow(0,cwtmatr)

                self.paintCWT.setAx(0, 1, '3d')  # 第 2 行, 共 2 行
                self.paintCWT.MyPlot_surface(0, cwtmatr, 1,
                                             2)  # 第几行、数据、绘图采样步长:频率、绘图采样步长:时间
                self.paintCWT.My3DView_init(0, 45, 180)

    # 导航栏更新

    def toolButton_NavigationBar_Update(self, i):
        # 设置导航栏颜色
        p = QtGui.QPalette()  # 调色板
        p.setColor(QtGui.QPalette.Button, QtGui.QColor(44, 44, 44))  # 灰黑色

        self.ui.toolButton_Home.setPalette(p)
        self.ui.toolButton_FFT.setPalette(p)
        self.ui.toolButton_CWT.setPalette(p)
        self.ui.toolButton_LSTM.setPalette(p)
        self.ui.toolButton_Set.setPalette(p)

        p.setColor(QtGui.QPalette.Button, QtGui.QColor(128, 128, 128))  # 灰色
        if i == 0:
            self.ui.toolButton_Home.setPalette(p)
        if i == 1:
            self.ui.toolButton_FFT.setPalette(p)
        if i == 2:
            self.ui.toolButton_CWT.setPalette(p)
        if i == 3:
            self.ui.toolButton_LSTM.setPalette(p)
        if i == 4:
            self.ui.toolButton_Set.setPalette(p)

        self.ui.stackedWidget_Panel.setCurrentIndex(i)
        self.ui.stackedWidget_Canvs.setCurrentIndex(i)

    def toolButton_Home_clicked(self):
        self.toolButton_NavigationBar_Update(0)

    def toolButton_FFT_clicked(self):
        if self.stateDiagram >= 1:  # 1-已加载文件
            self.toolButton_NavigationBar_Update(1)
            self.stateDiagram = 2
        else:
            QtWidgets.QMessageBox.warning(self, "Warning",
                                          Message().dict['Warning(1001)'],
                                          QtWidgets.QMessageBox.Yes)

    def toolButton_CWT_clicked(self):
        if self.stateDiagram >= 2:  # 2-已完成FFT
            self.toolButton_NavigationBar_Update(2)
        else:
            QtWidgets.QMessageBox.warning(self, "Warning",
                                          Message().dict['Warning(1002)'],
                                          QtWidgets.QMessageBox.Yes)

    def toolButton_LSTM_clicked(self):
        if self.stateDiagram >= 3:  # 3-已完成CWT
            self.toolButton_NavigationBar_Update(3)
        else:
            QtWidgets.QMessageBox.warning(self, "Warning",
                                          Message().dict['Warning(1003)'],
                                          QtWidgets.QMessageBox.Yes)

    def toolButton_Set_clicked(self):
        if self.stateDiagram >= 1:  # 1-已加载文件
            self.toolButton_NavigationBar_Update(4)
        else:
            QtWidgets.QMessageBox.warning(self, "Warning",
                                          Message().dict['Warning(1001)'],
                                          QtWidgets.QMessageBox.Yes)
Пример #5
0
class Controller(QtWidgets.QMainWindow):
    def __init__(self):
        super(Controller, self).__init__()  # 先调用父类的构造函数
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.initUi()  # 界面初始设置
        self.connect()  # 绑定信号槽
        self.addPainteWidget()  #添加绘图控件

        self.stateDiagram = 0  #程序状态控制 —— 用于切换不同界面控制:0.初始状态、1.已加载文件、2.已完成FFT、3.已完成CWT、4、已完成LSTM

    def initUi(self):  # 界面初始设置
        self.setWindowState(QtCore.Qt.WindowMaximized)
        self.toolButton_Home_clicked()

    '''  ↓ 添加绘图控件 ↓    '''

    def addPainteWidget(self):

        self.pushButton123 = QtWidgets.QPushButton(self.ui.page_Canvas_Home)
        self.pushButton123.setObjectName("pushButton123")
        self.ui.gridLayout_Canvas_Home.addWidget(self.pushButton123, 3, 0, 2,
                                                 1)

        self.paintHome = MyFigureCanvas(self.ui.page_Canvas_Home)
        self.ui.gridLayout_Canvas_Home.addWidget(self.paintHome)

        self.paintFFT = MyFigureCanvas(self.ui.page_Canvas_FFT)
        self.ui.gridLayout_Canvas_FFT.addWidget(self.paintFFT, 1, 0, 1, 1)

        self.paintCWT = MyFigureCanvas(self.ui.page_Canvas_CWT)
        self.ui.gridLayout_Canvas_CWT.addWidget(self.paintCWT)

        # self.paintLSTM = MyFigureCanvas()
        # self.ui.gridLayout_Canvas_LSTM.addWidget(self.paintLSTM)

    def connect(self):  # 绑定信号槽
        # 绑定导航栏按钮
        self.ui.toolButton_Home.clicked.connect(self.toolButton_Home_clicked)
        self.ui.toolButton_FFT.clicked.connect(self.toolButton_FFT_clicked)
        self.ui.toolButton_CWT.clicked.connect(self.toolButton_CWT_clicked)
        self.ui.toolButton_LSTM.clicked.connect(self.toolButton_LSTM_clicked)
        self.ui.toolButton_Set.clicked.connect(self.toolButton_Set_clicked)

        # 绑定meanBar
        self.ui.opeanFile.triggered.connect(self.menu_opeanFile)

    '''  -------------------- ↓ 菜单栏事件 ↓ --------------------  '''

    def menu_opeanFile(self):
        fileName, filetype = QtWidgets.QFileDialog.getOpenFileName(
            self, "选取文件", "C:/", "seg Files (*.seg)")  # 设置文件扩展名过滤,注意用双分号间隔

        if fileName == '':
            QtWidgets.QMessageBox.warning(self, "Warning",
                                          Message().dict['Error(1002)'],
                                          QtWidgets.QMessageBox.Yes)
        else:
            self.segFile = SegFile()

            reply = self.segFile.loadFile(fileName)
            if (reply != 0):
                QtWidgets.QMessageBox.warning(self, "Warning",
                                              Message().dict[reply],
                                              QtWidgets.QMessageBox.Yes)
            else:
                self.stateDiagram = 1  # 1-已加载文件

                # self.paintFFT.figure.clf()
                # for i in range(0,self.segFile.tapeNum):
                # for i in range(0,1):
                #     self.paintCWT.setAx(i,self.segFile.tapeNum)
                #     self.paintCWT.paint(self.segFile.dataList[i].data,i)
                #### self.paintFFT.canvas.draw() #在画布上绘制

                #self.paintHome.figure.clf()
                # for i in range(0,self.segFile.tapeNum):
                for i in range(0, 1):
                    self.paintHome.setAx(i, self.segFile.tapeNum)
                    self.paintHome.paint(self.segFile.dataList[i].data, i)
                self.paintHome.canvas.draw()  #在画布上绘制

    # 导航栏更新

    def toolButton_NavigationBar_Update(self, i):
        # 设置导航栏颜色
        p = QtGui.QPalette()  # 调色板
        p.setColor(QtGui.QPalette.Button, QtGui.QColor(44, 44, 44))  # 灰黑色

        self.ui.toolButton_Home.setPalette(p)
        self.ui.toolButton_FFT.setPalette(p)
        self.ui.toolButton_CWT.setPalette(p)
        self.ui.toolButton_LSTM.setPalette(p)
        self.ui.toolButton_Set.setPalette(p)

        p.setColor(QtGui.QPalette.Button, QtGui.QColor(128, 128, 128))  # 灰色
        if i == 0:
            self.ui.toolButton_Home.setPalette(p)
        if i == 1:
            self.ui.toolButton_FFT.setPalette(p)
        if i == 2:
            self.ui.toolButton_CWT.setPalette(p)
        if i == 3:
            self.ui.toolButton_LSTM.setPalette(p)
        if i == 4:
            self.ui.toolButton_Set.setPalette(p)

        self.ui.stackedWidget_Panel.setCurrentIndex(i)
        self.ui.stackedWidget_Canvs.setCurrentIndex(i)

    def toolButton_Home_clicked(self):
        self.toolButton_NavigationBar_Update(0)

    def toolButton_FFT_clicked(self):
        if self.stateDiagram >= 1:  # 1-已加载文件
            self.toolButton_NavigationBar_Update(1)
            self.stateDiagram = 2
        else:
            QtWidgets.QMessageBox.warning(self, "Warning",
                                          Message().dict['Warning(1001)'],
                                          QtWidgets.QMessageBox.Yes)

    def toolButton_CWT_clicked(self):
        if self.stateDiagram >= 2:  # 2-已完成FFT
            self.toolButton_NavigationBar_Update(2)
        else:
            QtWidgets.QMessageBox.warning(self, "Warning",
                                          Message().dict['Warning(1002)'],
                                          QtWidgets.QMessageBox.Yes)

    def toolButton_LSTM_clicked(self):
        if self.stateDiagram >= 3:  # 3-已完成CWT
            self.toolButton_NavigationBar_Update(3)
        else:
            QtWidgets.QMessageBox.warning(self, "Warning",
                                          Message().dict['Warning(1003)'],
                                          QtWidgets.QMessageBox.Yes)

    def toolButton_Set_clicked(self):
        if self.stateDiagram >= 1:  # 1-已加载文件
            self.toolButton_NavigationBar_Update(4)
        else:
            QtWidgets.QMessageBox.warning(self, "Warning",
                                          Message().dict['Warning(1001)'],
                                          QtWidgets.QMessageBox.Yes)