From b87ca6ed42390691ac50c728131929f7fa45c8a3 Mon Sep 17 00:00:00 2001 From: marques <20172333133@m.scnu.edu.cn> Date: Tue, 20 May 2025 15:04:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=A7=86=E5=9B=BE=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E6=8C=89=E9=92=AE=E5=B9=B6=E5=AE=9E=E7=8E=B0=E7=BB=98?= =?UTF-8?q?=E5=88=B6=E6=95=A3=E7=82=B9=E5=9B=BE=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- func/Module_approximately_align.py | 93 ++++++++++++++++++++++-------- func/Module_precisely_align.py | 8 +-- func/utils/ConfigParams.py | 2 +- 3 files changed, 73 insertions(+), 30 deletions(-) diff --git a/func/Module_approximately_align.py b/func/Module_approximately_align.py index d925cc4..d161719 100644 --- a/func/Module_approximately_align.py +++ b/func/Module_approximately_align.py @@ -245,6 +245,7 @@ class MainWindow_approximately_align(QMainWindow): self.ui.pushButton_Standardize.clicked.connect(self.__slot_btn_Standardize__) self.ui.pushButton_CutOff.clicked.connect(self.__slot_btn_CutOff__) 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_save.clicked.connect(self.__slot_btn_save__) 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_custom.clicked.connect(self.__enableAlign__) + @overrides def closeEvent(self, event): reply = QMessageBox.question(self, '确认', '确认退出吗?', QMessageBox.Yes | QMessageBox.No, QMessageBox.No) @@ -325,6 +327,8 @@ class MainWindow_approximately_align(QMainWindow): result = self.DrawPicTryAlign() elif sender == self.ui.radioButton_custom: result = self.DrawPicTryAlign() + elif sender == self.ui.pushButton_ChangeView: + result = self.DrawAlignScatter() elif sender == self.ui.pushButton_JUMP: result = self.DrawPicByEpoch(*args, **kwargs) elif sender == self.ui.pushButton_EM1: @@ -561,6 +565,22 @@ class MainWindow_approximately_align(QMainWindow): # self.ui.groupBox_align_position.setEnabled(True) 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): PublicFunc.__disableAllButton__(self, ButtonState) @@ -867,7 +887,27 @@ class MainWindow_approximately_align(QMainWindow): return Result().success(info=Constants.DRAWING_FINISHED) 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: @@ -1226,33 +1266,36 @@ class Data: epoch_min = response.data["epoch_min"] epoch_max = response.data["epoch_max"] - """ - bias_list = [] - samp_rate4 = 100 - for epoch in tqdm(range(epoch_min, epoch_max)): - win1 = 30 * epoch - win2 = win1 + 30 * 3 - SP = win1 * samp_rate4 - EP = win2 * samp_rate4 - - tho_seg = tho_pn * tho_low[SP: EP] - abd_seg = abd_pn * abd_low[SP: EP] - 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) - """ + temp_freq = ConfigParams.APPROXIMATELY_ALIGN_CONFIG_NEW_CONTENT["TempFrequency"] + window_epoch = ConfigParams.APPROXIMATELY_ALIGN_CONFIG_NEW_CONTENT["CorrByEpoch"]["window_epoch"] + tho_bias_list = [] + abd_bias_list = [] + + # pos采样率转换 + pos = Config["pos"] * temp_freq // Config["ApplyFrequency"] 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: diff --git a/func/Module_precisely_align.py b/func/Module_precisely_align.py index a47564c..f297148 100644 --- a/func/Module_precisely_align.py +++ b/func/Module_precisely_align.py @@ -1642,10 +1642,10 @@ class Data: orgfs = Config["orgfs"] off = Config["offset_anchor"] - self.res_orgBcg = self.raw_orgBcg - self.res_BCG = self.raw_BCG - self.cut_ECG = self.raw_ECG - self.cut_Rpeak = self.Rpeak + self.res_orgBcg = self.raw_orgBcg.copy() + self.res_BCG = self.raw_BCG.copy() + self.cut_ECG = self.raw_ECG.copy() + self.cut_Rpeak = self.Rpeak.copy() if off > 0: self.cut_ECG = self.cut_ECG[off:] diff --git a/func/utils/ConfigParams.py b/func/utils/ConfigParams.py index c7c34ea..1efb4ca 100644 --- a/func/utils/ConfigParams.py +++ b/func/utils/ConfigParams.py @@ -47,7 +47,7 @@ class ConfigParams: "Multiple_Factor":100, "CorrByEpoch": { - "window_second": 30 + "window_epoch": 6 } } APPROXIMATELY_ALIGN_INPUT_ORGBCG_FILENAME: str = "orgBcg_Raw_"