edfx_database.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:AutoSleepScorerDev 作者: skjerns 项目源码 文件源码
def convert_hypnograms(datadir):
    """
    This function is quite a hack to read the edf hypnogram as a byte array. 
    I found no working reader for the hypnogram edfs.
    """
    print('Converting hypnograms')
    files = [x for x in os.listdir(datadir) if x.endswith('.hyp')]
    for file in files:
        file = os.path.join(datadir,file)
        hypnogram = []
        with open(file, mode='rb') as f: # b is important -> binary

            raw_hypno = [x for x in str(f.read()).split('Sleep_stage_')][1:]
            for h in raw_hypno:
                stage  = h[0]
                repeat = int(h.split('\\')[0][12:])//30 # no idea if this also works on linux
                hypnogram.extend(stage*repeat)            
        with open(file[:-4] + '.csv', "w") as f:
            writer = csv.writer(f, lineterminator='\r')
            writer.writerows(hypnogram)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号