实验性功能:新增了<数据预处理>的绘图方式,在Config_public.yaml中将Plot_Mode字段的值改为"vispy"即可使用vispy的绘图引擎,默认为"matplotlib"
This commit is contained in:
@ -183,7 +183,7 @@ class MainWindow(QMainWindow, Ui_Signal_Label):
|
|||||||
self.check_save_path_and_mkdir(root_path, sampID)
|
self.check_save_path_and_mkdir(root_path, sampID)
|
||||||
|
|
||||||
def __slot_btn_preprocess__(self):
|
def __slot_btn_preprocess__(self):
|
||||||
self.preprocess = MainWindow_preprocess()
|
self.preprocess = MainWindow_preprocess(Config["Plot_Mode"])
|
||||||
|
|
||||||
sender = self.sender()
|
sender = self.sender()
|
||||||
root_path = self.ui.plainTextEdit_root_path.toPlainText()
|
root_path = self.ui.plainTextEdit_root_path.toPlainText()
|
||||||
|
|||||||
@ -7,9 +7,12 @@ from PySide6.QtWidgets import QMessageBox, QMainWindow, QApplication
|
|||||||
from matplotlib import gridspec
|
from matplotlib import gridspec
|
||||||
from matplotlib.backends.backend_qt import NavigationToolbar2QT
|
from matplotlib.backends.backend_qt import NavigationToolbar2QT
|
||||||
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg
|
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg
|
||||||
|
from numpy import column_stack, arange
|
||||||
from overrides import overrides
|
from overrides import overrides
|
||||||
from pandas import read_csv, DataFrame
|
from pandas import read_csv, DataFrame
|
||||||
from scipy.signal import resample
|
from scipy.signal import resample
|
||||||
|
from vispy import scene
|
||||||
|
from vispy.scene import visuals
|
||||||
from yaml import dump, load, FullLoader
|
from yaml import dump, load, FullLoader
|
||||||
|
|
||||||
from func.utils.ConfigParams import Filename, Params
|
from func.utils.ConfigParams import Filename, Params
|
||||||
@ -167,7 +170,7 @@ class SettingWindow(QMainWindow):
|
|||||||
|
|
||||||
class MainWindow_preprocess(QMainWindow):
|
class MainWindow_preprocess(QMainWindow):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, plot_mode):
|
||||||
super(MainWindow_preprocess, self).__init__()
|
super(MainWindow_preprocess, self).__init__()
|
||||||
self.ui = Ui_MainWindow_preprocess()
|
self.ui = Ui_MainWindow_preprocess()
|
||||||
self.ui.setupUi(self)
|
self.ui.setupUi(self)
|
||||||
@ -184,12 +187,24 @@ class MainWindow_preprocess(QMainWindow):
|
|||||||
self.progressbar = None
|
self.progressbar = None
|
||||||
PublicFunc.add_progressbar(self)
|
PublicFunc.add_progressbar(self)
|
||||||
|
|
||||||
|
self.plot_mode = plot_mode
|
||||||
|
if self.plot_mode == "matplotlib":
|
||||||
#初始化画框
|
#初始化画框
|
||||||
self.fig = None
|
self.fig = None
|
||||||
self.canvas = None
|
self.canvas = None
|
||||||
self.figToolbar = None
|
self.figToolbar = None
|
||||||
self.gs = None
|
self.gs = None
|
||||||
self.ax0 = None
|
self.ax0 = None
|
||||||
|
elif self.plot_mode == "vispy":
|
||||||
|
# 初始化画框
|
||||||
|
self.canvas = None
|
||||||
|
self.view = None
|
||||||
|
self.y_axis = None
|
||||||
|
self.x_axis = None
|
||||||
|
self.view = None
|
||||||
|
self.grid_lines = None
|
||||||
|
self.line_original = None
|
||||||
|
self.line_processed = None
|
||||||
|
|
||||||
self.ui.textBrowser_info.setStyleSheet("QTextBrowser { background-color: rgb(255, 255, 200); }")
|
self.ui.textBrowser_info.setStyleSheet("QTextBrowser { background-color: rgb(255, 255, 200); }")
|
||||||
PublicFunc.__styleAllButton__(self, ButtonState)
|
PublicFunc.__styleAllButton__(self, ButtonState)
|
||||||
@ -206,6 +221,7 @@ class MainWindow_preprocess(QMainWindow):
|
|||||||
|
|
||||||
self.setting = SettingWindow(mode, root_path, sampID)
|
self.setting = SettingWindow(mode, root_path, sampID)
|
||||||
|
|
||||||
|
if self.plot_mode == "matplotlib":
|
||||||
# 初始化画框
|
# 初始化画框
|
||||||
self.fig = plt.figure(figsize=(12, 9), dpi=100)
|
self.fig = plt.figure(figsize=(12, 9), dpi=100)
|
||||||
self.canvas = FigureCanvasQTAgg(self.fig)
|
self.canvas = FigureCanvasQTAgg(self.fig)
|
||||||
@ -220,6 +236,35 @@ class MainWindow_preprocess(QMainWindow):
|
|||||||
self.ax0 = self.fig.add_subplot(self.gs[0])
|
self.ax0 = self.fig.add_subplot(self.gs[0])
|
||||||
self.ax0.grid(True)
|
self.ax0.grid(True)
|
||||||
self.ax0.xaxis.set_major_formatter(Params.FORMATTER)
|
self.ax0.xaxis.set_major_formatter(Params.FORMATTER)
|
||||||
|
elif self.plot_mode == "vispy":
|
||||||
|
# 初始化画框
|
||||||
|
self.canvas = scene.SceneCanvas(keys='interactive', show=True, bgcolor='white')
|
||||||
|
self.ui.verticalLayout_canvas.addWidget(self.canvas.native)
|
||||||
|
self.main_grid = self.canvas.central_widget.add_grid(spacing=0)
|
||||||
|
self.y_axis = scene.AxisWidget(orientation='left',
|
||||||
|
axis_color='black',
|
||||||
|
tick_color='black',
|
||||||
|
text_color='black',
|
||||||
|
axis_font_size=4,
|
||||||
|
tick_font_size=4,
|
||||||
|
tick_label_margin=20)
|
||||||
|
self.y_axis.width_max = 80
|
||||||
|
self.x_axis = scene.AxisWidget(orientation='bottom',
|
||||||
|
axis_color='black',
|
||||||
|
tick_color='black',
|
||||||
|
text_color='black',
|
||||||
|
axis_font_size=4,
|
||||||
|
tick_font_size=4,
|
||||||
|
tick_label_margin=20)
|
||||||
|
self.x_axis.height_max = 40
|
||||||
|
self.view = self.main_grid.add_view(row=0, col=1, camera='panzoom')
|
||||||
|
self.main_grid.add_widget(self.y_axis, row=0, col=0)
|
||||||
|
self.main_grid.add_widget(self.x_axis, row=1, col=1)
|
||||||
|
self.x_axis.link_view(self.view)
|
||||||
|
self.y_axis.link_view(self.view)
|
||||||
|
self.grid_lines = visuals.GridLines(color=(0.3, 0.3, 0.3, 0.5), parent=self.view.scene)
|
||||||
|
self.grid_lines.set_gl_state(line_width=1)
|
||||||
|
self.grid_lines.order = 100
|
||||||
|
|
||||||
PublicFunc.__resetAllButton__(self, ButtonState)
|
PublicFunc.__resetAllButton__(self, ButtonState)
|
||||||
|
|
||||||
@ -253,14 +298,17 @@ class MainWindow_preprocess(QMainWindow):
|
|||||||
QApplication.processEvents()
|
QApplication.processEvents()
|
||||||
|
|
||||||
# 清空画框
|
# 清空画框
|
||||||
|
if self.plot_mode == "matplotlib":
|
||||||
if self.ax0 is not None:
|
if self.ax0 is not None:
|
||||||
self.ax0.clear()
|
self.ax0.clear()
|
||||||
|
self.fig.clf()
|
||||||
|
plt.close(self.fig)
|
||||||
|
elif self.plot_mode == "vispy":
|
||||||
|
self.canvas.close()
|
||||||
|
|
||||||
# 释放资源
|
# 释放资源
|
||||||
self.setting.close()
|
self.setting.close()
|
||||||
del self.data
|
del self.data
|
||||||
self.fig.clf()
|
|
||||||
plt.close(self.fig)
|
|
||||||
self.deleteLater()
|
self.deleteLater()
|
||||||
collect()
|
collect()
|
||||||
self.canvas = None
|
self.canvas = None
|
||||||
@ -273,10 +321,9 @@ class MainWindow_preprocess(QMainWindow):
|
|||||||
|
|
||||||
def __plot__(self):
|
def __plot__(self):
|
||||||
# 清空画框
|
# 清空画框
|
||||||
|
if self.plot_mode == "matplotlib":
|
||||||
self.reset_axes()
|
self.reset_axes()
|
||||||
|
|
||||||
sender = self.sender()
|
sender = self.sender()
|
||||||
|
|
||||||
if sender == self.ui.pushButton_view:
|
if sender == self.ui.pushButton_view:
|
||||||
self.ax0.plot(self.data.raw_data,
|
self.ax0.plot(self.data.raw_data,
|
||||||
color=Constants.PLOT_COLOR_RED,
|
color=Constants.PLOT_COLOR_RED,
|
||||||
@ -289,7 +336,38 @@ class MainWindow_preprocess(QMainWindow):
|
|||||||
return Result().success(info=Constants.DRAW_FINISHED)
|
return Result().success(info=Constants.DRAW_FINISHED)
|
||||||
else:
|
else:
|
||||||
self.canvas.draw()
|
self.canvas.draw()
|
||||||
return Result().success(info=Constants.DRAW_FAILURE)
|
return Result().failure(info=Constants.DRAW_FAILURE)
|
||||||
|
elif self.plot_mode == "vispy":
|
||||||
|
sender = self.sender()
|
||||||
|
if self.line_original is not None:
|
||||||
|
self.line_original.parent = None
|
||||||
|
if self.line_processed is not None:
|
||||||
|
self.line_processed.parent = None
|
||||||
|
if sender == self.ui.pushButton_view:
|
||||||
|
t = arange(len(self.data.raw_data))
|
||||||
|
raw_data_2d = column_stack((t, self.data.raw_data))
|
||||||
|
self.line_original = visuals.Line(raw_data_2d,
|
||||||
|
color=Constants.PLOT_COLOR_RED,
|
||||||
|
parent=self.view.scene,
|
||||||
|
antialias=False,
|
||||||
|
width=2,
|
||||||
|
method='gl')
|
||||||
|
processed_y = self.data.processed_data + Constants.PREPROCESS_OUTPUT_INPUT_AMP_OFFSET
|
||||||
|
processed_data_2d = column_stack((t, processed_y))
|
||||||
|
self.line_processed = visuals.Line(processed_data_2d,
|
||||||
|
color=Constants.PLOT_COLOR_BLUE,
|
||||||
|
parent=self.view.scene,
|
||||||
|
antialias=False,
|
||||||
|
width=2,
|
||||||
|
method='gl')
|
||||||
|
self.line_original.order = 0
|
||||||
|
self.line_processed.order = -1
|
||||||
|
self.view.camera.set_range()
|
||||||
|
self.canvas.update()
|
||||||
|
return Result().success(info=Constants.DRAW_FINISHED)
|
||||||
|
else:
|
||||||
|
|
||||||
|
return Result().failure(info=Constants.DRAW_FAILURE)
|
||||||
|
|
||||||
def __update_config__(self):
|
def __update_config__(self):
|
||||||
if self.mode == "BCG":
|
if self.mode == "BCG":
|
||||||
@ -306,10 +384,12 @@ class MainWindow_preprocess(QMainWindow):
|
|||||||
def __slot_btn_input__(self):
|
def __slot_btn_input__(self):
|
||||||
PublicFunc.__disableAllButton__(self, ButtonState)
|
PublicFunc.__disableAllButton__(self, ButtonState)
|
||||||
|
|
||||||
|
if self.plot_mode == "matplotlib":
|
||||||
# 清空画框
|
# 清空画框
|
||||||
self.reset_axes()
|
self.reset_axes()
|
||||||
|
|
||||||
self.canvas.draw()
|
self.canvas.draw()
|
||||||
|
elif self.plot_mode == "vispy":
|
||||||
|
self.canvas.update()
|
||||||
|
|
||||||
self.data = Data()
|
self.data = Data()
|
||||||
|
|
||||||
|
|||||||
@ -76,7 +76,8 @@ class Params:
|
|||||||
PUBLIC_CONFIG_NEW_CONTENT = {
|
PUBLIC_CONFIG_NEW_CONTENT = {
|
||||||
"Path": {
|
"Path": {
|
||||||
"Root": ""
|
"Root": ""
|
||||||
}
|
},
|
||||||
|
"Plot_Mode": "matplotlib"
|
||||||
}
|
}
|
||||||
UTF8_ENCODING: str = "utf-8"
|
UTF8_ENCODING: str = "utf-8"
|
||||||
GBK_ENCODING: str = "gbk"
|
GBK_ENCODING: str = "gbk"
|
||||||
|
|||||||
Reference in New Issue
Block a user