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
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 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
def __init__(self, filename): self.__filename = filename #self.__hypdata = None #self.__artdata = None #self.__data = None self.__channels = [] self.__epoch = None self.__HDR = None #self.__has_read_data = False if not os.path.isfile(self.__filename): raise IOError('file ' + self.__filename + ' cannot be opened!') self.__HDR = biosig.constructHDR(0, 0) self.__HDR = biosig.sopen(self.__filename, "r", self.__HDR) self.__Fs = np.zeros(self.__HDR.NS) for i in range(self.__HDR.NS): self.__Fs[i] = self.__HDR.CHANNEL[i].SPR channel = self.__HDR.CHANNEL[i].Label nullpos = channel.find('\x00') if nullpos != -1: channel = channel[:nullpos] self.__channels.append(channel) self.__HDR.CHANNEL[i].OnOff = 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)
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();
# make test import biosig import numpy as S import ctypes import datetime filename = '/scratch/schloegl/R/data/test/CFS/example_6channels.dat' filename = '/home/as/data/test/CFS/example_6channels.dat' filename = '/home/as/data/test/BDF/sample_bdf_plus_file.bdf' filename = '/fs/home/schloegl/data/test/gdf/test.clemens.20121220.gdf' print 'open file ', filename HDR = biosig.constructHDR(0, 0) HDR = biosig.sopen(filename, 'r', HDR) HDR.Patient.Id HDR.Patient.Sex HDR.Patient.Handedness HDR.Patient.DrugAbuse HDR.Patient.Smoking ### convert from gdftime/matlab/octave datetime format to python datetime format ### for some unknown reason, the starting point is 366 days off. d = datetime.timedelta(days=HDR.T0 * (2**-32) - 366) m, s = divmod(d.seconds, 60) h, m = divmod(m, 60) starttime = datetime.datetime.combine(datetime.date.fromordinal(d.days), datetime.time(h, m, s))
# make test import biosig import numpy as S import ctypes import datetime filename = '/scratch/schloegl/R/data/test/CFS/example_6channels.dat' filename = '/home/as/data/test/CFS/example_6channels.dat' filename = '/home/as/data/test/BDF/sample_bdf_plus_file.bdf' filename = '/fs/home/schloegl/data/test/gdf/test.clemens.20121220.gdf' print 'open file ',filename HDR = biosig.constructHDR(0, 0) HDR = biosig.sopen(filename , 'r', HDR) HDR.Patient.Id HDR.Patient.Sex HDR.Patient.Handedness HDR.Patient.DrugAbuse HDR.Patient.Smoking ### convert from gdftime/matlab/octave datetime format to python datetime format ### for some unknown reason, the starting point is 366 days off. d = datetime.timedelta(days=HDR.T0*(2**-32)-366) m, s = divmod(d.seconds, 60) h, m = divmod(m, 60) starttime = datetime.datetime.combine(datetime.date.fromordinal(d.days), datetime.time(h,m,s)) print "starting time:",starttime