Example #1
0
def plot_epoch(start=0.0, duration=10.0):
    "plot all the signals one above another in a 10 second epoch"
    from stacklineplot import stackplot
    x0 = start * fs
    x1 = (start + duration) * fs
    stackplot(allsig[:, x0:x1],
              seconds=duration,
              start_time=start,
              ylabels=signal_labels)
Example #2
0
def test_edflibpyx():
    bfile_name = FILE_NAME.encode(TEXT_ENCODING)
    with _edflib.CyEdfReader(bfile_name, TEXT_ENCODING) as efc:

        signal_labels, signal_nsamples = fileinfo(efc)
        # convert byte strings to regular string
        signal_labels = [
            label.decode(TEXT_ENCODING) for label in signal_labels
        ]
        sig1 = np.zeros(2000, dtype='float64')
        efc.read_phys_signal(1, 0, 2000, sig1)

        nsigs = efc.signals_in_file
        sigbufs = np.zeros((nsigs, 2000), dtype='float64')
        # read the first 10 sec
        readpt = 0
        for ii in range(nsigs):
            efc.read_phys_signal(ii, readpt, 2000, sigbufs[ii])

        if __name__ == '__main__':
            import matplotlib.pyplot as plt
            from stacklineplot import stackplot, figure
            fig1 = plt.figure(1, figsize=(8, 6))
            stackplot(sigbufs,
                      seconds=10.0,
                      start_time=0.0,
                      ylabels=signal_labels)
            fig1.savefig('test_edflibpyx_fig1.png', bbox_inches='tight')

        # now read the next 10 seconds
        readpt = 2000
        for ii in range(nsigs):
            efc.read_phys_signal(ii, readpt, 2000, sigbufs[ii])

        if __name__ == '__main__':
            fig2 = plt.figure(2, figsize=(8, 6))
            stackplot(sigbufs,
                      seconds=10.0,
                      start_time=10.0,
                      ylabels=signal_labels)
            fig2.savefig('test_edflibpyx_fig2.png', bbox_inches='tight')

        # now read the overlap 5-15 seconds
        readpt = 1000
        for ii in range(nsigs):
            efc.read_phys_signal(ii, readpt, 2000, sigbufs[ii])

        Nibuf = 1000
        ibuf = np.zeros(Nibuf, dtype='int32')

        # try pickout signal 5
        _edflib.rewind(efc.handle, 5)
        _edflib.read_int_samples(efc.handle, 5, Nibuf, ibuf)
Example #3
0
def plotEDFdata(eeg_path):
    f = pyedflib.EdfReader(eeg_path)
    n_channels = f.signals_in_file  # number of EEG channels
    signal_labels = f.getSignalLabels()  # names of EEG channels

    n_min = f.getNSamples()[0]
    sigbufs = [np.zeros(f.getNSamples()[i]) for i in np.arange(n_channels)]
    for i in np.arange(n_channels):
        sigbufs[i] = f.readSignal(i)
        if n_min < len(sigbufs[i]):
            n_min = len(sigbufs[i])
    f._close()
    del f
    n_plot = np.min((n_min, 2800))
    sigbufs_plot = np.zeros((n_channels, n_plot))
    for i in np.arange(n_channels):
        sigbufs_plot[i, :] = sigbufs[i][:n_plot]

    stackplot(sigbufs_plot[:, :n_plot], ylabels=signal_labels)
Example #4
0
def readsignals(edf, start_time, end_time, buf=None):
    """times in seconds"""
    # assume same sampling rate for all channels for a moment and use signal#0
    assert end_time <= edf.file_duration
    
    readpt = int(edf.samplefrequency(0)*(start_time))
    print( "readpt:", readpt)
    readlen = int( edf.samplefrequency(0)*(end_time-start_time))
    assert readlen <= MAXSIGLEN
    print( "readlen:", readlen)
    for ii in range(nsigs):
        e.readsignal(ii, readpt, readlen, sigbufs[ii])
    return readpt, readlen
L = 8.0
s,l = readsignals(e, 0, L)
stackplot(sigbufs[:, s:s+l], seconds = L, ylabels=signal_labels)

# findx2 = [ (ii, signal_labels[ii]) for ii in range(len(signal_labels))] 
# X2 is signal 27
# A2 is signal 23

ekg = sigbufs[27][0:l] - sigbufs[23][0:l]

from scipy.signal import kaiserord, lfilter, firwin, freqz
# lowpass filter

sample_rate = e.samplefrequency(0)
nyq_rate = sample_rate/2.0
width = 5.0/nyq_rate
ripple_db = 60.0
N, beta = kaiserord(ripple_db, width)
Example #5
0
#!/usr/bin/env python
from __future__ import division, print_function, absolute_import

import numpy as np

import pyedflib

from stacklineplot import stackplot

