优化了<数据精同步>的部分代码结构

This commit is contained in:
Yorusora
2025-06-13 23:11:06 +08:00
parent 170926ddd0
commit bf0c780f01

View File

@ -1949,50 +1949,45 @@ class Data:
def correlation_align(self, mode): def correlation_align(self, mode):
try: try:
if mode == "init": if mode == "init":
anchor0 = [Config["front"]["anchor_R"], Config["front"]["anchor_J"]] Config["orgfs"] = ((int(Config["back"]["anchor_J"]) - int(Config["front"]["anchor_J"])) * Config["InputConfig"]["UseFreq"] /
anchor1 = [Config["back"]["anchor_R"], Config["back"]["anchor_J"]] (int(Config["back"]["anchor_R"]) - int(Config["front"]["anchor_R"])))
Config["orgfs"] = ((int(anchor1[1]) - int(anchor0[1])) * Config["InputConfig"]["UseFreq"] / Config["offset_anchor"] = Config["front"]["anchor_R"] - Config["front"]["anchor_J"]
(int(anchor1[0]) - int(anchor0[0])))
Config["offset_anchor"] = anchor0[0] - anchor0[1]
orgfs = Config["orgfs"]
off = Config["offset_anchor"]
self.res_orgBcg = self.raw_orgBcg.copy() self.res_orgBcg = self.raw_orgBcg.copy()
self.res_BCG = self.raw_BCG.copy() self.res_BCG = self.raw_BCG.copy()
self.cut_ECG = self.raw_ECG.copy() self.cut_ECG = self.raw_ECG.copy()
self.cut_Rpeak = self.Rpeak.copy() self.cut_Rpeak = self.Rpeak.copy()
if off > 0: if Config["offset_anchor"] > 0:
self.cut_ECG = self.cut_ECG[off:] self.cut_ECG = self.cut_ECG[Config["offset_anchor"]:]
anchor0[0] = anchor0[0] - off Config["front"]["anchor_R"] = Config["front"]["anchor_R"] - Config["offset_anchor"]
anchor1[0] = anchor1[0] - off Config["back"]["anchor_R"] = Config["back"]["anchor_R"] - Config["offset_anchor"]
idxs = where(self.cut_Rpeak > off)[0] idxs = where(self.cut_Rpeak > Config["offset_anchor"])[0]
self.cut_Rpeak = self.cut_Rpeak[idxs] - off self.cut_Rpeak = self.cut_Rpeak[idxs] - Config["offset_anchor"]
else: else:
self.res_BCG = self.res_BCG[-off:] self.res_BCG = self.res_BCG[-Config["offset_anchor"]:]
self.res_orgBcg = self.res_orgBcg[-off:] self.res_orgBcg = self.res_orgBcg[-Config["offset_anchor"]:]
anchor0[1] = anchor0[1] + off Config["front"]["anchor_J"] = Config["front"]["anchor_J"] + Config["offset_anchor"]
anchor1[1] = anchor1[1] + off Config["back"]["anchor_J"] = Config["back"]["anchor_J"] + Config["offset_anchor"]
self.res_BCG = resample(self.res_BCG, orgfs, Config["InputConfig"]["UseFreq"]) self.res_BCG = resample(self.res_BCG, Config["orgfs"], Config["InputConfig"]["UseFreq"])
self.res_orgBcg = resample(self.res_orgBcg, orgfs, Config["InputConfig"]["UseFreq"]) self.res_orgBcg = resample(self.res_orgBcg, Config["orgfs"], Config["InputConfig"]["UseFreq"])
anchor0[1] = round(int(anchor0[1]) * Config["InputConfig"]["UseFreq"] / orgfs) Config["front"]["anchor_J"] = round(int(Config["front"]["anchor_J"]) * Config["InputConfig"]["UseFreq"] / Config["orgfs"])
anchor1[1] = round(int(anchor1[1]) * Config["InputConfig"]["UseFreq"] / orgfs) Config["back"]["anchor_J"] = round(int(Config["back"]["anchor_J"]) * Config["InputConfig"]["UseFreq"] / Config["orgfs"])
off = anchor1[0] - anchor1[1] Config["offset_anchor"] = Config["back"]["anchor_R"] - Config["back"]["anchor_J"]
if off > 0: if Config["offset_anchor"] > 0:
self.cut_ECG = self.cut_ECG[off:] self.cut_ECG = self.cut_ECG[Config["offset_anchor"]:]
anchor0[0] = anchor0[0] - off Config["front"]["anchor_R"] = Config["front"]["anchor_R"] - Config["offset_anchor"]
anchor1[0] = anchor1[0] - off Config["back"]["anchor_R"] = Config["back"]["anchor_R"] - Config["offset_anchor"]
idxs = where(self.cut_Rpeak > off)[0] idxs = where(self.cut_Rpeak > Config["offset_anchor"])[0]
self.cut_Rpeak = self.cut_Rpeak[idxs] - off self.cut_Rpeak = self.cut_Rpeak[idxs] - Config["offset_anchor"]
else: else:
self.res_BCG = self.res_BCG[-off:] self.res_BCG = self.res_BCG[-Config["offset_anchor"]:]
self.res_orgBcg = self.res_orgBcg[-off:] self.res_orgBcg = self.res_orgBcg[-Config["offset_anchor"]:]
anchor0[1] = anchor0[1] + off Config["front"]["anchor_J"] = Config["front"]["anchor_J"] + Config["offset_anchor"]
anchor1[1] = anchor1[1] + off Config["back"]["anchor_J"] = Config["back"]["anchor_J"] + Config["offset_anchor"]
datalen = np_min([len(self.cut_ECG), len(self.res_BCG)]) datalen = np_min([len(self.cut_ECG), len(self.res_BCG)])
self.cut_ECG = self.cut_ECG[:datalen] self.cut_ECG = self.cut_ECG[:datalen]
@ -2009,8 +2004,8 @@ class Data:
result = { result = {
"res_BCG": self.res_BCG, "res_BCG": self.res_BCG,
"cut_ECG": self.cut_ECG, "cut_ECG": self.cut_ECG,
"anchor00": anchor0[0], "anchor00": Config["front"]["anchor_R"],
"anchor10": anchor1[0], "anchor10": Config["back"]["anchor_R"],
"a": a, "a": a,
"b": b, "b": b,
"peak_ECG": peak_ECG, "peak_ECG": peak_ECG,
@ -2034,27 +2029,24 @@ class Data:
def data_postprocess(self): def data_postprocess(self):
try: try:
if len(self.correlation_align_point_match_ECG) != 2 and len(self.correlation_align_point_match_BCG) != 2: if len(self.correlation_align_point_match_ECG) != 2 and len(self.correlation_align_point_match_BCG) != 2:
off = 0 Config["offset_anchor"] = 0
else: else:
self.correlation_align_point_match_ECG.sort() self.correlation_align_point_match_ECG.sort()
self.correlation_align_point_match_BCG.sort() self.correlation_align_point_match_BCG.sort()
off = round(((int(self.correlation_align_point_match_ECG[1]) - int( Config["offset_anchor"] = round(((int(self.correlation_align_point_match_ECG[1]) - int(
self.correlation_align_point_match_BCG[1])) + (int(self.correlation_align_point_match_ECG[0]) - int( self.correlation_align_point_match_BCG[1])) + (int(self.correlation_align_point_match_ECG[0]) - int(
self.correlation_align_point_match_BCG[0]))) / 2) self.correlation_align_point_match_BCG[0]))) / 2)
anchor0 = [Config["front"]["anchor_R"], Config["front"]["anchor_J"]] if Config["offset_anchor"] > 0:
anchor1 = [Config["back"]["anchor_R"], Config["back"]["anchor_J"]] self.cut_ECG = self.cut_ECG[Config["offset_anchor"]:]
Config["front"]["anchor_R"] = Config["front"]["anchor_R"] - Config["offset_anchor"]
if off > 0: Config["back"]["anchor_R"] = Config["back"]["anchor_R"] - Config["offset_anchor"]
self.cut_ECG = self.cut_ECG[off:] self.cut_Rpeak = self.cut_Rpeak[where(self.cut_Rpeak > Config["offset_anchor"])[0]] - Config["offset_anchor"]
anchor0[0] = anchor0[0] - off
anchor1[0] = anchor1[0] - off
self.cut_Rpeak = self.cut_Rpeak[where(self.cut_Rpeak > off)[0]] - off
else: else:
self.res_BCG = self.res_BCG[-off:] self.res_BCG = self.res_BCG[-Config["offset_anchor"]:]
self.res_orgBcg = self.res_orgBcg[-off:] self.res_orgBcg = self.res_orgBcg[-Config["offset_anchor"]:]
anchor0[1] = anchor0[1] + off Config["front"]["anchor_J"] = Config["front"]["anchor_J"] + Config["offset_anchor"]
anchor1[1] = anchor1[1] + off Config["back"]["anchor_J"] = Config["back"]["anchor_J"] + Config["offset_anchor"]
datalen = np_min([len(self.cut_ECG), len(self.res_BCG)]) datalen = np_min([len(self.cut_ECG), len(self.res_BCG)])
self.cut_ECG = self.cut_ECG[:datalen] self.cut_ECG = self.cut_ECG[:datalen]
@ -2064,8 +2056,6 @@ class Data:
idxs = where(self.cut_Rpeak < datalen)[0] idxs = where(self.cut_Rpeak < datalen)[0]
self.cut_Rpeak = self.cut_Rpeak[idxs] self.cut_Rpeak = self.cut_Rpeak[idxs]
Config["offset_correct"] = off
self.cut_Jpeak = [] self.cut_Jpeak = []
peaks, _ = find_peaks(self.res_BCG) peaks, _ = find_peaks(self.res_BCG)
for i in self.cut_Rpeak: for i in self.cut_Rpeak:
@ -2081,6 +2071,21 @@ class Data:
frontcut_index_ECG = self.argmax_ECG - np_argmax(self.cut_ECG) 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) 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["frontcut_index_BCG"] = frontcut_index_BCG
Config["backcut_index_BCG"] = backcut_index_BCG Config["backcut_index_BCG"] = backcut_index_BCG
Config["frontcut_index_ECG"] = frontcut_index_ECG Config["frontcut_index_ECG"] = frontcut_index_ECG