def load_biosig(fname):
    """Loads biosig compatible datasets.
    Parameters
    ----------
    fname : path to dataset

    Returns
    -------
    data : dataset as a numpy matrix
    sample_rate : dataset sample rate

    Examples
    --------
    >>> data_path = "/PATH/TO/PATH/dataset.gdf"
    >>> EEGdata = loadBiosig(data_path)
    """

    # Loads GDF competition data
    HDR = biosig.constructHDR(0, 0)
    HDR = biosig.sopen(fname, 'r', HDR)

    sample_rate = HDR.SampleRate
    data = biosig.sread(0, HDR.NRec, HDR)

    biosig.sclose(HDR)
    biosig.destructHDR(HDR)

    return data, sample_rate
Exemple #2
0
def loadBiosig(fname):
    """Loads biosig compatible datasets.
    Parameters
    ----------
    fname : path to dataset

    Returns
    -------
    data : dataset as a numpy matrix
    sample_rate : dataset sample rate

    Examples
    --------
    >>> data_path = "/PATH/TO/PATH/dataset.gdf"
    >>> EEGdata = loadBiosig(data_path)
    """

    # Loads GDF competition data
    HDR = biosig.constructHDR(0, 0)
    HDR = biosig.sopen(fname, 'r', HDR)

    sample_rate = HDR.SampleRate
    data = biosig.sread(0, HDR.NRec, HDR)

    biosig.sclose(HDR)
    biosig.destructHDR(HDR)

    return data, sample_rate
def read_data(f_name):
    t1 = time.time()
    HDR = biosig.sopen(f_name, 'r')
    print("Read header of %s in %f s\n" % (f_name, time.time() - t1))

    t1 = time.time()
    data = biosig.sread(HDR, HDR.NRec, 0)
    print("Read data of %s in %f s\n" % (f_name, time.time() - t1))

    biosig.sclose(HDR)

    return HDR, data
Exemple #4
0
def load(fname):
    HDR = biosig.constructHDR(0, 0)
    HDR = biosig.sopen(fname, "r", HDR)

    # 	turn off all channels
    #    for i in range(HDR.NS):
    #        HDR.CHANNEL[i].OnOff = 0

    # 	turn on specific channels
    #    HDR.CHANNEL[0].OnOff = 1
    #    HDR.CHANNEL[1].OnOff = 1
    #    HDR.CHANNEL[HDR.NS-1].OnOff = 1

    data = biosig.sread(0, HDR.NRec, HDR)

    biosig.sclose(HDR)
    biosig.destructHDR(HDR)

    return data
Exemple #5
0
def load(fname):
    HDR = biosig.constructHDR(0, 0)
    HDR = biosig.sopen(fname, "r", HDR)

    #	turn off all channels
    #    for i in range(HDR.NS):
    #        HDR.CHANNEL[i].OnOff = 0

    #	turn on specific channels
    #    HDR.CHANNEL[0].OnOff = 1
    #    HDR.CHANNEL[1].OnOff = 1
    #    HDR.CHANNEL[HDR.NS-1].OnOff = 1

    data = biosig.sread(0, HDR.NRec, HDR)

    biosig.sclose(HDR)
    biosig.destructHDR(HDR)

    return data
Exemple #6
0
def _load_biosig(filename):
    import biosig
    hdr = biosig.constructHDR(0, 0)
    hdr = biosig.sopen(filename, 'r', hdr)
    # The logic here does not match the biosig API. But it is deliberately
    # this way to work around a bug loading EDF files in python-biosig 1.3.
    # TODO: revisit this code when I finally get python-biosig 1.6 to install.
    channels = hdr.NS - 1
    fs = hdr.SampleRate / channels
    npoints = hdr.NRec * hdr.SPR / channels
    ar = np.zeros((npoints, channels), dtype=np.float64)
    channelnames = []
    for i in range(channels):
        label = hdr.CHANNEL[i].Label
        if '\x00' in label:
            label = label[:label.index('\x00')]
        channelnames.append(label)
        for j in range(hdr.NS):
            hdr.CHANNEL[j].OnOff = int(j == i)
        data = biosig.sread(0, hdr.NRec, hdr)
        ar[:, i] = data.reshape((npoints, channels))[:, 0]
    biosig.sclose(hdr)
    biosig.destructHDR(hdr)
    return Timeseries(ar, labels=[None, channelnames], fs=fs)
Exemple #7
0
import pylab
import numpy
import biosig
HDR=biosig.sopen('/home/schloegl/data/test/gdf/sample.gdf','r',biosig.constructHDR(0,0));
#for i in range(HDR.NS):
#    HDR.CHANNEL[i].OnOff = 0
#HDR.CHANNEL[0].OnOff = 1
data = biosig.sread(0, HDR.NRec, HDR)
biosig.sclose(HDR)
#biosig.destructHDR(HDR)


pylab.ion();
pylab.plot(numpy.transpose(data))
pylab.show();

Exemple #8
0
    #for k in range(HDR.EVENT.N): print k,TYP[k],POS[k],POS[k]/HDR.EVENT.SampleRate #,HDR.EVENT.CodeDesc[TYP[k]]

    for k in range(HDR.NS):
        # convert C to Python string: get rid of everything after \x00, then remove leading and trailing whitespace
        str = HDR.CHANNEL[k].Label
        HDR.CHANNEL[k].Label = str[0:str.find(chr(0))].strip()
        str = HDR.CHANNEL[k].Transducer
        HDR.CHANNEL[k].Transducer = str[0:str.find(chr(0))].strip()
        print k, HDR.CHANNEL[k].OnOff == 0, '<', HDR.CHANNEL[
            k].Label, '>,<', HDR.CHANNEL[k].Transducer, '>'
    #	turn off all channels
    #    for i in range(HDR.NS):
    #        HDR.CHANNEL[i].OnOff = 0
    #
    #	turn on specific channels
    #    HDR.CHANNEL[0].OnOff = 1
    #    HDR.CHANNEL[1].OnOff = 1
    #    HDR.CHANNEL[HDR.NS-1].OnOff = 1
    #
    # read data
    data = biosig.sread(0, HDR.NRec, HDR)
    print data.shape
    #
    # close file
    biosig.sclose(HDR)
    #
    # release allocated memory
    biosig.destructHDR(HDR)
    #
    #return data
Exemple #9
0
 def closefile(self):
     biosig.sclose(self.__HDR)