更新相关计算方法,拆分错误提示
This commit is contained in:
@ -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
|
||||
Reference in New Issue
Block a user