将<人工纠正>和<呼吸可用性及间期标注>的左键寻峰增加峰值修改为了通过有上限下限的矩形来获取峰值坐标

This commit is contained in:
Yorusora
2025-06-10 12:07:11 +08:00
parent 422030442c
commit 953136c9c5
3 changed files with 87 additions and 15 deletions

View File

@ -7,7 +7,7 @@
每个功能运行时,若./Config目录下不存在该功能对应的yaml配置文件则程序将创建一份默认的配置文件。配置文件的内容主要涉及一些对应功能的界面默认初始值的设置此配置文件可以根据用户需要自行修改或是在修改了相应参数后在导入设置界面中单击“确定”即可保存相关参数到yaml文件中。
## TODO LIST
1、根据选定区域获取峰值时将绘制的区域设置为有上限和下限的矩形根据矩形获取到的横纵区域来计算峰值
~~1、根据选定区域获取峰值时将绘制的区域设置为有上限和下限的矩形根据矩形获取到的横纵区域来计算峰值~~
~~2、体动选取区域的判别尚未做的很完整选中多个已有的体动的区域时可能会出现问题~~

View File

@ -758,6 +758,7 @@ class MainWindow_label_check(QMainWindow):
elif event.button == 3:
self.is_right_button_pressed = True
self.figToolbar.rect_start_x = event.xdata
self.figToolbar.rect_start_y = event.ydata
# 如果矩形patch已存在先移除
if self.figToolbar.rect_patch_ax0 is not None and self.figToolbar.rect_patch_ax1 is not None:
self.figToolbar.rect_patch_ax0.remove()
@ -768,9 +769,11 @@ class MainWindow_label_check(QMainWindow):
def on_release(self, event):
if self.figToolbar.action_Label_Multiple.isChecked():
if self.figToolbar.rect_start_x is not None:
if self.figToolbar.rect_start_x is not None and self.figToolbar.rect_start_y is not None:
self.figToolbar.rect_end_x = event.xdata
if self.figToolbar.rect_start_x is not None and self.figToolbar.rect_end_x is not None:
self.figToolbar.rect_end_y = event.ydata
if ((self.figToolbar.rect_start_x is not None and self.figToolbar.rect_end_x is not None) and
(self.figToolbar.rect_start_y is not None and self.figToolbar.rect_end_y is not None)):
if self.figToolbar.rect_start_x < self.figToolbar.rect_end_x:
rect_left = self.figToolbar.rect_start_x
rect_right = self.figToolbar.rect_end_x
@ -780,9 +783,20 @@ class MainWindow_label_check(QMainWindow):
else:
rect_left = self.figToolbar.rect_start_x
rect_right = self.figToolbar.rect_start_x
if self.figToolbar.rect_start_y < self.figToolbar.rect_end_y:
rect_bottom = self.figToolbar.rect_start_y
rect_top = self.figToolbar.rect_end_y
elif self.figToolbar.rect_start_y > self.figToolbar.rect_end_y:
rect_bottom = self.figToolbar.rect_end_y
rect_top = self.figToolbar.rect_start_y
else:
rect_bottom = self.figToolbar.rect_start_y
rect_top = self.figToolbar.rect_start_y
else:
rect_left = self.figToolbar.rect_start_x
rect_right = self.figToolbar.rect_start_x
rect_bottom = self.figToolbar.rect_start_y
rect_top = self.figToolbar.rect_start_y
if event.button == 1 and self.is_left_button_pressed:
self.is_left_button_pressed = False
if rect_left < 0:
@ -796,6 +810,13 @@ class MainWindow_label_check(QMainWindow):
rect_left = 0
rect_right = 0
selected_area_for_add_points = self.data.processed_data[int(rect_left):int(rect_right)]
# 找到子列表的最小值
min_value = min(selected_area_for_add_points)
# 遍历子列表,将不满足条件的元素替换为最小值
selected_area_for_add_points = [
y if rect_bottom < y < rect_top else min_value
for y in selected_area_for_add_points
]
peaks_idx, _ = find_peaks(selected_area_for_add_points,
height=Config["FindPeaks"]["MinHeight"],
distance=Config["FindPeaks"]["MinInterval"])
@ -827,6 +848,8 @@ class MainWindow_label_check(QMainWindow):
self.__redraw_peaks__()
self.figToolbar.rect_start_x = None
self.figToolbar.rect_end_x = None
self.figToolbar.rect_start_y = None
self.figToolbar.rect_end_y = None
self.data.corrected_peak.sort()
self.data.corrected_peak_y = [self.data.processed_data[x] for x in self.data.corrected_peak]
self.__update_tableWidget_and_info__()
@ -850,6 +873,8 @@ class MainWindow_label_check(QMainWindow):
def on_hold(self, event):
if self.figToolbar.rect_start_x is not None and event.xdata is not None:
self.figToolbar.rect_end_x = event.xdata
if self.figToolbar.rect_start_y is not None and event.ydata is not None:
self.figToolbar.rect_end_y = event.ydata
# 如果矩形patch不存在则创建一个新的
if self.figToolbar.rect_patch_ax0 is None:
@ -878,14 +903,24 @@ class MainWindow_label_check(QMainWindow):
# 更新矩形patch的位置和大小
x_start = self.figToolbar.rect_start_x
x_end = self.figToolbar.rect_end_x
rect_down = min(self.ax0.get_ylim()[0], self.ax1.get_ylim()[0]) - 1000
rect_up = max(self.ax0.get_ylim()[1], self.ax1.get_ylim()[1]) + 1000
self.figToolbar.rect_patch_ax0.set_xy((min(x_start, x_end), rect_down))
if self.is_left_button_pressed:
y_start = self.figToolbar.rect_start_y
y_end = self.figToolbar.rect_end_y
self.figToolbar.rect_patch_ax0.set_xy((min(x_start, x_end), min(y_start, y_end)))
self.figToolbar.rect_patch_ax0.set_height(abs(y_end - y_start))
self.figToolbar.rect_patch_ax1.set_xy((min(x_start, x_end), min(y_start, y_end)))
self.figToolbar.rect_patch_ax1.set_height(abs(y_end - y_start))
elif self.is_right_button_pressed:
y_start = min(self.ax0.get_ylim()[0], self.ax1.get_ylim()[0]) - 1000
y_end = max(self.ax0.get_ylim()[1], self.ax1.get_ylim()[1]) + 1000
self.figToolbar.rect_patch_ax0.set_xy((min(x_start, x_end), y_start))
self.figToolbar.rect_patch_ax0.set_height(abs(y_end - y_start))
self.figToolbar.rect_patch_ax1.set_xy((min(x_start, x_end), y_start))
self.figToolbar.rect_patch_ax1.set_height(abs(y_end - y_start))
self.figToolbar.rect_patch_ax0.set_width(abs(x_end - x_start))
self.figToolbar.rect_patch_ax0.set_height(rect_up - rect_down)
self.figToolbar.rect_patch_ax1.set_xy((min(x_start, x_end), rect_down))
self.figToolbar.rect_patch_ax1.set_width(abs(x_end - x_start))
self.figToolbar.rect_patch_ax1.set_height(rect_up - rect_down)
self.canvas.draw()
@ -1071,6 +1106,8 @@ class CustomNavigationToolbar(NavigationToolbar2QT):
# 初始化矩形选择区域
self.rect_start_x = None
self.rect_end_x = None
self.rect_start_y = None
self.rect_end_y = None
self.rect_patch_ax0 = None # 用于绘制矩形的patch
self.rect_patch_ax1 = None # 用于绘制矩形的patch

