Exemplo n.º 1
0
    def test_drop_channel(self):
        signal_headers = highlevel.make_signal_headers(
            ['ch' + str(i) for i in range(5)])
        signals = np.random.rand(5, 256 * 300) * 200  #5 minutes of eeg
        highlevel.write_edf(self.drop_from, signals, signal_headers)

        dropped = highlevel.drop_channels(self.drop_from,
                                          to_keep=['ch1', 'ch2'],
                                          verbose=True)

        signals2, signal_headers, header = highlevel.read_edf(dropped)

        np.testing.assert_allclose(signals[1:3, :], signals2, atol=0.01)

        highlevel.drop_channels(self.drop_from,
                                self.drop_from[:-4] + '2.edf',
                                to_drop=['ch0', 'ch1', 'ch2'])
        signals2, signal_headers, header = highlevel.read_edf(
            self.drop_from[:-4] + '2.edf')

        np.testing.assert_allclose(signals[3:, :], signals2, atol=0.01)

        with self.assertRaises(AssertionError):
            highlevel.drop_channels(self.drop_from,
                                    to_keep=['ch1'],
                                    to_drop=['ch3'])
Exemplo n.º 2
0
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 29 15:33:03 2020

@author: skjerns
"""
import ospath
import os, sys
import numpy as np
import shutil
import config as cfg
from tqdm import tqdm
from sleep import SleepSet
from pyedflib.highlevel import drop_channels


files = ospath.list_files(cfg.folder_edf, exts='edf')
mats = ospath.list_files(cfg.folder_edf, exts='mat', relative=True)
mats = [mat.replace('_hrv', '').replace('_small', '').replace('.mat', '') for mat in mats]

ecg_dir = cfg.folder_edf + '/edf_no_mat'
os.makedirs(ecg_dir)


for file in tqdm(files):
    code = ospath.basename(file)[:-4]
    if code in mats: continue
    drop_channels(os.path.join(cfg.folder_edf, f'{code}.edf'), os.path.join(ecg_dir,f'{code}.edf'), to_keep=['ECG I'])