if __name__ == '__main__':
    f = pyedflib.data.test_generator()
    n = f.signals_in_file
    signal_labels = f.getSignalLabels()

    sigbufs = np.zeros((n, f.getNSamples()[0]))
    for i in np.arange(n):
        sigbufs[i, :] = f.readSignal(i)

    f._close()
    del f
    # stackplot(sigbufs,seconds=10.0, start_time=0.0, ylabels=signal_labels)

    stackplot(sigbufs[:, :2000], ylabels=signal_labels)
    sig1 = np.zeros(2000.0, dtype='float64')
    e.readsignal(1,0, 2000, sig1)

    nsigs = e.signals_in_file
    MAXSIGLEN = 20000
    sigbufs = np.zeros((nsigs,MAXSIGLEN), dtype='float64')
    # read the first 10 sec
    readpt = 0
    for ii in range(nsigs):
        e.readsignal(ii, readpt, 2000, sigbufs[ii])

    # stackplot(sigbufs,seconds=10.0, start_time=0.0, ylabels=signal_labels)

    L = 8.0
    s,l = readsignals(e, 0, L)
    stackplot(sigbufs[:, s:s+l], seconds = L, ylabels=signal_labels)

    # findx2 = [ (ii, signal_labels[ii]) for ii in range(len(signal_labels))] 
    # X2 is signal 27
    # A2 is signal 23

    ekg = sigbufs[27][0:l] - sigbufs[23][0:l]

    from scipy.signal import kaiserord, lfilter, firwin, freqz
    sample_rate = e.samplefrequency(0)
    nyq_rate = sample_rate/2.0
    width = 5.0/nyq_rate
    ripple_db = 60.0
    N, beta = kaiserord(ripple_db, width)
    cutoff_hz = 10.0
    taps = firwin(N, cutoff_hz/nyq_rate, window=('kaiser', beta))
Example #7
0
        print(edf.samplefrequency(ii))


fileinfo(e)
sig1 = np.zeros(2000, dtype='float64')
e.read_phys_signal(1, 0, 2000, sig1)

nsigs = e.signals_in_file
sigbufs = np.zeros((nsigs, 2000), dtype='float64')
# read the first 10 sec
readpt = 0
for ii in range(nsigs):
    e.read_phys_signal(ii, readpt, 2000, sigbufs[ii])

from stacklineplot import stackplot, figure
stackplot(sigbufs, seconds=10.0, start_time=0.0, ylabels=signal_labels)

# now read the next 10 seconds
readpt = 2000
for ii in range(nsigs):
    e.read_phys_signal(ii, readpt, 2000, sigbufs[ii])
figure()
stackplot(sigbufs, seconds=10.0, start_time=10.0, ylabels=signal_labels)

# now read the overlap 5-15 seconds
readpt = 1000
for ii in range(nsigs):
    e.read_phys_signal(ii, readpt, 2000, sigbufs[ii])

Nibuf = 1000
ibuf = np.zeros(Nibuf, dtype='int32')
        print edf.samplefrequency(ii)

fileinfo(e)
sig1 = np.zeros(2000.0, dtype='float64')
e.readsignal(1,0, 2000, sig1)

nsigs = e.signals_in_file
sigbufs = np.zeros((nsigs,2000), dtype='float64')
# read the first 10 sec
readpt = 0
for ii in range(nsigs):
    e.readsignal(ii, readpt, 2000, sigbufs[ii])


from stacklineplot import stackplot, figure
stackplot(sigbufs,seconds=10.0, start_time=0.0, ylabels=signal_labels)


# now read the next 10 seconds
readpt = 2000
for ii in range(nsigs):
    e.readsignal(ii, readpt, 2000, sigbufs[ii])
figure()
stackplot(sigbufs,seconds=10.0, start_time=10.0, ylabels=signal_labels)

# now read the overlap 5-15 seconds
readpt = 1000
for ii in range(nsigs):
    e.readsignal(ii, readpt, 2000, sigbufs[ii])

Nibuf=1000
Example #9
0
def showEEG(start, end):
    stackplot(sigbufs[:, (start * sr):(end * sr)], ylabels=signal_labels)
Example #10
0
#!/usr/bin/env python
from __future__ import division, print_function, absolute_import

import numpy as np

import pyedflib

from stacklineplot import stackplot

if __name__ == '__main__':
    f = pyedflib.data.test_generator()
    n = f.signals_in_file
    signal_labels = f.getSignalLabels()
    n_min = f.getNSamples()[0]
    sigbufs = [np.zeros(f.getNSamples()[i]) for i in np.arange(n)]
    for i in np.arange(n):
        sigbufs[i] = f.readSignal(i)
        if n_min < len(sigbufs[i]):
            n_min = len(sigbufs[i])
    f._close()
    del f

    n_plot = np.min((n_min, 2000))
    sigbufs_plot = np.zeros((n, n_plot))
    for i in np.arange(n):
        sigbufs_plot[i, :] = sigbufs[i][:n_plot]

    stackplot(sigbufs_plot[:, :n_plot], ylabels=signal_labels)
Example #11
0
#!/usr/bin/env python
from __future__ import division, print_function, absolute_import

import os
import numpy as np

import pyedflib


from stacklineplot import stackplot


if __name__ == '__main__':
    f = pyedflib.EdfReader("data/test_generator.edf")
    n = f.signals_in_file
    signal_labels = f.getSignalLabels()

    sigbufs = np.zeros((n, f.getNSamples()[0]))
    for i in np.arange(n):
        sigbufs[i, :] = f.readSignal(i)

    f._close()
    del f
    # stackplot(sigbufs,seconds=10.0, start_time=0.0, ylabels=signal_labels)

    stackplot(sigbufs[:, :2000], ylabels=signal_labels)