添加体动事件

This commit is contained in:
marques 2022-04-21 10:43:31 +08:00
parent f04f8a9e03
commit 7b2a1b20a9
2 changed files with 53 additions and 10 deletions

View File

@ -24,7 +24,9 @@ PSG_Data_Path = Path("I:/CXH/Quality_Relabel/Data/PSG/")
PSG_Label_Path = Path("I:/CXH/Quality_Relabel/Data/PSG_label/")
BCG_Data_Path = Path("I:/CXH/Quality_Relabel/Data/BCG/")
BCG_Label_Path = Path("I:/CXH/Quality_Relabel/Data/BCG_label/")
all_path = [PSG_Data_Path, PSG_Label_Path, BCG_Data_Path, BCG_Label_Path]
Artifact_Label_Path = Path("I:/CXH/Quality_Relabel/Data/Artifact_label/")
Artifact_Offset_Path = Path("I:/CXH/Quality_Relabel/Data/Artifact_label/20220421Artifact_offset_value.xlsx")
all_path = [PSG_Data_Path, PSG_Label_Path, BCG_Data_Path, BCG_Label_Path, Artifact_Label_Path, Artifact_Offset_Path]
# end-----一般不用修改------
# 要遍历的事件

View File

@ -63,8 +63,14 @@ class Quality_Relabel:
# 3 红色 阻塞型
# 4 灰色 混合型
# 5 绿色 血氧饱和度下降
color_cycle = ["black", "pink", "blue", "red", "grey", "green"]
assert len(color_cycle) == len(base_event) + 1, "基础事件数量与颜色数量不一致"
# 6 橙色 大体动
# 7 橙色 小体动
# 8 橙色 深呼吸
# 9 橙色 脉冲体动
# 10 橙色 无效片段
color_cycle = ["black", "pink", "blue", "red", "silver", "green", "orange", "orange", "orange", "orange", "orange"]
# assert len(color_cycle) == len(base_event) + 1, "基础事件数量与颜色数量不一致"
def __init__(self, all_path: List, sampNo: int, frequency: int = 100, bcg_frequency: int = 1000,
channel_list: List[str] = ['Effort Tho', 'Effort Abd', 'SpO2', 'Flow Patient', 'Flow Patient'],
@ -77,7 +83,13 @@ class Quality_Relabel:
:param channel_list: 显示的通道
:param focus_event_list: 关注暂停事件
"""
self.PSG_Data_Path, self.PSG_Label_Path, self.BCG_Data_Path, self.BCG_Label_Path = all_path
self.PSG_Data_Path = all_path[0]
self.PSG_Label_Path = all_path[1]
self.BCG_Data_Path = all_path[2]
self.BCG_Label_Path = all_path[3]
self.Artifact_Label_Path = all_path[4]
self.Artifact_Offset_Path = all_path[5]
self.sampNo = sampNo
self.channel_list = channel_list
self.focus_event_list = focus_event_list
@ -90,6 +102,7 @@ class Quality_Relabel:
self.ecg_event_label = None
self.bcg_event_label = None
self.spo2_event_label = None
self.artifact_event_label = None
# 仅包含关注暂停事件的列表
self.ecg_event_label_filtered_df = None
@ -251,6 +264,23 @@ class Quality_Relabel:
elif one_data["Event type"] == "Mixed apnea":
self.bcg_event_label[SP:EP] = 4
def read_artifact_label(self):
all_offset_length = pd.read_excel(self.Artifact_Offset_Path)
offset_length = all_offset_length[all_offset_length['数据编号'] == self.sampNo]['from_code']
artifact_label_path = self.Artifact_Label_Path / f"{self.sampNo}samp" / "Artifact_a.txt"
artifact_label = pd.read_csv(artifact_label_path, header=None).to_numpy().reshape(-1, 4)
self.artifact_event_label = np.zeros(len(self.bcg_event_label))
for i, artifact_type, SP, EP in artifact_label:
SP = (SP + offset_length) // (1000 // self.frequency)
EP = (SP + offset_length) // (1000 // self.frequency)
artifact_label += 5
if EP > len(self.bcg_event_label):
continue
self.artifact_event_label[SP:EP] = artifact_label
# assert len(self.ecg_event_label_filtered_df) == len(self.bcg_event_label_filtered_df), \
# f"PSG与心晓事件数量不一致, PSG事件数量{len(self.ecg_event_label_filtered_df)},
# 心晓事件数量{len(self.bcg_event_label_filtered_df)}"
@ -324,10 +354,14 @@ class Quality_Relabel:
self.plt_channel(plt_=plt, SP=ecg_SP, EP=ecg_EP, channel="SpO2", event_code=[5])
plt.subplot(gs[5])
self.plt_channel(plt_=plt, SP=bcg_SP, EP=bcg_EP, channel="orgdata", event_show_under=False)
self.plt_channel(plt_=plt, SP=bcg_SP, EP=bcg_EP, channel="orgdata",
event_code=[1, 2, 3, 4, 6, 7, 8, 9, 10],
event_show_under=False)
plt.subplot(gs[6])
self.plt_channel(plt_=plt, SP=bcg_SP, EP=bcg_EP, channel="0.7lowpass_resp", event_show_under=False,
self.plt_channel(plt_=plt, SP=bcg_SP, EP=bcg_EP, channel="0.7lowpass_resp",
event_code=[1, 2, 3, 4, 6, 7, 8, 9, 10],
event_show_under=False,
ax_bottom=True,
title=f"心晓 sampNo:{self.sampNo} Epoch:{one_bcg_data['Epoch']} Duration:{bcg_duration}",
)
@ -353,6 +387,7 @@ class Quality_Relabel:
:param title: 显示标题
:return:
"""
linestyle = "-"
SP = 0 if SP < 0 else SP
plt_.plot(np.linspace(SP, EP, (EP - SP) * self.frequency),
self.signal_select[channel][SP * self.frequency:EP * self.frequency], label=channel,
@ -362,7 +397,11 @@ class Quality_Relabel:
if channel == "SpO2":
mask = self.spo2_event_label[SP * self.frequency:EP * self.frequency] == j
elif channel == "orgdata" or channel == "0.7lowpass_resp":
mask = self.bcg_event_label[SP * self.frequency:EP * self.frequency] == j
if j < 4:
mask = self.bcg_event_label[SP * self.frequency:EP * self.frequency] == j
else:
mask = self.artifact_event_label[SP * self.frequency:EP * self.frequency] == j
linestyle = "--"
else:
mask = self.ecg_event_label[SP * self.frequency:EP * self.frequency] == j
@ -373,8 +412,10 @@ class Quality_Relabel:
np.place(y, y == 0, np.nan)
else:
y = (self.signal_select[channel][SP * self.frequency:EP * self.frequency] * mask).astype('float')
np.place(y, y == 0, np.nan)
plt_.plot(np.linspace(SP, EP, (EP - SP) * self.frequency), y, color=self.color_cycle[j])
plt_.plot(np.linspace(SP, EP, (EP - SP) * self.frequency), y, color=self.color_cycle[j],
linestyle=linestyle)
plt_.legend(loc=1)
if title is not None:
@ -404,6 +445,6 @@ if __name__ == '__main__':
PSG_Label_Path = "../Data/PSG_label/"
BCG_Data_Path = "../Data/BCG/"
BCG_Label_Path = "../Data/BCG_label/"
all_path = [PSG_Data_Path, PSG_Label_Path, BCG_Data_Path, BCG_Label_Path]
prepareData = Quality_Relabel(all_path, 670)
all_paths = [PSG_Data_Path, PSG_Label_Path, BCG_Data_Path, BCG_Label_Path]
prepareData = Quality_Relabel(all_paths, 670)
prepareData.show_all_event()