Merge branch 'master' into cxh_dev
# Conflicts: # func/Module_approximately_align.py
This commit is contained in:
@ -13,8 +13,10 @@ from pandas import read_csv, DataFrame
|
||||
from scipy.signal import find_peaks, resample, butter, sosfiltfilt, correlate
|
||||
from yaml import dump, load, FullLoader
|
||||
from sklearn.linear_model import TheilSenRegressor
|
||||
|
||||
from func.utils.ConfigParams import Filename, Params
|
||||
from func.utils.PublicFunc import PublicFunc
|
||||
from func.utils.Constants import Constants, ConfigParams
|
||||
from func.utils.Constants import Constants
|
||||
from func.utils.Result import Result
|
||||
|
||||
from ui.MainWindow.MainWindow_approximately_align import Ui_MainWindow_approximately_align
|
||||
@ -99,11 +101,11 @@ class SettingWindow(QMainWindow):
|
||||
self.ui.pushButton_cancel.clicked.connect(self.close)
|
||||
|
||||
def __read_config__(self):
|
||||
if not Path(ConfigParams.APPROXIMATELY_ALIGN_CONFIG_FILE_PATH).exists():
|
||||
with open(ConfigParams.APPROXIMATELY_ALIGN_CONFIG_FILE_PATH, "w") as f:
|
||||
dump(ConfigParams.APPROXIMATELY_ALIGN_CONFIG_NEW_CONTENT, f)
|
||||
if not Path(Params.APPROXIMATELY_ALIGN_CONFIG_FILE_PATH).exists():
|
||||
with open(Params.APPROXIMATELY_ALIGN_CONFIG_FILE_PATH, "w") as f:
|
||||
dump(Params.APPROXIMATELY_ALIGN_CONFIG_NEW_CONTENT, f)
|
||||
|
||||
with open(ConfigParams.APPROXIMATELY_ALIGN_CONFIG_FILE_PATH, "r") as f:
|
||||
with open(Params.APPROXIMATELY_ALIGN_CONFIG_FILE_PATH, "r") as f:
|
||||
file_config = load(f.read(), Loader=FullLoader)
|
||||
Config.update(file_config)
|
||||
self.config = file_config
|
||||
@ -112,15 +114,15 @@ class SettingWindow(QMainWindow):
|
||||
|
||||
Config.update({
|
||||
"Path": {
|
||||
"Input_orgBcg": str((Path(self.root_path) / ConfigParams.PUBLIC_PATH_ORGBCG_TEXT /
|
||||
"Input_orgBcg": str((Path(self.root_path) / Filename.PATH_ORGBCG_TEXT /
|
||||
Path(str(self.sampID)))),
|
||||
"Input_Tho": str((Path(self.root_path) / ConfigParams.PUBLIC_PATH_PSG_TEXT /
|
||||
"Input_Tho": str((Path(self.root_path) / Filename.PATH_PSG_TEXT /
|
||||
Path(str(self.sampID)))),
|
||||
"Input_Abd": str((Path(self.root_path) / ConfigParams.PUBLIC_PATH_PSG_TEXT /
|
||||
"Input_Abd": str((Path(self.root_path) / Filename.PATH_PSG_TEXT /
|
||||
Path(str(self.sampID)))),
|
||||
"Save": str((Path(self.root_path) / ConfigParams.PUBLIC_PATH_PSG_TEXT /
|
||||
Path(str(self.sampID)) / Path(ConfigParams.APPROXIMATELY_ALIGN_INFO +
|
||||
ConfigParams.ENDSWITH_CSV)))
|
||||
"Save": str((Path(self.root_path) / Filename.PATH_LABEL /
|
||||
Path(str(self.sampID)) / Path(Filename.APPROXIMATELY_ALIGN_INFO +
|
||||
Params.ENDSWITH_CSV)))
|
||||
},
|
||||
"orgBcgConfig": {},
|
||||
"PSGConfig": {}
|
||||
@ -162,7 +164,7 @@ class SettingWindow(QMainWindow):
|
||||
self.config["Filter"]["BandPassLow"] = self.ui.doubleSpinBox_bandpassLow.value()
|
||||
self.config["Filter"]["BandPassHigh"] = self.ui.doubleSpinBox_bandpassHigh.value()
|
||||
|
||||
with open(ConfigParams.APPROXIMATELY_ALIGN_CONFIG_FILE_PATH, "w") as f:
|
||||
with open(Params.APPROXIMATELY_ALIGN_CONFIG_FILE_PATH, "w") as f:
|
||||
dump(self.config, f)
|
||||
|
||||
self.close()
|
||||
@ -173,31 +175,25 @@ class SettingWindow(QMainWindow):
|
||||
def __update_ui__(self):
|
||||
self.ui.plainTextEdit_file_path_input_orgBcg.setPlainText(
|
||||
str((Path(self.root_path) /
|
||||
ConfigParams.PUBLIC_PATH_ORGBCG_TEXT /
|
||||
Filename.PATH_ORGBCG_TEXT /
|
||||
Path(str(self.sampID)) /
|
||||
Path(ConfigParams.ORGBCG_RAW +
|
||||
Path(Filename.ORGBCG_RAW +
|
||||
str(self.ui.spinBox_input_orgBcg_freq.value()) +
|
||||
ConfigParams.ENDSWITH_TXT))))
|
||||
Params.ENDSWITH_TXT))))
|
||||
self.ui.plainTextEdit_file_path_input_Tho.setPlainText(
|
||||
str((Path(self.root_path) /
|
||||
ConfigParams.PUBLIC_PATH_PSG_TEXT /
|
||||
Filename.PATH_PSG_TEXT /
|
||||
Path(str(self.sampID)) /
|
||||
Path(ConfigParams.THO_RAW +
|
||||
Path(Filename.THO_RAW +
|
||||
str(self.ui.spinBox_input_Tho_freq.value()) +
|
||||
ConfigParams.ENDSWITH_TXT))))
|
||||
Params.ENDSWITH_TXT))))
|
||||
self.ui.plainTextEdit_file_path_input_Abd.setPlainText(
|
||||
str((Path(self.root_path) /
|
||||
ConfigParams.PUBLIC_PATH_PSG_TEXT /
|
||||
Filename.PATH_PSG_TEXT /
|
||||
Path(str(self.sampID)) /
|
||||
Path(ConfigParams.ABD_RAW +
|
||||
Path(Filename.ABD_RAW +
|
||||
str(self.ui.spinBox_input_Abd_freq.value()) +
|
||||
ConfigParams.ENDSWITH_TXT))))
|
||||
self.ui.plainTextEdit_file_path_save.setPlainText(
|
||||
str((Path(self.root_path) /
|
||||
ConfigParams.PUBLIC_PATH_ORGBCG_TEXT /
|
||||
Path(str(self.sampID)) /
|
||||
Path(ConfigParams.APPROXIMATELY_ALIGN_INFO +
|
||||
ConfigParams.ENDSWITH_CSV))))
|
||||
Params.ENDSWITH_TXT))))
|
||||
|
||||
|
||||
class MainWindow_approximately_align(QMainWindow):
|
||||
@ -998,19 +994,19 @@ class Data:
|
||||
if Path(Config["Path"]["Input_Abd"]).is_file():
|
||||
Config["Path"]["Input_Abd"] = str(Path(Config["Path"]["Input_Abd"]).parent)
|
||||
|
||||
result = PublicFunc.examine_file(Config["Path"]["Input_orgBcg"], ConfigParams.ORGBCG_RAW)
|
||||
result = PublicFunc.examine_file(Config["Path"]["Input_orgBcg"], Filename.ORGBCG_RAW, Params.ENDSWITH_TXT)
|
||||
if result.status:
|
||||
Config["Path"]["Input_orgBcg"] = result.data["path"]
|
||||
Config["InputConfig"]["orgBcgFreq"] = result.data["freq"]
|
||||
else:
|
||||
return result
|
||||
result = PublicFunc.examine_file(Config["Path"]["Input_Tho"], ConfigParams.THO_RAW)
|
||||
result = PublicFunc.examine_file(Config["Path"]["Input_Tho"], Filename.THO_RAW, Params.ENDSWITH_TXT)
|
||||
if result.status:
|
||||
Config["Path"]["Input_Tho"] = result.data["path"]
|
||||
Config["InputConfig"]["ThoFreq"] = result.data["freq"]
|
||||
else:
|
||||
return result
|
||||
result = PublicFunc.examine_file(Config["Path"]["Input_Abd"], ConfigParams.ABD_RAW)
|
||||
result = PublicFunc.examine_file(Config["Path"]["Input_Abd"], Filename.ABD_RAW, Params.ENDSWITH_TXT)
|
||||
if result.status:
|
||||
Config["Path"]["Input_Abd"] = result.data["path"]
|
||||
Config["InputConfig"]["AbdFreq"] = result.data["freq"]
|
||||
@ -1019,13 +1015,13 @@ class Data:
|
||||
|
||||
try:
|
||||
self.raw_orgBcg = read_csv(Config["Path"]["Input_orgBcg"],
|
||||
encoding=ConfigParams.UTF8_ENCODING,
|
||||
encoding=Params.UTF8_ENCODING,
|
||||
header=None).to_numpy().reshape(-1)
|
||||
self.raw_Tho = read_csv(Config["Path"]["Input_Tho"],
|
||||
encoding=ConfigParams.UTF8_ENCODING,
|
||||
encoding=Params.UTF8_ENCODING,
|
||||
header=None).to_numpy().reshape(-1)
|
||||
self.raw_Abd = read_csv(Config["Path"]["Input_Abd"],
|
||||
encoding=ConfigParams.UTF8_ENCODING,
|
||||
encoding=Params.UTF8_ENCODING,
|
||||
header=None).to_numpy().reshape(-1)
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.INPUT_FAILURE + Constants.FAILURE_REASON[
|
||||
@ -1034,8 +1030,6 @@ class Data:
|
||||
return Result().success(info=Constants.INPUT_FINISHED)
|
||||
|
||||
def save(self, epoch):
|
||||
if (not Path(Config["Path"]["Save"]).parent.exists()) or (not Path(Config["Path"]["Save"]).parent.is_dir()):
|
||||
Path(Config["Path"]["Save"]).parent.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
pos = Config["pos"]
|
||||
ApplyFrequency = Config["ApplyFrequency"]
|
||||
@ -1120,10 +1114,7 @@ class Data:
|
||||
def Standardize_2(self):
|
||||
# 预重采样
|
||||
try:
|
||||
# TODO:这里的采样率处理,如果THO和ABD的采样率不同,可能还是会导致之后的ApplyFrequency出问题,最后导致得到的粗同步坐标不正确
|
||||
#
|
||||
if Config["InputConfig"]["ThoFreq"] != Config["TempFrequency"]:
|
||||
print(int(Config["InputConfig"]["ThoFreq"]), int(Config["TempFrequency"]))
|
||||
self.processed_Tho = resample(self.processed_Tho,
|
||||
int(Config["PSG_seconds"] * Config["TempFrequency"]))
|
||||
|
||||
@ -1198,7 +1189,7 @@ class Data:
|
||||
# 计算互相关1/2
|
||||
try:
|
||||
# 计算因子
|
||||
MULTIPLE_FACTOER = ConfigParams.APPROXIMATELY_ALIGN_CONFIG_NEW_CONTENT["Multiple_Factor"]
|
||||
MULTIPLE_FACTOER = Params.APPROXIMATELY_ALIGN_CONFIG_NEW_CONTENT["Multiple_Factor"]
|
||||
a = self.processed_downsample_Tho[
|
||||
Config["PSGConfig"]["PreCut"]:len(self.processed_downsample_Tho) - Config["PSGConfig"][
|
||||
"PostCut"]].copy()
|
||||
@ -1293,8 +1284,8 @@ class Data:
|
||||
epoch_max = response.data["epoch_max"]
|
||||
epoch_second = ConfigParams.APPROXIMATELY_ALIGN_CONFIG_NEW_CONTENT["Second_PerEpoch"]
|
||||
|
||||
temp_freq = ConfigParams.APPROXIMATELY_ALIGN_CONFIG_NEW_CONTENT["TempFrequency"]
|
||||
window_epoch = ConfigParams.APPROXIMATELY_ALIGN_CONFIG_NEW_CONTENT["CorrByEpoch"]["window_epoch"]
|
||||
temp_freq = Params.APPROXIMATELY_ALIGN_CONFIG_NEW_CONTENT["TempFrequency"]
|
||||
window_epoch = Params.APPROXIMATELY_ALIGN_CONFIG_NEW_CONTENT["CorrByEpoch"]["window_epoch"]
|
||||
tho_bias_list = []
|
||||
abd_bias_list = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user