Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement