From dab7bf19347f1ec4e88d0f7e599fa50040ff0964 Mon Sep 17 00:00:00 2001 From: marques <20172333133@m.scnu.edu.cn> Date: Wed, 14 May 2025 21:27:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9B=B8=E5=85=B3=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E6=96=B9=E6=B3=95=EF=BC=8C=E6=8B=86=E5=88=86=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- func/Module_approximately_align.py | 55 ++++++++++++------------------ func/utils/ConfigParams.py | 3 +- 2 files changed, 23 insertions(+), 35 deletions(-) diff --git a/func/Module_approximately_align.py b/func/Module_approximately_align.py index 47fae83..8ab27e3 100644 --- a/func/Module_approximately_align.py +++ b/func/Module_approximately_align.py @@ -7,12 +7,11 @@ from PySide6.QtWidgets import QMessageBox, QMainWindow, QApplication from matplotlib.backends.backend_qt import NavigationToolbar2QT from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg as FigureCanvas from matplotlib.figure import Figure -from numba import prange, njit from numpy import repeat, convolve, ones, mean, std, empty, int64, sum as np_sum, pad, zeros, array, argmax, linspace, \ diff from overrides import overrides from pandas import read_csv, DataFrame -from scipy.signal import find_peaks, resample, butter, sosfiltfilt +from scipy.signal import find_peaks, resample, butter, sosfiltfilt, correlate from yaml import dump, load, FullLoader from func.utils.PublicFunc import PublicFunc @@ -856,10 +855,19 @@ class Data: self.processed_Abd = None def open_file(self): - if ((not Path(Config["Path"]["Input_orgBcg"]).exists()) - or (not Path(Config["Path"]["Input_Tho"]).exists()) - or (not Path(Config["Path"]["Input_Abd"]).exists())): - return Result().failure(info=Constants.INPUT_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Data_Path_Not_Exist"]) + + if not Path(Config["Path"]["Input_orgBcg"]).exists(): + return Result().failure( + info=Constants.INPUT_FAILURE + "orgBcg: " + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON[ + "Data_Path_Not_Exist"]) + if not Path(Config["Path"]["Input_Tho"]).exists(): + return Result().failure( + info=Constants.INPUT_FAILURE + "Tho: " + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON[ + "Data_Path_Not_Exist"]) + if not Path(Config["Path"]["Input_Abd"]).exists(): + return Result().failure( + info=Constants.INPUT_FAILURE + "Abd: " + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON[ + "Data_Path_Not_Exist"]) try: self.raw_orgBcg = read_csv(Config["Path"]["Input_orgBcg"], @@ -1008,20 +1016,16 @@ class Data: def calculate_correlation1(self): # 计算互相关1/2 try: + # 计算因子 + MULTIPLE_FACTOER = ConfigParams.APPROXIMATELY_ALIGN_CONFIG_NEW_CONTENT["Multiple_Factor"] a = self.processed_Tho[Config["PSGConfig"]["PreCut"]:len(self.processed_Tho) - Config["PSGConfig"]["PostCut"]].copy() v = self.processed_orgBcg[Config["orgBcgConfig"]["PreCut"]:len(self.processed_orgBcg) - Config["orgBcgConfig"]["PostCut"]].copy() - a *= 100 - v *= 100 + a *= MULTIPLE_FACTOER + v *= MULTIPLE_FACTOER a = a.astype(int64) v = v.astype(int64) - a = pad(a, (len(v) - 1, len(v) - 1), mode='constant') - tho_relate = zeros(len(a) - len(v) - 1, dtype=int64) - len_calc = len(a) - len(v) - 1 - # 将序列分成一百份来计算 - for i in range(100): - tho_relate[i * len_calc // 100:(i + 1) * len_calc // 100] = Data.get_Correlate(a, v, array( - [i * len_calc // 100, (i + 1) * len_calc // 100], dtype=int64)) - tho_relate = tho_relate / 10000 + tho_relate = correlate(a, v, mode='full') + tho_relate = tho_relate / (MULTIPLE_FACTOER ** 2) tho_relate2 = - tho_relate result = {"tho_relate": tho_relate, "tho_relate2": tho_relate2} @@ -1039,14 +1043,7 @@ class Data: v *= 100 a = a.astype(int64) v = v.astype(int64) - a = pad(a, (len(v) - 1, len(v) - 1), mode='constant') - - abd_relate = zeros(len(a) - len(v) - 1, dtype=int64) - len_calc = len(a) - len(v) - 1 - # 将序列分成一百份来计算 - for i in range(100): - abd_relate[i * len_calc // 100:(i + 1) * len_calc // 100] = Data.get_Correlate(a, v, array( - [i * len_calc // 100, (i + 1) * len_calc // 100], dtype=int64)) + abd_relate = correlate(a, v, mode='full') abd_relate = abd_relate / 10000 abd_relate2 = - abd_relate @@ -1086,13 +1083,3 @@ class Data: return Result().success(info=Constants.APPROXIMATELY_EPOCH_GET_FINISHED, data=result) - @staticmethod - @njit("int64[:](int64[:],int64[:], int64[:])", nogil=True, parallel=True) - def get_Correlate(a, v, between): - begin, end = between - if end == 0: - end = len(a) - len(v) - 1 - result = empty(end - begin, dtype=int64) - for i in prange(end - begin): - result[i] = np_sum(a[begin + i: begin + i + len(v)] * v) - return result \ No newline at end of file diff --git a/func/utils/ConfigParams.py b/func/utils/ConfigParams.py index 80c554d..1f607e5 100644 --- a/func/utils/ConfigParams.py +++ b/func/utils/ConfigParams.py @@ -42,7 +42,8 @@ class ConfigParams: "BandPassOrder": 4, "BandPassLow": 0.01, "BandPassHigh": 0.7 - } + }, + "Multiple_Factor":100 } APPROXIMATELY_ALIGN_INPUT_ORGBCG_FILENAME: str = "orgBcg_Raw_" APPROXIMATELY_ALIGN_INPUT_THO_FILENAME: str = "Effort Tho_Raw_"