修改体动标签读取失败

This commit is contained in:
marques 2022-04-21 11:26:53 +08:00
parent cbc559572e
commit ec57c4d050
2 changed files with 22 additions and 16 deletions

View File

@ -56,13 +56,13 @@ if __name__ == '__main__':
opt = parser.parse_args()
focus_event_list = []
if 'OSA' in opt.focus_event_list:
if 'OSA' in opt.event:
focus_event_list.append("Obstructive apnea")
if 'CSA' in opt.focus_event_list:
if 'CSA' in opt.event:
focus_event_list.append("Central apnea")
if 'MSA' in opt.focus_event_list:
if 'MSA' in opt.event:
focus_event_list.append("Mixed apnea")
if 'HPY' in opt.focus_event_list:
if 'HPY' in opt.event:
focus_event_list.append("Hypopnea")
qualityRelabel = Quality_Relabel(all_path=all_path, sampNo=opt.sampNo, frequency=frequency,

View File

@ -63,12 +63,12 @@ class Quality_Relabel:
# 3 红色 阻塞型
# 4 灰色 混合型
# 5 绿色 血氧饱和度下降
# 6 色 大体动
# 7 色 小体动
# 8 色 深呼吸
# 9 色 脉冲体动
# 10 色 无效片段
color_cycle = ["black", "pink", "blue", "red", "silver", "green", "orange", "orange", "orange", "orange", "orange"]
# 6 色 大体动
# 7 色 小体动
# 8 色 深呼吸
# 9 色 脉冲体动
# 10 色 无效片段
color_cycle = ["black", "pink", "blue", "red", "silver", "green", "yellow", "yellow", "yellow", "yellow", "yellow"]
# assert len(color_cycle) == len(base_event) + 1, "基础事件数量与颜色数量不一致"
@ -118,6 +118,7 @@ class Quality_Relabel:
self.check_channel()
self.read_data(frequency, bcg_frequency)
self.read_event()
self.read_artifact_label()
def check_channel(self):
for i in self.channel_list:
@ -266,20 +267,25 @@ class Quality_Relabel:
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']
offset_length = all_offset_length[all_offset_length['数据编号'] == self.sampNo]['from_code'].values[0]
artifact_label_path = self.Artifact_Label_Path / f"Artifact_{self.sampNo}.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):
SP = (int(SP) + offset_length) // (1000 // self.frequency)
EP = (int(EP) + offset_length) // (1000 // self.frequency)
artifact_type = int(artifact_type) + 5
SP = 0 if SP < 0 else SP
if EP < 0:
continue
self.artifact_event_label[SP:EP] = artifact_label
if SP > len(self.bcg_event_label):
continue
self.artifact_event_label[SP:EP] = artifact_type
# 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)},