View File

@ -1166,6 +1166,7 @@ class MainWindow_resp_quality_label(QMainWindow):
elif event.button == 3:
self.is_right_button_pressed = True
self.figToolbar.rect_start_x = event.xdata
self.figToolbar.rect_start_y = event.ydata
# 如果矩形patch已存在先移除
if self.figToolbar.rect_patch_ax1 is not None:
self.figToolbar.rect_patch_ax1.remove()
@ -1174,9 +1175,11 @@ class MainWindow_resp_quality_label(QMainWindow):
def on_release(self, event):
if self.figToolbar.action_Label_Multiple.isChecked():
if self.figToolbar.rect_start_x is not None:
if self.figToolbar.rect_start_x is not None and self.figToolbar.rect_start_y is not None:
self.figToolbar.rect_end_x = event.xdata
if self.figToolbar.rect_start_x is not None and self.figToolbar.rect_end_x is not None:
self.figToolbar.rect_end_y = event.ydata
if ((self.figToolbar.rect_start_x is not None and self.figToolbar.rect_end_x is not None) and
(self.figToolbar.rect_start_y is not None and self.figToolbar.rect_end_y is not None)):
if self.figToolbar.rect_start_x < self.figToolbar.rect_end_x:
rect_left = self.figToolbar.rect_start_x
rect_right = self.figToolbar.rect_end_x
@ -1186,9 +1189,20 @@ class MainWindow_resp_quality_label(QMainWindow):
else:
rect_left = self.figToolbar.rect_start_x
rect_right = self.figToolbar.rect_start_x
if self.figToolbar.rect_start_y < self.figToolbar.rect_end_y:
rect_bottom = self.figToolbar.rect_start_y
rect_top = self.figToolbar.rect_end_y
elif self.figToolbar.rect_start_y > self.figToolbar.rect_end_y:
rect_bottom = self.figToolbar.rect_end_y
rect_top = self.figToolbar.rect_start_y
else:
rect_bottom = self.figToolbar.rect_start_y
rect_top = self.figToolbar.rect_start_y
else:
rect_left = self.figToolbar.rect_start_x
rect_right = self.figToolbar.rect_start_x
rect_bottom = self.figToolbar.rect_start_y
rect_top = self.figToolbar.rect_start_y
if event.button == 1 and self.is_left_button_pressed:
self.is_left_button_pressed = False
if rect_left < Config["CurrentThoIndex"]:
@ -1205,6 +1219,13 @@ class MainWindow_resp_quality_label(QMainWindow):
rect_left = 0
rect_right = 0
selected_area_for_add_points = self.data.Tho_Processed[int(rect_left):int(rect_right)]
# 找到子列表的最小值
min_value = min(selected_area_for_add_points)
# 遍历子列表,将不满足条件的元素替换为最小值
selected_area_for_add_points = [
y if rect_bottom < y < rect_top else min_value
for y in selected_area_for_add_points
]
peaks_idx, _ = find_peaks(selected_area_for_add_points,
height=float(Config["FindPeaks"]["MinHeight"]),
distance=float(Config["FindPeaks"]["MinInterval"]))
@ -1243,6 +1264,8 @@ class MainWindow_resp_quality_label(QMainWindow):
self.data.Tho_peak_y = [self.data.Tho_Processed[x] for x in self.data.Tho_peak]
self.figToolbar.rect_start_x = None
self.figToolbar.rect_end_x = None
self.figToolbar.rect_start_y = None
self.figToolbar.rect_end_y = None
result = self.data.save_tho_peak()
if not result.status:
@ -1262,6 +1285,8 @@ class MainWindow_resp_quality_label(QMainWindow):
def on_hold(self, event):
if self.figToolbar.rect_start_x is not None and event.xdata is not None:
self.figToolbar.rect_end_x = event.xdata
if self.figToolbar.rect_start_y is not None and event.ydata is not None:
self.figToolbar.rect_end_y = event.ydata
# 如果矩形patch不存在则创建一个新的
if self.figToolbar.rect_patch_ax1 is None:
@ -1278,11 +1303,19 @@ class MainWindow_resp_quality_label(QMainWindow):
# 更新矩形patch的位置和大小
x_start = self.figToolbar.rect_start_x
x_end = self.figToolbar.rect_end_x
rect_down = self.ax1.get_ylim()[0] - 1000
rect_up = self.ax1.get_ylim()[1] + 1000
self.figToolbar.rect_patch_ax1.set_xy((min(x_start, x_end), rect_down))
if self.is_left_button_pressed:
y_start = self.figToolbar.rect_start_y
y_end = self.figToolbar.rect_end_y
self.figToolbar.rect_patch_ax1.set_xy((min(x_start, x_end), min(y_start, y_end)))
self.figToolbar.rect_patch_ax1.set_height(abs(y_end - y_start))
elif self.is_right_button_pressed:
y_start = min(self.ax0.get_ylim()[0], self.ax1.get_ylim()[0]) - 1000
y_end = max(self.ax0.get_ylim()[1], self.ax1.get_ylim()[1]) + 1000
self.figToolbar.rect_patch_ax1.set_xy((min(x_start, x_end), y_start))
self.figToolbar.rect_patch_ax1.set_height(abs(y_end - y_start))
self.figToolbar.rect_patch_ax1.set_width(abs(x_end - x_start))
self.figToolbar.rect_patch_ax1.set_height(rect_up - rect_down)
self.canvas.draw()
@ -1603,6 +1636,8 @@ class CustomNavigationToolbar(NavigationToolbar2QT):
# 初始化矩形选择区域
self.rect_start_x = None
self.rect_end_x = None
self.rect_start_y = None
self.rect_end_y = None
self.rect_patch_ax1 = None # 用于绘制矩形的patch
def home(self, *args):