def __init__(self, around, aroundTS, dbName, begkey, Signame, TSName): self.lastMove = None self.Sig = np.memmap(Signame, dtype=np.float32, mode='r') self.SigCh = [self.Sig[i::NChan] for i in range(NChan)] ts = np.loadtxt(TSName, unpack=True) self.P1 = ts[1][find(ts[0] == 1)] / freq self.P2 = ts[1][find(ts[0] == -1)] / freq self.around = around self.aroundTS = aroundTS self.key = begkey self.db = recogdb.openDB(dbName, 'rw') if key != 0: self.k = struct.pack('=q', key) self.k, self.bindata = self.db.set_location(self.k) else: self.k, self.bindata = self.db.first() self.k, self.bindata = self.db.set_location(self.k) self.read_data = recogdb.parseDBHeader(self.bindata) self.off, = struct.unpack('=q', self.k) print('key:\t%d' % self.off) print('time: %s' % self.sec2hms(self.off / freq, None)) for a, b in recogdb.dicFields.items(): print('%s:\t%s' % (a, self.read_data[b])) self.formatterX = FuncFormatter(self.sec2hms) self.f = plt.figure(1, figsize=(25, 20)) self.ax1 = self.f.add_subplot(111) self.sigs = [None for i in range(NChan)] for i in range(NChan): self.sigs[i], = self.ax1.plot((), (), 'k-') self.P1Lines = [None for j in range(self.aroundTS)] self.P2Lines = [None for j in range(self.aroundTS)] for j in range(self.aroundTS): self.P1Lines[j], = self.ax1.plot((0, 0), (-10, 5 * (NChan + 1)), 'b-', alpha=0.4) self.P2Lines[j], = self.ax1.plot((0, 0), (-10, 5 * (NChan + 1)), 'r-', alpha=0.4) self.strongLine, = self.ax1.plot((0, 0), (-10, 5 * (NChan + 1)), 'k-') self.newLine, = self.ax1.plot((0, 0), (-10, 5 * (NChan + 1)), 'k-') self.f.canvas.mpl_connect('button_press_event', self.spikeClick) self.f.canvas.mpl_connect('motion_notify_event', self.spikeMove) self.f.canvas.mpl_connect('button_release_event', self.spikeRelease) self.init_data() self.plotStuff() self.makeButtons() self.adjustAxes()
def dbnext(self, event): self.lastMove = 'next' self.k, self.bindata = self.db.next() self.read_data = recogdb.parseDBHeader(self.bindata) self.off, = struct.unpack('=q', self.k) print('\nkey:\t%d' % self.off) print('time: %s' % self.sec2hms(self.off / freq, None)) for a, b in recogdb.dicFields.items(): print('%s:\t%s' % (a, self.read_data[b])) self.init_data() self.plotStuff() self.adjustAxes()
import numpy as np import recogdb import struct import sys keybeg = 356604502 keyend = 356637225 db = recogdb.openDB(sys.argv[1], 'rw') kb = struct.pack('=q', keybeg) ke = struct.pack('=q', keyend) off, bindata = db.set_location(kb) off, = struct.unpack('=q', off) read_data = recogdb.parseDBHeader(bindata) while (off <= keyend): key = recogdb.verifyKey(db, off) sys.stdout.write('%d\r' % off) sys.stdout.flush() oldFish = read_data[recogdb.dicFields['presentFish']] oldCorrectedPosA = read_data[recogdb.dicFields['correctedPosA']] oldCorrectedPosB = read_data[recogdb.dicFields['correctedPosB']] oldDistA = read_data[recogdb.dicFields['distA']] oldDistB = read_data[recogdb.dicFields['distB']] oldDistAB = read_data[recogdb.dicFields['distAB']] if oldFish == 1: newFish = 2
'B':0, } flag = { 'A': 1, 'B': -1, } prob = { 'A': 0., 'B': 0., } allOffs = {} OffsRaw = {} print 'enter DB' for rec in db.iteritems(): # Gambi pra verificar se o spike ja foi classificado off, bindata = rec read_data = recogdb.parseDBHeader(bindata) offraw, direction, distA, distB, distAB, SaturationFlag, svm, pairsvm, prob['A'], prob['B'], fishwins = recogdb.fishrec(rec) off = offraw/4/NumChannels for PIdx in fishwins.keys(): if PIdx == 'A': f.write('%d %d\n'%(1, off + fishwins[PIdx][0])) if PIdx == 'B': f.write('%d %d\n'%(-1, off + fishwins[PIdx][0])) f.flush() '''correctedPosA = read_data[ recogdb.dicFields['correctedPosA'] ] correctedPosB = read_data[ recogdb.dicFields['correctedPosB'] ] if (correctedPosA != -1) and (correctedPosB != -1): f.write( '%d\t%d\n'%(1, correctedPosA) )