添加视图切换按钮并实现绘制散点图功能,优化数据处理逻辑

This commit is contained in:
marques
2025-05-20 15:04:48 +08:00
parent adb90c258c
commit b87ca6ed42
3 changed files with 73 additions and 30 deletions

View File

@ -245,6 +245,7 @@ class MainWindow_approximately_align(QMainWindow):
self.ui.pushButton_Standardize.clicked.connect(self.__slot_btn_Standardize__) self.ui.pushButton_Standardize.clicked.connect(self.__slot_btn_Standardize__)
self.ui.pushButton_CutOff.clicked.connect(self.__slot_btn_CutOff__) self.ui.pushButton_CutOff.clicked.connect(self.__slot_btn_CutOff__)
self.ui.pushButton_GetPos.clicked.connect(self.__slot_btn_GetPosition__) self.ui.pushButton_GetPos.clicked.connect(self.__slot_btn_GetPosition__)
self.ui.pushButton_ChangeView.clicked.connect(self.__slot_btn_changeview__)
self.ui.pushButton_JUMP.clicked.connect(self.__slot_btn_jump__) self.ui.pushButton_JUMP.clicked.connect(self.__slot_btn_jump__)
self.ui.pushButton_save.clicked.connect(self.__slot_btn_save__) self.ui.pushButton_save.clicked.connect(self.__slot_btn_save__)
self.ui.pushButton_EM1.clicked.connect(self.__EpochChange__) self.ui.pushButton_EM1.clicked.connect(self.__EpochChange__)
@ -259,6 +260,7 @@ class MainWindow_approximately_align(QMainWindow):
self.ui.radioButton_NABD.clicked.connect(self.__enableAlign__) self.ui.radioButton_NABD.clicked.connect(self.__enableAlign__)
self.ui.radioButton_custom.clicked.connect(self.__enableAlign__) self.ui.radioButton_custom.clicked.connect(self.__enableAlign__)
@overrides @overrides
def closeEvent(self, event): def closeEvent(self, event):
reply = QMessageBox.question(self, '确认', '确认退出吗?', QMessageBox.Yes | QMessageBox.No, QMessageBox.No) reply = QMessageBox.question(self, '确认', '确认退出吗?', QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
@ -325,6 +327,8 @@ class MainWindow_approximately_align(QMainWindow):
result = self.DrawPicTryAlign() result = self.DrawPicTryAlign()
elif sender == self.ui.radioButton_custom: elif sender == self.ui.radioButton_custom:
result = self.DrawPicTryAlign() result = self.DrawPicTryAlign()
elif sender == self.ui.pushButton_ChangeView:
result = self.DrawAlignScatter()
elif sender == self.ui.pushButton_JUMP: elif sender == self.ui.pushButton_JUMP:
result = self.DrawPicByEpoch(*args, **kwargs) result = self.DrawPicByEpoch(*args, **kwargs)
elif sender == self.ui.pushButton_EM1: elif sender == self.ui.pushButton_EM1:
@ -561,6 +565,22 @@ class MainWindow_approximately_align(QMainWindow):
# self.ui.groupBox_align_position.setEnabled(True) # self.ui.groupBox_align_position.setEnabled(True)
PublicFunc.finish_operation(self, ButtonState) PublicFunc.finish_operation(self, ButtonState)
def __slot_btn_changeview__(self):
PublicFunc.__disableAllButton__(self, ButtonState)
# 绘图
PublicFunc.progressbar_update(self, 1, 1, Constants.DRAWING_DATA, 0)
result = self.__plot__()
if not result.status:
PublicFunc.text_output(self.ui, "(1/1)" + result.info, Constants.TIPS_TYPE_ERROR)
PublicFunc.msgbox_output(self, result.info, Constants.MSGBOX_TYPE_ERROR)
PublicFunc.finish_operation(self, ButtonState)
return
else:
PublicFunc.text_output(self.ui, "(1/1)" + result.info, Constants.TIPS_TYPE_INFO)
PublicFunc.finish_operation(self, ButtonState)
def __slot_btn_jump__(self): def __slot_btn_jump__(self):
PublicFunc.__disableAllButton__(self, ButtonState) PublicFunc.__disableAllButton__(self, ButtonState)
@ -867,7 +887,27 @@ class MainWindow_approximately_align(QMainWindow):
return Result().success(info=Constants.DRAWING_FINISHED) return Result().success(info=Constants.DRAWING_FINISHED)
def DrawAlignScatter(self): def DrawAlignScatter(self):
pass try:
response = self.data.get_corr_by_epoch()
epoch_min = response.data["epoch_min"]
epoch_max = response.data["epoch_max"]
tho_bias_list = response.data["tho_bias_list"]
abd_bias_list = response.data["abd_bias_list"]
ax1 = self.fig.add_subplot(211)
ax1.scatter(linspace(epoch_min, epoch_max, len(tho_bias_list)), tho_bias_list, alpha=0.2)
ax1.set_title("THO")
ax2 = self.fig.add_subplot(212)
ax2.scatter(linspace(epoch_min, epoch_max, len(abd_bias_list)), abd_bias_list, alpha=0.2)
ax2.set_title("ABD")
self.fig.canvas.draw()
return Result().success(info=Constants.DRAWING_FINISHED)
except Exception as e:
return Result().failure(info=Constants.DRAWING_FAILURE + "\n" + format_exc())
class Data: class Data:
@ -1226,33 +1266,36 @@ class Data:
epoch_min = response.data["epoch_min"] epoch_min = response.data["epoch_min"]
epoch_max = response.data["epoch_max"] epoch_max = response.data["epoch_max"]
""" temp_freq = ConfigParams.APPROXIMATELY_ALIGN_CONFIG_NEW_CONTENT["TempFrequency"]
bias_list = [] window_epoch = ConfigParams.APPROXIMATELY_ALIGN_CONFIG_NEW_CONTENT["CorrByEpoch"]["window_epoch"]
samp_rate4 = 100 tho_bias_list = []
for epoch in tqdm(range(epoch_min, epoch_max)): abd_bias_list = []
win1 = 30 * epoch
win2 = win1 + 30 * 3
SP = win1 * samp_rate4
EP = win2 * samp_rate4
tho_seg = tho_pn * tho_low[SP: EP] # pos采样率转换
abd_seg = abd_pn * abd_low[SP: EP] pos = Config["pos"] * temp_freq // Config["ApplyFrequency"]
resp_seg = resp_pn * resp_low[SP - tho_pos *
samp_rate4: EP - tho_pos * samp_rate4]
abd_relate_seg = correlate(abd_seg, resp_seg, mode="full")
abd_seg_pos = np.argmax(abd_relate_seg) - len(resp_seg)
bias_list.append(abd_seg_pos)
plt.figure()
plt.scatter(np.linspace(0, len(bias_list), len(bias_list)), bias_list, alpha=0.2)
"""
for epoch in range(epoch_min, epoch_max): for epoch in range(epoch_min, epoch_max):
SP = epoch * 30 SP = epoch * 30 * temp_freq
EP = (epoch + window_epoch) * 30 * temp_freq
tho_seg = self.processed_Tho[SP:EP]
abd_seg = self.processed_Abd[SP:EP]
result = None orgBcg_seg = self.processed_orgBcg[SP - pos:EP - pos] * Config["orgBcg_reverse"]
tho_relate_seg = correlate(tho_seg, orgBcg_seg, mode='full')
abd_relate_seg = correlate(abd_seg, orgBcg_seg, mode='full')
tho_seg_pos = argmax(tho_relate_seg) - len(orgBcg_seg)
abd_seg_pos = argmax(abd_relate_seg) - len(orgBcg_seg)
tho_bias_list.append(tho_seg_pos // temp_freq)
abd_bias_list.append(abd_seg_pos // temp_freq)
result = {
"tho_bias_list": tho_bias_list,
"abd_bias_list": abd_bias_list,
"epoch_min": epoch_min,
"epoch_max": epoch_max
}
except Exception as e: except Exception as e:

View File

@ -1642,10 +1642,10 @@ class Data:
orgfs = Config["orgfs"] orgfs = Config["orgfs"]
off = Config["offset_anchor"] off = Config["offset_anchor"]
self.res_orgBcg = self.raw_orgBcg self.res_orgBcg = self.raw_orgBcg.copy()
self.res_BCG = self.raw_BCG self.res_BCG = self.raw_BCG.copy()
self.cut_ECG = self.raw_ECG self.cut_ECG = self.raw_ECG.copy()
self.cut_Rpeak = self.Rpeak self.cut_Rpeak = self.Rpeak.copy()
if off > 0: if off > 0:
self.cut_ECG = self.cut_ECG[off:] self.cut_ECG = self.cut_ECG[off:]

View File

@ -47,7 +47,7 @@ class ConfigParams:
"Multiple_Factor":100, "Multiple_Factor":100,
"CorrByEpoch": "CorrByEpoch":
{ {
"window_second": 30 "window_epoch": 6
} }
} }
APPROXIMATELY_ALIGN_INPUT_ORGBCG_FILENAME: str = "orgBcg_Raw_" APPROXIMATELY_ALIGN_INPUT_ORGBCG_FILENAME: str = "orgBcg_Raw_"