From 4ef5463b1a265d4b0e3128d3d8992b95578bfd39 Mon Sep 17 00:00:00 2001 From: Yorusora <2023025086@m.scnu.edu.cn> Date: Sat, 14 Jun 2025 19:32:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86<=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=B2=BE=E5=90=8C=E6=AD=A5>=E4=B8=AD=E5=88=87=E5=89=B2?= =?UTF-8?q?=E7=B4=A2=E5=BC=95=E5=8F=AF=E8=83=BD=E5=AD=98=E5=9C=A8=E8=B4=9F?= =?UTF-8?q?=E5=80=BC=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- func/Module_precisely_align.py | 54 ++++++++++++++-------------------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/func/Module_precisely_align.py b/func/Module_precisely_align.py index bb92f13..d82d462 100644 --- a/func/Module_precisely_align.py +++ b/func/Module_precisely_align.py @@ -1645,9 +1645,6 @@ class Data: self.correlation_align_point_match_ECG = array([]).astype(int) self.correlation_align_point_match_BCG = array([]).astype(int) - self.argmax_BCG = None - self.argmax_ECG = None - def open_file(self): if Path(Config["Path"]["Input_OrgBCG"]).is_file(): Config["Path"]["Input_OrgBCG"] = str(Path(Config["Path"]["Input_OrgBCG"]).parent) @@ -1740,8 +1737,6 @@ class Data: self.Rpeak = read_csv(Config["Path"]["Input_Rpeak"], encoding=Params.UTF8_ENCODING, header=None).to_numpy().reshape(-1) - self.argmax_BCG = np_argmax(self.raw_BCG) - self.argmax_ECG = np_argmax(self.raw_ECG) except Exception as e: return Result().failure(info=Constants.INPUT_FAILURE + Constants.FAILURE_REASON["Open_Data_Exception"] + "\n" + format_exc()) @@ -1958,17 +1953,21 @@ class Data: self.cut_ECG = self.raw_ECG.copy() self.cut_Rpeak = self.Rpeak.copy() + Config["frontcut_index_BCG"], Config["frontcut_index_ECG"] = 0, 0 + if Config["offset_anchor"] > 0: self.cut_ECG = self.cut_ECG[Config["offset_anchor"]:] Config["front"]["anchor_R"] = Config["front"]["anchor_R"] - Config["offset_anchor"] Config["back"]["anchor_R"] = Config["back"]["anchor_R"] - Config["offset_anchor"] idxs = where(self.cut_Rpeak > Config["offset_anchor"])[0] self.cut_Rpeak = self.cut_Rpeak[idxs] - Config["offset_anchor"] + Config["frontcut_index_ECG"] += Config["offset_anchor"] else: self.res_BCG = self.res_BCG[-Config["offset_anchor"]:] self.res_orgBcg = self.res_orgBcg[-Config["offset_anchor"]:] Config["front"]["anchor_J"] = Config["front"]["anchor_J"] + Config["offset_anchor"] Config["back"]["anchor_J"] = Config["back"]["anchor_J"] + Config["offset_anchor"] + Config["frontcut_index_BCG"] -= Config["offset_anchor"] self.res_BCG = resample(self.res_BCG, Config["orgfs"], Config["InputConfig"]["UseFreq"]) self.res_orgBcg = resample(self.res_orgBcg, Config["orgfs"], Config["InputConfig"]["UseFreq"]) @@ -1983,16 +1982,25 @@ class Data: Config["back"]["anchor_R"] = Config["back"]["anchor_R"] - Config["offset_anchor"] idxs = where(self.cut_Rpeak > Config["offset_anchor"])[0] self.cut_Rpeak = self.cut_Rpeak[idxs] - Config["offset_anchor"] + Config["frontcut_index_ECG"] += Config["offset_anchor"] * Config["orgfs"] / Config["InputConfig"]["UseFreq"] else: self.res_BCG = self.res_BCG[-Config["offset_anchor"]:] self.res_orgBcg = self.res_orgBcg[-Config["offset_anchor"]:] Config["front"]["anchor_J"] = Config["front"]["anchor_J"] + Config["offset_anchor"] Config["back"]["anchor_J"] = Config["back"]["anchor_J"] + Config["offset_anchor"] + Config["frontcut_index_BCG"] -= Config["offset_anchor"] * Config["orgfs"] / Config["InputConfig"]["UseFreq"] datalen = np_min([len(self.cut_ECG), len(self.res_BCG)]) self.cut_ECG = self.cut_ECG[:datalen] self.res_BCG = self.res_BCG[:datalen] self.res_orgBcg = self.res_orgBcg[:datalen] + + Config["frontcut_index_BCG"] = int(Config["frontcut_index_BCG"]) + Config["frontcut_index_ECG"] = int(Config["frontcut_index_ECG"]) + + Config["backcut_index_BCG"] = int(Config["frontcut_index_BCG"] + datalen) + Config["backcut_index_ECG"] = int(Config["frontcut_index_ECG"] + datalen) + a = np_max([np_max(self.cut_ECG), np_max(self.res_BCG)]) b = np_min([np_min(self.cut_ECG), np_min(self.res_BCG)]) peak_ECG, _ = find_peaks(self.cut_ECG) @@ -2042,17 +2050,25 @@ class Data: Config["front"]["anchor_R"] = Config["front"]["anchor_R"] - Config["offset_anchor"] Config["back"]["anchor_R"] = Config["back"]["anchor_R"] - Config["offset_anchor"] self.cut_Rpeak = self.cut_Rpeak[where(self.cut_Rpeak > Config["offset_anchor"])[0]] - Config["offset_anchor"] + Config["frontcut_index_ECG"] += Config["offset_anchor"] * Config["orgfs"] / Config["InputConfig"]["UseFreq"] else: self.res_BCG = self.res_BCG[-Config["offset_anchor"]:] self.res_orgBcg = self.res_orgBcg[-Config["offset_anchor"]:] Config["front"]["anchor_J"] = Config["front"]["anchor_J"] + Config["offset_anchor"] Config["back"]["anchor_J"] = Config["back"]["anchor_J"] + Config["offset_anchor"] + Config["frontcut_index_BCG"] -= Config["offset_anchor"] * Config["orgfs"] / Config["InputConfig"]["UseFreq"] datalen = np_min([len(self.cut_ECG), len(self.res_BCG)]) self.cut_ECG = self.cut_ECG[:datalen] self.res_BCG = self.res_BCG[:datalen] self.res_orgBcg = self.res_orgBcg[:datalen] + Config["frontcut_index_BCG"] = int(Config["frontcut_index_BCG"]) + Config["frontcut_index_ECG"] = int(Config["frontcut_index_ECG"]) + + Config["backcut_index_BCG"] = int(Config["frontcut_index_BCG"] + datalen) + Config["backcut_index_ECG"] = int(Config["frontcut_index_ECG"] + datalen) + idxs = where(self.cut_Rpeak < datalen)[0] self.cut_Rpeak = self.cut_Rpeak[idxs] @@ -2064,37 +2080,11 @@ class Data: self.cut_Jpeak.append(peaks[idx]) self.cut_Jpeak = asarray(self.cut_Jpeak).astype(int) - frontcut_index_BCG = int( - (self.argmax_BCG - np_argmax(self.res_BCG) / Config["InputConfig"]["UseFreq"] * Config["orgfs"])) - backcut_index_BCG = int(len(self.res_BCG) / Config["InputConfig"]["UseFreq"] * Config["orgfs"] + np_argmax( - self.raw_BCG) - np_argmax(self.res_BCG) / Config["InputConfig"]["UseFreq"] * Config["orgfs"]) - frontcut_index_ECG = self.argmax_ECG - np_argmax(self.cut_ECG) - backcut_index_ECG = len(self.cut_ECG) + self.argmax_ECG - np_argmax(self.cut_ECG) - - print("修正前的值:front_BCG:{}, back_BCG:{}, front_ECG:{}, back_ECG:{}".format(frontcut_index_BCG, - backcut_index_BCG, - frontcut_index_ECG, - backcut_index_ECG)) - if frontcut_index_BCG < 0: - backcut_index_BCG = np_abs(frontcut_index_BCG) + backcut_index_BCG - frontcut_index_BCG = 0 - if frontcut_index_ECG < 0: - backcut_index_ECG = np_abs(frontcut_index_ECG) + backcut_index_ECG - frontcut_index_ECG = 0 - print("修正后的值:front_BCG:{}, back_BCG:{}, front_ECG:{}, back_ECG:{}".format(frontcut_index_BCG, - backcut_index_BCG, - frontcut_index_ECG, - backcut_index_ECG)) - - Config["frontcut_index_BCG"] = frontcut_index_BCG - Config["backcut_index_BCG"] = backcut_index_BCG - Config["frontcut_index_ECG"] = frontcut_index_ECG - Config["backcut_index_ECG"] = backcut_index_ECG except Exception as e: return Result().failure(info=Constants.PRECISELY_ALIGN_POSTPROCESS_VIEW_FAILURE + Constants.FAILURE_REASON["PostProcess_Align_Exception"] + "\n" + format_exc()) - info = f"{Constants.PRECISELY_ALIGN_POSTPROCESS_VIEW_FINISHED},BCG前后段被切割的坐标值为[{frontcut_index_BCG}, {backcut_index_BCG}],ECG前后段被切割的坐标值为[{frontcut_index_ECG}, {backcut_index_ECG}]" + info = f"{Constants.PRECISELY_ALIGN_POSTPROCESS_VIEW_FINISHED},BCG前后段被切割的坐标值为[{Config['frontcut_index_BCG']}, {Config['backcut_index_BCG']}],ECG前后段被切割的坐标值为[{Config['frontcut_index_ECG']}, {Config['backcut_index_ECG']}]" return Result().success(info=info) def save_alignInfo(self):