def setUp(self): # Init self.Signal = plux.loadbpf("../signals/bvp.txt") self.Signal = self.Signal[:, 3] self.SamplingRate = float(Signal.header['SamplingFrequency']) self.DataFolder = r'../signals/bvp' self.Benchmark = 0
fname = os.path.split(fpath)[1] # map file name to a subject subId = db.subjects.get({'field': 'value'}, {'_id': 1})['docList'][0]['_id'] # create record recId = db.records.add({ 'experiment': '', 'subject': subId, 'supervisor': '', 'date': '' })['recordId'] # load data data = plux.loadbpf(fpath) # add data dataType = '' metadata = { 'device': { 'name': '', 'channels': [0, 1], 'Vcc': data.header['Vcc'], 'version': data.header['Version'] }, 'transducer': '', 'placement': '', 'units': { 'time': 'second', 'sensor': data.header['Units']
def setUp(self): # Init self.Signal = plux.loadbpf("../signals/resp.txt") self.Signal = self.Signal[:, 3] self.SamplingRate = float(Signal.header['SamplingFrequency'])
def testfeatures(self): # Test if a dict is returned by the features function self.res = features(Signal=self.Signal, SamplingRate=self.SamplingRate) assert type( self.res ) is dict, "Returned value by the features function is not a dict." # Test if the right exception is raised when no input signal is given self.assertRaises(TypeError, features, None) # ... # ... # Example: # Load Data RawSignal = plux.loadbpf("../signals/resp.txt") RawSignal = RawSignal[:, 3] SamplingRate = float(RawSignal.header['SamplingFrequency']) # Unit conversion RawSignal = RawSignal.toV() # Filter Signal = filt(Signal=RawSignal)['Signal'] #*losing bparray information # Convert to bparray Signal = plux.bparray(Signal, RawSignal.header) # Time array Time = np.linspace(0, len(Signal) / SamplingRate, len(Signal)) # Beat information res = resp(Signal=Signal, SamplingRate=SamplingRate) # Plot fig = pl.figure() ax = fig.add_subplot(111)
def testfeatures(self): # Test if a dict is returned by the features function self.res = features(Signal=self.Signal, SamplingRate=self.SamplingRate) assert type( self.res ) is dict, "Returned value by the features function is not a dict." # Test if the right exception is raised when no input signal is given self.assertRaises(TypeError, features, None) # ... # ... # Example: # Load Data RawSignal = plux.loadbpf("../signals/ecg.txt") RawSignal = RawSignal[:, 3] SamplingRate = float(RawSignal.header['SamplingFrequency']) # Unit conversion RawSignal = RawSignal.tomV() # Filter Signal = filt(Signal=RawSignal, SamplingRate=SamplingRate, UpperCutoff=30.0, LowerCutoff=0.5)['Signal'] #*losing bparray information # Convert to bparray Signal = plux.bparray(Signal, RawSignal.header) # Time array Time = scipy.linspace(0, len(Signal) / SamplingRate, len(Signal)) # Beat information res = ecg(Signal=Signal, SamplingRate=SamplingRate)
def cvp_files2db(config, datapath=r"Y:\\data\\CVP"): # connect to DB db = biomesh.biomesh(**config) # add the experiments db.experiments.add({ 'name': 'T1', 'goals': 'ECG acquisition.', 'description': 'First session; ECG acquired from hands, in recumbent and sitting positions.' }) db.experiments.add({ 'name': 'T2', 'goals': 'ECG acquisition.', 'description': 'Second session; ECG acquired from hands, in recumbent and sitting positions.' }) user_file_dict = {} # add subjects filename = '\\Lista de Participantes %s.xls' for experiment in ['Cardiopneumologia', 'Enfermagem', 'Fisioterapia']: # print experiment if experiment == 'Cardiopneumologia': idx = 0 else: idx = -1 #add subjects wb = xlrd.open_workbook(datapath + filename % experiment) sheet = wb.sheet_by_index(0) for rownum in range(1, sheet.nrows): # 'N Aluno', 'Sexo', 'Nome', 'D.N.', 'Altura (cm)', 'Peso (Kg)', \ # 'Raca', 'E-Mail*', 'Telemovel*', 'Desporto', 'Desporto (2o teste)',\ # '1o teste Sentado', '1o teste Deitado', '2o Teste Sentado', '2o teste Deitado' # print sheet.row_values(rownum), len(sheet.row_values(rownum)) birthdate = sheet.cell_value(rownum, 3) year, month, day, hour, minute, sec = xlrd.xldate_as_tuple( birthdate, wb.datemode) birthdate = datetime.datetime(year, month, day, hour, minute, sec).isoformat() name = sheet.cell_value(rownum, 2) gender = sheet.cell_value(rownum, 1) fname1, fname2, fname3, fname4 = sheet.cell_value( rownum, 11 + idx), sheet.cell_value(rownum, 12 + idx), sheet.cell_value( rownum, 13 + idx), sheet.cell_value(rownum, 14 + idx) # MISSING FILEs aux = numpy.array( map(lambda pat: fname1.find(pat), [ 'F2851', 'F2847', 'F2825', 'F2826', 'F2828', 'F2845', 'F2871', 'F2908' ])) if numpy.any(aux >= 0): print "skipped %s" % fname1 continue ext = '.txt' fname1, fname2, fname3, fname4 = fname1 + ext, fname2 + ext, fname3 + ext, fname4 + ext if gender == 'M': # print gender, fname1, fname2, fname3, fname4 for timest in ['-T1', '-T2']: rawdatapath = datapath + '\\' + experiment + '\\' + experiment + timest ext = '*.txt' for fname in glob.glob(os.path.join(rawdatapath, ext)): fsplt = fname.split('\\')[-1] # print fsplt # print fname1, fname2, fname3, fname4 if fsplt in [fname1, fname2, fname3, fname4]: newfname = fname.replace('F', 'M') try: os.rename(fname, newfname) print "corrected %s to %s" % (fname, newfname) except Exception as e: # pass print fname print e fname1 = fname1.replace('F', 'M') fname2 = fname2.replace('F', 'M') fname3 = fname3.replace('F', 'M') fname4 = fname4.replace('F', 'M') info = { 'number': sheet.cell_value(rownum, 0), 'sex': gender, 'name': name, 'birthdate': birthdate, 'heigth': sheet.cell_value(rownum, 4), 'weigth': sheet.cell_value(rownum, 5), # 'ethnicity': sheet.cell_value(rownum,6), 'email': sheet.cell_value(rownum, 7) } #, # 'mobilenr': sheet.cell_value(rownum,8), # 'sport1': sheet.cell_value(rownum,9), # 'sport2': sheet.cell_value(rownum,10), # 'file': { # '1Sentado': fname1, # '1Deitado': fname2, # '2Sentado': fname3, # '2Deitado': fname4}} # add the subject subId = db.subjects.add(info)['subjectId'] # print subId user_file_dict[str(fname1)] = subId user_file_dict[str(fname2)] = subId user_file_dict[str(fname3)] = subId user_file_dict[str(fname4)] = subId # add data for source in ['Cardiopneumologia', 'Enfermagem', 'Fisioterapia']: for timest in ['-T1', '-T2']: # data path rawdatapath = datapath + '\\' + source + '\\' + source + timest ext = '*' + timest + '*.txt' for fname in glob.glob(os.path.join(rawdatapath, ext)): print fname fsplt = fname.split('\\')[-1] try: subId = user_file_dict[fsplt] except Exception as e: print "skipped %s" % fname continue # Read samples file data = plux.loadbpf(fname) data = data[:, 3] # datetime date = data.header['StartDateTime'].replace(' ', 'T') # get record out = db.records.getAll({ 'experiment': timest[1:], 'subject': subId })['idList'] if len(out) == 0: recId = db.records.add({ 'date': date, 'experiment': timest[1:], 'subject': subId, 'source': source })['recordId'] else: recId = out[0] if 'Deit' in fsplt: position = 'Recumbent' elif 'Sent' in fsplt: position = 'Sitting' mdata = { 'labels': ['ECG'], 'device': { 'Vcc': data.header['Vcc'], 'version': data.header['Version'] }, 'units': { 'time': 'second', 'sensor': data.header['Units'] }, 'sampleRate': data.header['SamplingFrequency'], 'resolution': data.header['SamplingResolution'] } db.records.addSignal(recId, '/ECG/hand/' + position + '/raw', data, mdata) # close db db.close()
import sync import tools as tls reload(bvp) reload(eda) reload(edafc) pl.ioff() fname = '../data/PN11 12.12.txt' #fname='../data/PN12 13.12.txt' #fname='../data/PN13 13.12.txt' print "loading " + fname Raw = plux.loadbpf(fname) SamplingRate = 10. # SamplingRate=20 DownSampling = Raw.header['SamplingFrequency'] / SamplingRate Data = Raw[::DownSampling, :] print "switch events" Switch = sync.step(Raw[:, 1]) #Switch=sync.step(Data[:,1]) Switch['Event'] /= Raw.header['SamplingFrequency'] / SamplingRate print "eda events" EDA = eda.scr(Signal=Data[:, 3].touS(), SamplingRate=SamplingRate, Filter={'UpperCutoff': 0.05})
# for file in glob.glob(os.path.join(self.DataFolder, '*.txt')): # self.Signal = plux.loadbpf(file) # self.Signal = self.Signal[:,3] # self.SamplingRate = float(Signal.header['SamplingFrequency']) # self.res = filt(Signal=self.Signal, SamplingRate=self.SamplingRate) # self.res = pulse(Signal=self.res['Signal'], SamplingRate=self.SamplingRate) # self.NrBeats = # if(len(self.res['Onset']) == self.NrBeats): # self.Benchmark+=1 # # ... # ... # ... # Example: # Load Data RawSignal = plux.loadbpf("../signals/bvp.txt") RawSignal = RawSignal[:, 3] SamplingRate = float(RawSignal.header['SamplingFrequency']) # Unit conversion RawSignal = RawSignal.tomV() # Filter Signal = filt( Signal=RawSignal, SamplingRate=SamplingRate)['Signal'] #*losing bparray information # Convert to bparray Signal = plux.bparray(Signal, RawSignal.header) # Normalization: 0-1 Signal = (Signal - min(Signal)) / (max(Signal) - min(Signal)) # Time array Time = np.linspace(0, len(Signal) / SamplingRate, len(Signal)) # Pulse information