实验性功能:新增了<数据预处理>的绘图方式,在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)
|
||||
|
||||
def __slot_btn_preprocess__(self):
|
||||
self.preprocess = MainWindow_preprocess()
|
||||
self.preprocess = MainWindow_preprocess(Config["Plot_Mode"])
|
||||
|
||||
sender = self.sender()
|
||||
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.backends.backend_qt import NavigationToolbar2QT
|
||||
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg
|
||||
from numpy import column_stack, arange
|
||||
from overrides import overrides
|
||||
from pandas import read_csv, DataFrame
|
||||
from scipy.signal import resample
|
||||
from vispy import scene
|
||||
from vispy.scene import visuals
|
||||
from yaml import dump, load, FullLoader
|
||||
|
||||
from func.utils.ConfigParams import Filename, Params
|
||||
@ -167,7 +170,7 @@ class SettingWindow(QMainWindow):
|
||||
|
||||
class MainWindow_preprocess(QMainWindow):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, plot_mode):
|
||||
super(MainWindow_preprocess, self).__init__()
|
||||
self.ui = Ui_MainWindow_preprocess()
|
||||
self.ui.setupUi(self)
|
||||
@ -184,12 +187,24 @@ class MainWindow_preprocess(QMainWindow):
|
||||
self.progressbar = None
|
||||
PublicFunc.add_progressbar(self)
|
||||
|
||||
#初始化画框
|
||||
self.fig = None
|
||||
self.canvas = None
|
||||
self.figToolbar = None
|
||||
self.gs = None
|
||||
self.ax0 = None
|
||||
self.plot_mode = plot_mode
|
||||
if self.plot_mode == "matplotlib":
|
||||
#初始化画框
|
||||
self.fig = None
|
||||
self.canvas = None
|
||||
self.figToolbar = None
|
||||
self.gs = 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); }")
|
||||
PublicFunc.__styleAllButton__(self, ButtonState)
|
||||
@ -206,20 +221,50 @@ class MainWindow_preprocess(QMainWindow):
|
||||
|
||||
self.setting = SettingWindow(mode, root_path, sampID)
|
||||
|
||||
# 初始化画框
|
||||
self.fig = plt.figure(figsize=(12, 9), dpi=100)
|
||||
self.canvas = FigureCanvasQTAgg(self.fig)
|
||||
self.figToolbar = NavigationToolbar2QT(self.canvas)
|
||||
for action in self.figToolbar.actions():
|
||||
if action.text() == "Subplots" or action.text() == "Customize":
|
||||
self.figToolbar.removeAction(action)
|
||||
self.ui.verticalLayout_canvas.addWidget(self.canvas)
|
||||
self.ui.verticalLayout_canvas.addWidget(self.figToolbar)
|
||||
self.gs = gridspec.GridSpec(1, 1, height_ratios=[1])
|
||||
self.fig.subplots_adjust(top=0.98, bottom=0.05, right=0.98, left=0.1, hspace=0, wspace=0)
|
||||
self.ax0 = self.fig.add_subplot(self.gs[0])
|
||||
self.ax0.grid(True)
|
||||
self.ax0.xaxis.set_major_formatter(Params.FORMATTER)
|
||||
if self.plot_mode == "matplotlib":
|
||||
# 初始化画框
|
||||
self.fig = plt.figure(figsize=(12, 9), dpi=100)
|
||||
self.canvas = FigureCanvasQTAgg(self.fig)
|
||||
self.figToolbar = NavigationToolbar2QT(self.canvas)
|
||||
for action in self.figToolbar.actions():
|
||||
if action.text() == "Subplots" or action.text() == "Customize":
|
||||
self.figToolbar.removeAction(action)
|
||||
self.ui.verticalLayout_canvas.addWidget(self.canvas)
|
||||
self.ui.verticalLayout_canvas.addWidget(self.figToolbar)
|
||||
self.gs = gridspec.GridSpec(1, 1, height_ratios=[1])
|
||||
self.fig.subplots_adjust(top=0.98, bottom=0.05, right=0.98, left=0.1, hspace=0, wspace=0)
|
||||
self.ax0 = self.fig.add_subplot(self.gs[0])
|
||||
self.ax0.grid(True)
|
||||
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)
|
||||
|
||||
@ -253,14 +298,17 @@ class MainWindow_preprocess(QMainWindow):
|
||||
QApplication.processEvents()
|
||||
|
||||
# 清空画框
|
||||
if self.ax0 is not None:
|
||||
self.ax0.clear()
|
||||
if self.plot_mode == "matplotlib":
|
||||
if self.ax0 is not None:
|
||||
self.ax0.clear()
|
||||
self.fig.clf()
|
||||
plt.close(self.fig)
|
||||
elif self.plot_mode == "vispy":
|
||||
self.canvas.close()
|
||||
|
||||
# 释放资源
|
||||
self.setting.close()
|
||||
del self.data
|
||||
self.fig.clf()
|
||||
plt.close(self.fig)
|
||||
self.deleteLater()
|
||||
collect()
|
||||
self.canvas = None
|
||||
@ -273,23 +321,53 @@ class MainWindow_preprocess(QMainWindow):
|
||||
|
||||
def __plot__(self):
|
||||
# 清空画框
|
||||
self.reset_axes()
|
||||
if self.plot_mode == "matplotlib":
|
||||
self.reset_axes()
|
||||
sender = self.sender()
|
||||
if sender == self.ui.pushButton_view:
|
||||
self.ax0.plot(self.data.raw_data,
|
||||
color=Constants.PLOT_COLOR_RED,
|
||||
label=Constants.PREPROCESS_PLOT_LABEL_ORIGINAL_DATA)
|
||||
self.ax0.plot(self.data.processed_data + Constants.PREPROCESS_OUTPUT_INPUT_AMP_OFFSET,
|
||||
color=Constants.PLOT_COLOR_BLUE,
|
||||
label=Constants.PREPROCESS_PLOT_LABEL_PROCESSED_DATA)
|
||||
self.ax0.legend(loc=Constants.PLOT_UPPER_RIGHT)
|
||||
self.canvas.draw()
|
||||
return Result().success(info=Constants.DRAW_FINISHED)
|
||||
else:
|
||||
self.canvas.draw()
|
||||
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:
|
||||
|
||||
sender = self.sender()
|
||||
|
||||
if sender == self.ui.pushButton_view:
|
||||
self.ax0.plot(self.data.raw_data,
|
||||
color=Constants.PLOT_COLOR_RED,
|
||||
label=Constants.PREPROCESS_PLOT_LABEL_ORIGINAL_DATA)
|
||||
self.ax0.plot(self.data.processed_data + Constants.PREPROCESS_OUTPUT_INPUT_AMP_OFFSET,
|
||||
color=Constants.PLOT_COLOR_BLUE,
|
||||
label=Constants.PREPROCESS_PLOT_LABEL_PROCESSED_DATA)
|
||||
self.ax0.legend(loc=Constants.PLOT_UPPER_RIGHT)
|
||||
self.canvas.draw()
|
||||
return Result().success(info=Constants.DRAW_FINISHED)
|
||||
else:
|
||||
self.canvas.draw()
|
||||
return Result().success(info=Constants.DRAW_FAILURE)
|
||||
return Result().failure(info=Constants.DRAW_FAILURE)
|
||||
|
||||
def __update_config__(self):
|
||||
if self.mode == "BCG":
|
||||
@ -306,10 +384,12 @@ class MainWindow_preprocess(QMainWindow):
|
||||
def __slot_btn_input__(self):
|
||||
PublicFunc.__disableAllButton__(self, ButtonState)
|
||||
|
||||
# 清空画框
|
||||
self.reset_axes()
|
||||
|
||||
self.canvas.draw()
|
||||
if self.plot_mode == "matplotlib":
|
||||
# 清空画框
|
||||
self.reset_axes()
|
||||
self.canvas.draw()
|
||||
elif self.plot_mode == "vispy":
|
||||
self.canvas.update()
|
||||
|
||||
self.data = Data()
|
||||
|
||||
|
||||
@ -76,7 +76,8 @@ class Params:
|
||||
PUBLIC_CONFIG_NEW_CONTENT = {
|
||||
"Path": {
|
||||
"Root": ""
|
||||
}
|
||||
},
|
||||
"Plot_Mode": "matplotlib"
|
||||
}
|
||||
UTF8_ENCODING: str = "utf-8"
|
||||
GBK_ENCODING: str = "gbk"
|
||||
|
||||
Reference in New Issue
Block a user