def main():
    EDF.setFilter(Injector.filter)
    DataManifest.setFolder('./{}_seizure'.format(Injector.dataset))
    with open(f'./{Injector.location}.json') as f:
        patientList = set()
        data = json.load(f)
        DataManifest.buildDir()
        result = {}
        sessionsWithSeizures = 0
        for channel in path:
            patients = data[channel]['seizure']
            sessionsWithSeizures += len(patients)
            for patient in patients:
                patientList.add(patient['id'])
                seizureExtraction(patient)
    print("The record is set to use the following channels in sequence:")
    print("------------")
    if Injector.performConversion:
        edfChannels = EDF.montageConversionChannels
    else:
        edfChannels = EDF.commonChannels
    for i, c in enumerate(edfChannels):
        print("No.{:02d}: {}".format(i + 1, c))
    print("------------")
    print("Total number of seizures: " + str(DataManifest.index))
    print("Total seizure duration: " + str(DataManifest.totalDuration))
    print("No. sessions w/ seizures: " + str(sessionsWithSeizures))
    print("No. patients w/ seizures: " + str(len(patientList)))
def seizureExtraction(patient):
    for session in patient['sessions']:
        manifest = DataManifest(session["edf"].split("/")[-1],
                                session['seizure']['seizureType'],
                                patient['info']['age'],
                                patient['info']['gender'])
        seizureDuration = \
            float(session['seizure']['stop']) - \
            float(session['seizure']['start'])
        for i in range(int(seizureDuration // Injector.timeWindow)):
            edfRecord = EDF(session['edf'])
            edfRecord.loadData(
                str(
                    float(session['seizure']['start']) +
                    Injector.timeWindow * i),
                str(
                    float(session['seizure']['start']) + Injector.timeWindow *
                    (i + 1)))
            manifest.seg = i + 1
            manifest.seizureDuration = seizureDuration
            manifest.freq = edfRecord.ofreq
            manifest.generateRecord()
            manifest.writeToManifest()
            if Injector.performConversion:
                edfRecord.saveFile(edfRecord.montageConversion(),
                                   manifest.fileName)
            else:
                edfRecord.saveFile(edfRecord.raw, manifest.fileName)
def main():
    EDF.setFilter(Injector.filter)
    DataManifest.setFolder('./{}_{}s_seg'.format(Injector.dataset,
                                                 Injector.timeWindow))
    with open(f'{Injector.location}.json') as f:
        patientList = set()
        data = json.load(f)
        DataManifest.buildDir()
        result = {}
        for channel in path:
            patients = data[channel]['seizure']
            for patient in patients:
                seizureExtraction(patient)
    print("Segments count: " + str(DataManifest.index))
def main():
    EDF.setFilter(Injector.filter)
    if Injector.timeWindow:
        DataManifest.setFolder('./{}_{}s_noseizure_seg'.format(
            Injector.dataset, Injector.timeWindow))
    else:
        DataManifest.setFolder('./{}_noseizure'.format(Injector.dataset))
    with open(f'{Injector.location}.json') as f:
        data = json.load(f)
        os.makedirs(f'./{DataManifest.dirName}', exist_ok=True)
        for channel in path:
            patients = data[channel]['noSeizure']
            for patient in patients:
                noseizureExtraction(patient)
    print("Segments count: " + str(DataManifest.index))
Esempio n. 5
0
def noSeizure():
    edfCount = 0
    DataManifest.setFolder('./{}_noseizure'.format(Injector.dataset))
    with open(f'./{Injector.location}.json') as f:
        patientList = set()
        data = json.load(f)
        result = {}
        sessionsWithSeizures = 0
        for channel in path:
            patients = data[channel]['noSeizure']
            sessionsWithSeizures += len(patients)
            for patient in patients:
                patientList.add(patient['id'])
                edfCount += len(patient['fileNames'])
    print("------------")
    print("Total files w/o seizures: " + str(edfCount))
    print("No. sessions w/o seizures: " + str(sessionsWithSeizures))
    print("No. patients w/o seizures: " + str(len(patientList)))
    print("------------")
Esempio n. 6
0
def seizure():
    DataManifest.setFolder('./{}_seizure'.format(Injector.dataset))
    with open(f'./{Injector.location}.json') as f:
        patientList = set()
        data = json.load(f)
        result = {}
        sessionsWithSeizures = 0
        for channel in path:
            patients = data[channel]['seizure']
            sessionsWithSeizures += len(patients)
            for patient in patients:
                patientList.add(patient['id'])
                seizureExtraction(patient)
    print("------------")
    print("Total number of seizures: " + str(DataManifest.index))
    print("Total seizure duration: " + str(DataManifest.totalDuration))
    print("No. sessions w/ seizures: " + str(sessionsWithSeizures))
    print("No. patients w/ seizures: " + str(len(patientList)))
    print("------------")
Esempio n. 7
0
def seizureExtraction(patient):
    for session in patient['sessions']:
        manifest = DataManifest(session["edf"].split("/")[-1],
                                session['seizure']['seizureType'],
                                patient['info']['age'],
                                patient['info']['gender'])
        manifest.generateRecord()
        seizureDuration = \
                float(session['seizure']['stop']) - \
                float(session['seizure']['start'])
        manifest.setSeizureDuration(seizureDuration)
def seizureExtraction(patient):
    for session in patient['sessions']:
        manifest = DataManifest(session["edf"].split("/")[-1],
                                session['seizure']['seizureType'],
                                patient['info']['age'],
                                patient['info']['gender'])
        manifest.generateRecord()
        if Injector.preprocess:
            seizureDuration = \
                float(session['seizure']['stop']) - \
                float(session['seizure']['start'])
            edfRecord = EDF(session['edf'])
            edfRecord.loadData(float(session['seizure']['start']),
                               float(session['seizure']['stop']))

            manifest.setSeizureDuration(seizureDuration)
            manifest.freq = edfRecord.ofreq
            manifest.seg = 1
            manifest.filterName = Injector.filter
            manifest.writeToManifest()
            if Injector.performConversion:
                edfRecord.saveFile(edfRecord.montageConversion(),
                                   manifest.fileName)
            else:
                edfRecord.saveFile(edfRecord.raw, manifest.fileName)
        else:
            edfRecord.saveFile(EDF(session["edf"]).raw, manifest.fileName)
def noseizureExtraction(patient):
    for edf in patient['fileNames']:
        manifest = DataManifest(
            edf.split("/")[-1], 'noseizure', patient['info']['age'],
            patient['info']['gender'])
        manifest.generateRecord()
        if Injector.preprocess:
            edfRecord = EDF(edf)
            seizureDuration = round(edfRecord.duration(), 4)
            for i in range(int(seizureDuration // Injector.timeWindow) - 1):
                edfRecord = EDF(edf)
                edfRecord.loadData(Injector.timeWindow * i,
                                   Injector.timeWindow * (i + 1))
                manifest.seg = i + 1
                manifest.filterName = Injector.filter
                manifest.generateRecord()
                manifest.freq = edfRecord.ofreq
                manifest.writeToManifest()
                if Injector.performConversion:
                    edfRecord.saveFile(edfRecord.montageConversion(),
                                       manifest.fileName)
                else:
                    edfRecord.saveFile(edfRecord.raw, manifest.fileName)
        else:
            edfRecord.saveFile(EDF(session["edf"]).raw, manifest.fileName)