Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Float edf #27

Open
gsamyak30 opened this issue Mar 14, 2022 · 1 comment
Open

Float edf #27

gsamyak30 opened this issue Mar 14, 2022 · 1 comment

Comments

@gsamyak30
Copy link

gsamyak30 commented Mar 14, 2022

Hi Simon

I am just getting a error

TypeError: 'float' object does not support item assignment

when I am taking the dataset of ST7022JM-Hypnogram.edf or any other hypnogram.edf from physionet in sleep telemetry while converting into csv file format

How do I resolve it !!

@skjerns
Copy link
Owner

skjerns commented Mar 14, 2022

EDF is an odd format for storing hypnograms, no idea why physionet decided to do that. you need to convert the hypnogram from EDF to CSV.

try this function taken from here: https://github.com/skjerns/AutoSleepScorerDev/blob/master/edfx_database.py

import csv
from pyedflib import highlevel

def convert_hypnograms(hypnogram_edf_file):
    """
    This function is quite a hack to read the edf hypnogram as a byte array. 
    I found no working reader for the hypnogram edfs.
    """
    
    hypnogram = []
    annot = highlevel.read_edf_header(hypnogram_edf_file)['annotations']
    for bstart, blength, bstage in annot:
        length = int(blength.decode())
        stage = bstage.decode()
        if 'movement' in stage.lower(): stage='M'
        stage = [str(stage[-1])]*(length//30)
        hypnogram.extend(stage)
        
    csv_file = hypnogram_edf_file.replace('-Hypnogram','')[:-5] + '0-PSG.csv'
    with open(csv_file, "w") as f:
        writer = csv.writer(f, lineterminator='\r')
        writer.writerows(hypnogram)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants