1 Star 0 Fork 0

mayfan11/1D-ResNet-SE-LSTM

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
preprocess_ISRUC_S1.py 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
weiming1122 提交于 2023-03-14 13:31 . Add files via upload
import numpy as np
import scipy.io as scio
import os
from scipy import signal
path_Extracted = 'data/ISRUC_S1/ExtractedChannels/'
path_RawData = 'data/ISRUC_S1/RawData/'
path_output = 'data/ISRUC_S1/'
def read_psg(path_Extracted, sub_id, fs=100):
psg = scio.loadmat(os.path.join(path_Extracted, 'subject%d.mat' % (sub_id)))
psg_use = psg['F3_A2'] # 'C3_A2', 'C4_A1', 'F3_A2', 'F4_A1', 'O1_A2', 'O2_A1', 'LOC_A2', 'ROC_A1','X1', 'X2'
psg_resample = signal.resample(psg_use, fs*30, axis=-1)
return psg_resample
def read_label(path_RawData, sub_id, ignore=30):
label = []
with open(os.path.join(path_RawData, '%d/%d_1.txt' % (sub_id, sub_id))) as f:
s = f.readline()
while True:
a = s.replace('\n', '')
label.append(int(a))
s = f.readline()
if s == '' or s == '\n':
break
return np.array(label[:-ignore])
for sub in range(1, 101):
print('Read subject', sub)
psg = read_psg(path_Extracted, sub)
label = read_label(path_RawData, sub)
print('Subject', sub, ':', label.shape, psg.shape)
assert len(label) == len(psg)
# in ISRUC, 0-Wake, 1-N1, 2-N2, 3-N3, 5-REM
label[label==5] = 4 # make 4 correspond to REM
filename = os.path.join(path_output, 'ISRUC_S1_%d.npz' % (sub))
save_dict = {'x': psg, 'y': label}
np.savez(filename, **save_dict)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mayfan11/1D-ResNet-SE-LSTM.git
git@gitee.com:mayfan11/1D-ResNet-SE-LSTM.git
mayfan11
1D-ResNet-SE-LSTM
1D-ResNet-SE-LSTM
main

搜索帮助