Exemplo n.º 1
0
def get_feature(edf_file):
    reader = EdfReader(edf_file)
    n = reader.signals_in_file
    buffer = np.zeros((n, reader.getNSamples()[0]))
    for i in np.arange(n):
        buffer[i, :] = reader.readSignal(i)

    signal = list(buffer[0])

    signal_len = 64

    return FeatureExt(signal, signal_len)
class ChbEdfFile(object):
    """
    Edf reader using pyedflib
    """
    def __init__(self, filename, patient_id=None):
        self._filename = filename
        self._patient_id = patient_id
        self._file = EdfReader(filename)

    def get_filename(self):
        return self._filename

    def get_n_channels(self):
        """
        Number of channels
        """
        return len(self._file.getSampleFrequencies())

    def get_n_data_points(self):
        """
        Number of data points
        """
        if len(self._file.getNSamples()) < 1:
            raise ValueError("Number of channels is less than 1")
        return self._file.getNSamples()[0]

    def get_channel_names(self):
        """
        Names of channels
        """
        return self._file.getSignalLabels()

    def get_channel_scalings(self):
        """
        Channel scalings as an array
        :return:
        """
        out = np.zeros(self.get_n_channels())
        for i in range(self.get_n_channels()):
            out[i] = self._file.getPhysicalMaximum(
                i) - self._file.getPhysicalMinimum(i)
        return out

    def get_file_duration(self):
        """
        Returns the file duration in seconds
        """
        return self._file.getFileDuration()

    def get_sampling_rate(self):
        """
        Get the frequency
        """
        if len(self._file.getSampleFrequencies()) < 1:
            raise ValueError("Number of channels is less than 1")
        return self._file.getSampleFrequency(0)

    def get_channel_data(self, channel_id):
        """
        Get raw data for a single channel
        """
        if channel_id >= self.get_n_channels() or channel_id < 0:
            raise ValueError("Illegal channel id selected %d" % channel_id)
        return self._file.readSignal(channel_id)

    def get_data(self):
        """
        Get raw data for all channels
        """
        output_data = np.zeros(
            (self.get_n_data_points(), self.get_n_channels()))
        for i in range(self.get_n_channels()):
            output_data[:, i] = self._file.readSignal(i)
        return output_data

    def get_start_datetime(self):
        """
        Get the starting date and time
        """
        return self._file.getStartdatetime()

    def get_end_datetime(self):
        return self._file.getStartdatetime() + datetime.timedelta(
            seconds=self._file.getFileDuration())
Exemplo n.º 3
0
# -*- coding: utf-8 -*-
"""
Created on Sun Jan  5 16:17:58 2020

@author: Dell
"""
# %% importing dependancies
from pyedflib import EdfReader
import numpy as np

# %% importing the dataset
filepath = 'D:\Mini II\DATASETS\eNTERFACING\Data\EEG\Part1_IAPS_SES1_EEG_fNIRS_03082006.bdf'
f = EdfReader(filepath)
n = f.signals_in_file
signal_labels = f.getSignalLabels()
sigbufs = np.zeros((n, f.getNSamples()[0]))
for i in np.arange(n):
    sigbufs = f.readSignal(i)

# %%