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_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 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
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
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();
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
# download and extract # http://www.biosemi.com/download/BDFtestfiles.zip # into /tmp/ # then run this demo # # on linux you can run instead # make test import biosig import numpy as S #def load(fname): HDR = biosig.constructHDR(0, 0) #HDR = biosig.sopen('/scratch/schloegl/R/data/test/HekaPatchMaster/AP100427b.dat' , 'r', HDR) #HDR = biosig.sopen('/scratch/schloegl/R/data/test/HekaPatchMaster/AP100429a.dat' , 'r', HDR) HDR = biosig.sopen('/scratch/schloegl/R/data/test/CFS/example_6channels.dat', 'r', HDR) # show header information biosig.hdr2ascii(HDR, 4) # 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)
#!/usr/bin/env python3 import pylab import numpy import biosig HDR = biosig.sopen( '/home/sweet/1-workdir/eeg001-2017/S01_ME/motorexecution_subject1_run1.gdf', 'r') #for i in range(HDR.NS): # HDR.CHANNEL[i].OnOff = 0 #HDR.CHANNEL[0].OnOff = 1 # data = biosig.sread(HDR, HDR.NRec, 0) # biosig.sclose(HDR) # # #biosig.destructHDR(HDR) # pylab.ion() # pylab.plot(numpy.transpose(data)) # pylab.show()
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
# download and extract # http://www.biosemi.com/download/BDFtestfiles.zip # into /tmp/ # then run this demo # # on linux you can run instead # make test import biosig import numpy as S #def load(fname): HDR = biosig.constructHDR(0, 0) #HDR = biosig.sopen('/scratch/schloegl/R/data/test/HekaPatchMaster/AP100427b.dat' , 'r', HDR) #HDR = biosig.sopen('/scratch/schloegl/R/data/test/HekaPatchMaster/AP100429a.dat' , 'r', HDR) HDR = biosig.sopen('/scratch/schloegl/R/data/test/CFS/example_6channels.dat' , 'r', HDR) # show header information biosig.hdr2ascii(HDR,4) # 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