Пример #1
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
Пример #2
0
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
Пример #3
0
def edfreadin(filename):
    hdr = biosig.sopen(filename, 'r', None)
    n = hdr.NS
    eegs = {}
    v = biosig.sread(0, hdr.NRec * hdr.SPR, hdr)
    for i in range(n):
        k = hdr.CHANNEL[i].Label.split('\x00')[0]
        if k in channels:
            eegs[k] = v[i].astype('float32')
    return eegs
Пример #4
0
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
Пример #5
0
 def read_channel(self, channel):
     """
     to avoid SEGMENTATION FAULT all channels have to be read one by one
     we set the OnOff option (this option turns reading of a channel on  or off) of all channels 0
     if we want to read the channel we set its OnOff option to 1 this means reading is on and we read the data
     after we read the channel's data we must set it again to 0, or else we get segmentation fault
     """
     #print "Debug: self.__channels=", self.__channels, " channel=", channel
     self.__HDR.CHANNEL[self.__channels.index(channel)].OnOff = 1
     channeldata = np.array(biosig.sread(0, self.__HDR.NRec, self.__HDR),
                            dtype=np.float32)[0]
     self.__HDR.CHANNEL[self.__channels.index(channel)].OnOff = 0
     return channeldata
Пример #6
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
Пример #7
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
Пример #8
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)
Пример #9
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();

Пример #10
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